3030 runs-on : ubuntu-latest
3131 if : ${{ github.event.workflow_run.conclusion == 'success' }}
3232 outputs :
33- compose-file-cache-key : ${{ env.HASH }}
34- pr-number : ${{ env.PR_NUMBER }}
33+ compose-file-cache-key : ${{ steps.hash.outputs.COMPOSE_FILE_HASH }}
34+ git-ref : ${{ steps.event.outputs.GIT_REF }}
35+ pr-number : ${{ steps.event.outputs.PR_NUMBER }}
36+ action : ${{ steps.event.outputs.ACTION }}
3537 steps :
3638 - name : Download artifacts
3739 # Fetch output (zip archive) from the workflow run that triggered this workflow.
4648 let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
4749 return artifact.name == "preview-spec"
4850 })[0];
51+ if (matchArtifact === undefined) {
52+ throw TypeError('Build Artifact not found!');
53+ }
4954 let download = await github.rest.actions.downloadArtifact({
5055 owner: context.repo.owner,
5156 repo: context.repo.repo,
@@ -55,34 +60,38 @@ jobs:
5560 let fs = require('fs');
5661 fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/preview-spec.zip`, Buffer.from(download.data));
5762
58- - name : Unzip artifact
59- run : unzip preview-spec.zip
63+ - name : ' Accept event from first stage'
64+ run : unzip preview-spec.zip event.json
65+
6066 - name : Read Event into ENV
67+ id : event
6168 run : |
62- echo 'EVENT_JSON<<EOF' >> $GITHUB_ENV
63- cat event.json >> $GITHUB_ENV
64- echo 'EOF' >> $GITHUB_ENV
69+ echo PR_NUMBER=$(jq '.number | tonumber' < event.json) >> $GITHUB_OUTPUT
70+ echo ACTION=$(jq --raw-output '.action | tostring | [scan("\\w+")][0]' < event.json) >> $GITHUB_OUTPUT
71+ echo GIT_REF=$(jq --raw-output '.pull_request.head.sha | tostring | [scan("\\w+")][0]' < event.json) >> $GITHUB_OUTPUT
6572
6673 - name : Hash Rendered Compose File
6774 id : hash
6875 # If the previous workflow was triggered by a PR close event, we will not have a compose file artifact.
69- if : ${{ fromJSON(env.EVENT_JSON).action != 'closed' }}
70- run : echo "HASH=$(md5sum docker-compose.rendered.yml | awk '{ print $1 }')" >> $GITHUB_ENV
76+ if : ${{ steps.event.outputs.ACTION != 'closed' }}
77+ run : |
78+ unzip preview-spec.zip docker-compose.rendered.yml
79+ echo "COMPOSE_FILE_HASH=$(md5sum docker-compose.rendered.yml | awk '{ print $1 }')" >> $GITHUB_OUTPUT
80+
7181 - name : Cache Rendered Compose File
72- if : ${{ fromJSON(env.EVENT_JSON).action != 'closed' }}
82+ if : ${{ steps.event.outputs.ACTION != 'closed' }}
7383 uses : actions/cache@v3
7484 with :
7585 path : docker-compose.rendered.yml
76- key : ${{ env.HASH }}
86+ key : ${{ steps.hash.outputs.COMPOSE_FILE_HASH }}
7787
78- - name : Read PR Number From Event Object
79- id : pr
80- run : echo "PR_NUMBER=${{ fromJSON(env.EVENT_JSON).number }}" >> $GITHUB_ENV
8188 - name : DEBUG - Print Job Outputs
8289 if : ${{ runner.debug }}
8390 run : |
84- echo "PR number: ${{ env.PR_NUMBER }}"
85- echo "Compose file hash: ${{ env.HASH }}"
91+ echo "PR number: ${{ steps.event.outputs.PR_NUMBER }}"
92+ echo "Git Ref: ${{ steps.event.outputs.GIT_REF }}"
93+ echo "Action: ${{ steps.event.outputs.ACTION }}"
94+ echo "Compose file hash: ${{ steps.hash.outputs.COMPOSE_FILE_HASH }}"
8695 cat event.json
8796
8897 deploy-uffizzi-preview :
0 commit comments