I currently have a quite simple setup with two workflows; build and deploy. As of now deploy deploys to dev, test and prod for us. There is a disadvantage with that in that it is hard to see what was the latest deploy to prod for example, and also that if I would like to re-deploy test or prod I would need to trigger the whole workflow.
When I have only the two mentioned above I can read the git sha for the build workflow by accessing github.event.workflow_run.head_sha, so the current flow sort of work (not ideal, but it works).
My plan is now to have separate workflows for the deploy to dev, test and prod, but I know have the problem of knowing the git sha triggered the build which the deploy to dev would trigger on. My plan was then to use outputs for jobs, but how do I access outputs in one workflow from another?
So something like this is what I would like to do:
name: Deploy dev
on:
workflow_run:
workflows: [Build]
types: [completed]
workflow_dispatch:
jobs:
on-build-failure:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
steps:
- run: |
echo "First workflow was a failure"
exit 1
on-build-success:
outputs:
commit-sha: ${{ github.event.workflow_run.head_sha }}
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- run: echo "Build succeeded, continue with deploy"
Then in Deploy test:
name: Deploy test
on:
workflow_run:
workflows: [Deploy dev]
types: [completed]
workflow_dispatch:
jobs:
on-build-failure:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
steps:
- run: |
echo "First workflow was a failure"
exit 1
on-build-success:
runs-on: ubuntu-latest
outputs:
commit-sha: ${{ github.event.workflow_run.outputs.commit-sha }}
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- run: echo "Build succeeded, continue with deploy ${{ github.event.workflow_run.outputs.commit-sha }}"