Add commit hash output to GitHub Action
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 PyPI
The 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