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

Improve release workflow #390

Merged
merged 6 commits into from
Apr 26, 2024
Merged

Conversation

felixfontein
Copy link
Contributor

The first commit stores the PR's URL and adds a step before uploading the release to PyPI which checks whether the PR has been merged. If it hasn't been merged, the publish stage fails. (This isn't the best solution possible, but will prevent something like the accidental 9.5.0 release from today.)

The second commit adds a Python step that parses the package version to validate it, and to extract the major version. This allows to simplify the workflow's input to a single version field.

If it wasn't merged, fail with an error message.
Copy link
Contributor

@gotmax23 gotmax23 left a comment

Choose a reason for hiding this comment

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

This looks good sans a few style nitpicks. Thanks!


from packaging.version import Version

FILE_APPEND_MODE = 'a'
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this really need to be a constant?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I copied this and the below from https://github.com/ansible-community/ansible-test-gh-action, it seems to be @webknjaz's preferred way of outputting things from a Python script in GHA. Maybe he can comment on it :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, fair enough

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I like to name the data. Otherwise, "what's is that weird 'a' string constant being passed to a function as a positional argument?" adds some cognitive load for people that are out of context. Some day, I'll move most of that to an actual Python file and this will reduce the boilerplate too..


def set_output(name, value):
with OUTPUTS_FILE_PATH.open(FILE_APPEND_MODE) as outputs_file:
outputs_file.writelines(f'{name}={value}{os.linesep}')
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not

Suggested change
outputs_file.writelines(f'{name}={value}{os.linesep}')
outputs_file.write(f'{name}={value}\n')

? You shouldn't need writelines to write one line and \n does the same thing as os.linesep (in text mode, python converts \n to \r\n if that's os.linesep and we're not working with Windows to begin with).

Copy link
Member

Choose a reason for hiding this comment

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

This is also copied from my code :)

I have helpers in other places where you can pass an iterable of strings and this is more genetic.

.github/workflows/ansible-release.yml Outdated Show resolved Hide resolved
.github/workflows/ansible-release.yml Outdated Show resolved Hide resolved
.github/workflows/ansible-release.yml Outdated Show resolved Hide resolved
Co-authored-by: Maxwell G <maxwell@gtmx.me>
@webknjaz
Copy link
Member

@felixfontein one thing I'd check is whether there's enough privileges in that job to query the PR data in that publish job. You may need a contents: read in there (don't forget to add a code comment explaining why).

@gotmax23
Copy link
Contributor

@felixfontein one thing I'd check is whether there's enough privileges in that job to query the PR data in that publish job. You may need a contents: read in there (don't forget to add a code comment explaining why).

I don't think it really matters if the repo is public.

Comment on lines +50 to 52
python3 -m pip install packaging
python3 -m pip install ansible-core
python3 -m pip install antsibull
Copy link
Contributor

Choose a reason for hiding this comment

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

TODO in a separate PR: merge these into one pip install command instead of three

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was wondering whether the separate installs were intentional for some reason, so I added a third. But yeah, let's collapse them (in a separate PR).

Co-authored-by: Maxwell G <maxwell@gtmx.me>
@felixfontein
Copy link
Contributor Author

@felixfontein one thing I'd check is whether there's enough privileges in that job to query the PR data in that publish job. You may need a contents: read in there (don't forget to add a code comment explaining why).

I don't think it really matters if the repo is public.

I think so too; I guess we'll see when we try this out. I'd abuse the next 10.0.0 alpha for this kind of testing :)

(I'll also try to approve the next step without merging the PR first, to see what happens. My guess is that restarting the failed second stage will work once the PR is merged.)

@felixfontein felixfontein merged commit 7a5eb7d into ansible-community:main Apr 26, 2024
3 checks passed
@felixfontein felixfontein deleted the workflow branch April 26, 2024 05:15
@felixfontein
Copy link
Contributor Author

@gotmax23 @webknjaz thanks for reviewing this!

@webknjaz
Copy link
Member

I don't think it really matters if the repo is public.

I think so too; I guess we'll see when we try this out. I'd abuse the next 10.0.0 alpha for this kind of testing :)

@gotmax23 it does matter because setting permissions overrides the defaults and essentially revokes all other permissions that are not set explicitly. So the resulting GITHUB_TOKEN may end up not having enough privileges. Hence the suggestion to check it. I think I've hit a problem with this before.

@felixfontein
Copy link
Contributor Author

https://github.com/ansible-community/ansible-build-data/actions/runs/8898520146/job/24436000110

gh: To use GitHub CLI in a GitHub Actions workflow, set the GH_TOKEN environment variable. Example:
  env:
    GH_TOKEN: ${{ github.token }}

Fixed in 1c10087.

@webknjaz
Copy link
Member

GH_TOKEN

GITHUB_TOKEN also works FYI

@felixfontein
Copy link
Contributor Author

Next try:

failed to run git: fatal: not a git repository (or any of the parent directories): .git

Fixed in acaf8bb.

@felixfontein
Copy link
Contributor Author

Ok, that fix was wrong, 9364168 should do better.

@felixfontein
Copy link
Contributor Author

Now it looks good:
https://github.com/ansible-community/ansible-build-data/actions/runs/8900826549/job/24443463257

Error: The state of PR https://github.com/ansible-community/ansible-build-data/pull/400 must be MERGED, not OPEN

🎉

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.

3 participants