30
30
runs-on : ubuntu-latest
31
31
if : ${{ github.event.workflow_run.conclusion == 'success' }}
32
32
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 }}
35
37
steps :
36
38
- name : Download artifacts
37
39
# Fetch output (zip archive) from the workflow run that triggered this workflow.
46
48
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
47
49
return artifact.name == "preview-spec"
48
50
})[0];
51
+ if (matchArtifact === undefined) {
52
+ throw TypeError('Build Artifact not found!');
53
+ }
49
54
let download = await github.rest.actions.downloadArtifact({
50
55
owner: context.repo.owner,
51
56
repo: context.repo.repo,
@@ -55,34 +60,38 @@ jobs:
55
60
let fs = require('fs');
56
61
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/preview-spec.zip`, Buffer.from(download.data));
57
62
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
+
60
66
- name : Read Event into ENV
67
+ id : event
61
68
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
65
72
66
73
- name : Hash Rendered Compose File
67
74
id : hash
68
75
# 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
+
71
81
- name : Cache Rendered Compose File
72
- if : ${{ fromJSON(env.EVENT_JSON).action != 'closed' }}
82
+ if : ${{ steps.event.outputs.ACTION != 'closed' }}
73
83
uses : actions/cache@v3
74
84
with :
75
85
path : docker-compose.rendered.yml
76
- key : ${{ env.HASH }}
86
+ key : ${{ steps.hash.outputs.COMPOSE_FILE_HASH }}
77
87
78
- - name : Read PR Number From Event Object
79
- id : pr
80
- run : echo "PR_NUMBER=${{ fromJSON(env.EVENT_JSON).number }}" >> $GITHUB_ENV
81
88
- name : DEBUG - Print Job Outputs
82
89
if : ${{ runner.debug }}
83
90
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 }}"
86
95
cat event.json
87
96
88
97
deploy-uffizzi-preview :
0 commit comments