Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds a new release GitHub Actions workflow #394

Merged
merged 4 commits into from Jun 14, 2021
Merged

Conversation

dkliban
Copy link
Member

@dkliban dkliban commented May 28, 2021

The new release workflow has 3 serial jobs:

Build artifacts:
Create change log using towncrier. Bump version to GA (from dev). Commits these changes. Bump version to the next Z.dev release and create a commit. If the changes already exist in the repository, the previous steps are skipped. Build the plugin Python package or download it from PyPI. The entire repository (including the dist directory with built package) is archived and uploaded to the next job.

Test:
Build a container from the package in the previous job. Build the Python client or install it from PyPI if it has already been published. Build the Ruby client. Build docs. Run unit and function tests using filesystem and S3 storage. Upload the Python and Ruby clients and the docs to be used by the next job.

Publish:
Publish plugin and client packages to PyPI if they are not present there. Publish Ruby client to RubyGems.org if it's not there. Publish docs. Push the commits created in the first job to GitHub. Push the tag to GitHub. Create a release on GitHub from the tag.

fixes: #7868
https://pulp.plan.io/issues/7868

@dkliban dkliban force-pushed the 7868 branch 7 times, most recently from 7c3fc88 to d64f8de Compare June 1, 2021 19:07
@pulpbot
Copy link
Member

pulpbot commented Jun 1, 2021

Attached issue: https://pulp.plan.io/issues/7868

@daviddavis
Copy link
Contributor

I think some of the scripts can go into .ci/scripts. Especially the ones that aren't specific to github.

Comment on lines 1 to 80
import argparse
import asyncio
import os
import textwrap

from pypi_tools import get_package_from_pypi

from git import Repo

helper = textwrap.dedent(
"""\
Create a new tag and build a Python package.

Example:

$ python .ci/scripts/create_tag_and_build_package.py 3.2.5 a96ba79cfbaae2f344c86a3641a

If the specified tag does not exist, a new tag is created in the repository.

If the tag already exists, this script checks if the package with such a version string
already exists on PyPI. If a package exists, the package is simply downloaded from PyPI
and saved as {{ plugin_dash }}-.tar.gz and {{ plugin_name }}-[tag]-py3-none-any.whl in the
'dist' directory.

If the package does not exist on PyPI, two new packages are built with the names
{{ plugin_dash }}-[tag].tar.gz and {{ plugin_name }}-[tag]-py3-none-any.whl. They are
stored in the 'dist' directory.
"""
)
parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter, description=helper)
parser.add_argument(
"desired_tag",
type=str,
help="The tag that should be created.",
)
parser.add_argument(
"commit_sha",
type=str,
help="The commit that should be used for the tag.",
)
args = parser.parse_args()
desired_tag = args.desired_tag
commit_sha = args.commit_sha

release_path = os.path.dirname(os.path.abspath(__file__))
plugin_path = release_path.split("/.github")[0]

repo = Repo(plugin_path)

# Remove auth header config
with repo.config_writer() as conf:
conf.remove_section('http "https://github.com/"')
conf.release()

# Determine if a tag exists and if it matches the specified commit sha
tag = None
for existing_tag in repo.tags:
if existing_tag.name == desired_tag:
if existing_tag.commit.hexsha == commit_sha:
tag = existing_tag
else:
raise RuntimeError(
"The '{desired_tag}' tag already exists, but the commit sha does not match "
"'{commit_sha}'."
)

# Create a tag if one does not exist
if not tag:
tag = repo.create_tag(desired_tag, ref=commit_sha)

# Checkout the desired tag and reset the tree
repo.head.reference = tag.commit
repo.head.reset(index=True, working_tree=True)

# Check if Package is available on PyPI
loop = asyncio.get_event_loop()
package_found = asyncio.run(get_package_from_pypi("{{ plugin_dash }}=={tag.name}", plugin_path))

if not package_found:
os.system("python3 setup.py sdist bdist_wheel --python-tag py3")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -0,0 +1,41 @@
import os
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this file used?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was going to re-use this for the client package also, but then I decided not to do it so that I could keep the code similar for python client and ruby client. I could move this code back into create_tag_and_build_package.py.j2 if you think that will be better.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am guessing create_tag_and_build_package.py.j2 went away?

Comment on lines 1 to 11
#!/bin/sh
set -e

curl -s -X POST https://api.github.com/repos/$GITHUB_REPOSITORY/git/refs \
-H "Authorization: token $GITHUB_TOKEN" \
-d @- << EOF
{
"ref": "refs/tags/$1",
"sha": "$2"
}
EOF
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@dkliban dkliban force-pushed the 7868 branch 2 times, most recently from 27524da to f52a1ce Compare June 11, 2021 02:14
The new release workflow has 3 stages:

Build artifacts - build the plugin Python packages or downloads them from PyPI.

Test - build a container from the package in the previous stage. Build the Python
       and Ruby clients. Build docs. Run unit and function tests using filesystem
       and S3 storage.

Publish - publish all packages to PyPI if they are not present there. Publish
          Ruby client to RubyGems.org if it's not there. Publish docs. Push
          tag to GitHub.

fixes: #7868
https://pulp.plan.io/issues/7868
@dkliban dkliban force-pushed the 7868 branch 2 times, most recently from 96387cf to f747dc1 Compare June 11, 2021 13:16
".ci/scripts/release_requirements.txt",
".ci/scripts/release.py",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 for remembering to deprecate files.

@dkliban dkliban force-pushed the 7868 branch 2 times, most recently from 26d7097 to 10ea1c8 Compare June 14, 2021 15:40
@dkliban dkliban merged commit cc4df91 into pulp:master Jun 14, 2021
@dkliban dkliban deleted the 7868 branch June 14, 2021 22:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants