Repository navigation
Description
Description
Hi,
The issue is related to another popular GitHub Action actions/checkout which allows to checkout the repository. Unfortunately, when checking out the repository that triggered a workflow, this defaults to the reference or SHA for that event. This means, that the subsequent jobs in the workflow will not include the updates made with PSR action.
For example if we have a workflow with 3 jobs, the first to run PSR and release package to GitHub, the second job to build and release image to Docker Hub(the image should include updated package with changelog changes, new version file, etc from the job 1), and the third job to build and release package to PyPI(the built package should also include all of the updates from the job 1).
Here is an example of this workflow(with some non-important steps amended):
jobs:
release:
name: Release Package to GitHub
outputs:
released: ${{ steps.release.outputs.released }}
version: ${{ steps.release.outputs.version }}
tag: ${{ steps.release.outputs.tag }}
steps:
- id: release
name: Python Semantic Release
uses: python-semantic-release/python-semantic-release@master
docker:
name: Build and push Docker image
needs: release
steps:
- name: Build and push
uses: docker/build-push-action@v5
with:
push: true
tags: username/image:${{ needs.release.outputs.version }}, username/image:latest
pypi:
name: Publish to PyPI
needs: release
steps:
- name: Install dependencies
- name: Download source code
uses: actions/checkout@v3
- name: Build package distributions
- name: Publish package distributions to PyPIThe way GitHub actions works, the pypi and docker jobs will not include the commits made by release job. A simple git pull to HEAD reference, will pull those commits; However, such solution can also introduce a race condition, in case there were other commits made while the release job was running. More Info about this issue.
The correct solution would be for PSR GitHub Action to output the hash of the commit that has been made, which can be used in other jobs to pull the updates.
Use cases
Using separate jobs for updating version/releasing packages.
Possible implementation
Well, adding outputs would be easy(I assume), but I'm not sure how to get the commit hash after push, if someone can explain which function pushes the committed changes, I can try to work on the pull request.
Thank you
Activity
wyardley commentedon Aug 30, 2024
I can try and take a look at this. This should be done in https://github.com/python-semantic-release/python-semantic-release/blob/master/semantic_release/cli/github_actions_output.py vs. the shell entrypoint, right? @codejedi365 do you have a preference for the name the hash shows up as?
commit_sha, and then usegit.repo.head.object.hexshato get the value?FWIW, this seems like a useful thing to do, but I also think having subsequent workflows run off the tag thatpython-semantic-releasecuts should be relatively reliable and resistant to the issue mentioned? Similarly, since there is already atag` output, this could probably also be used (explicitly check out the tag from the output in the downstream workflows), even if you don't want to run the workflow separately off the cut tag.(side note: one quirk I've found recently is that while the node semantic-release cuts releases with
[skip ci]by default, and that works fine with CircleCI (doesn't prevent the jobs off the cut tag from running), Google Cloud Build and GitHub Actions won't run the job for the tag when the last commit in the tag has[skip ci]in it. This is kind of a weird corner case, since tags aren't associated with commits.)codejedi365 commentedon Aug 30, 2024
Great! Yes, I think you can just extend the code that auto writes the variable file. That file is the object class where it is defined and modified (unfortunately not in the most standard way) inside of
cli/commands/version.py. You could change it over to using property setters with validation to be more official.That is a way to get the value but be aware it does perform git actions under the hood, no real preference on the name. You will need to consider probably a tag sha as well, as we do support
--no-commit. We might already have the sha in one of our data objects that would not require git requests.The default
[skip ci]is discussed and confirmed as desired enhancement in another issue (#153, #973)github-actions commentedon Oct 30, 2024
It has been 60 days since the last update on this confirmed issue. @python-semantic-release/team can you provide an update on the status of this issue?
13 remaining items
test(gha): add unit test for GitHub Actions output of `commit_sha`
test(gha): update e2e test for GitHub Actions output to include `comm…
feat(github-actions): add `commit_sha` as a GitHub Actions output value
feat(github-actions): add `commit_sha` as a GitHub Actions output value
feat(github-actions): add `commit_sha` as a GitHub Actions output value
test(gha): update e2e test for GitHub Actions output to include `comm…
feat(github-actions): add `commit_sha` as a GitHub Actions output value
feat(github-actions): add `commit_sha` as a GitHub Actions output val…
codejedi365 commentedon Aug 4, 2025
🎉 This issue has been resolved in v10.3.0 🎉
You can find more information about this release on the GitHub Releases page.
michael-pisman commentedon Aug 6, 2025
Thanks :)