1+ name : Deploy Uffizzi Preview
2+
3+ on :
4+ workflow_run :
5+ workflows :
6+ - " Build PR Image"
7+ types :
8+ - completed
9+
10+
11+ jobs :
12+ cache-compose-file :
13+ name : Cache Compose File
14+ runs-on : ubuntu-latest
15+ outputs :
16+ compose-file-cache-key : ${{ env.COMPOSE_FILE_HASH }}
17+ pr-number : ${{ env.PR_NUMBER }}
18+ steps :
19+ - name : ' Download artifacts'
20+ # Fetch output (zip archive) from the workflow run that triggered this workflow.
21+ uses : actions/github-script@v6
22+ with :
23+ script : |
24+ let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
25+ owner: context.repo.owner,
26+ repo: context.repo.repo,
27+ run_id: context.payload.workflow_run.id,
28+ });
29+ let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
30+ return artifact.name == "preview-spec"
31+ })[0];
32+ let download = await github.rest.actions.downloadArtifact({
33+ owner: context.repo.owner,
34+ repo: context.repo.repo,
35+ artifact_id: matchArtifact.id,
36+ archive_format: 'zip',
37+ });
38+ let fs = require('fs');
39+ fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/preview-spec.zip`, Buffer.from(download.data));
40+ - name : ' Unzip artifact'
41+ run : unzip preview-spec.zip
42+ - name : Read Event into ENV
43+ run : |
44+ echo 'EVENT_JSON<<EOF' >> $GITHUB_ENV
45+ cat event.json >> $GITHUB_ENV
46+ echo 'EOF' >> $GITHUB_ENV
47+ - name : Hash Rendered Compose File
48+ id : hash
49+ # If the previous workflow was triggered by a PR close event, we will not have a compose file artifact.
50+ if : ${{ fromJSON(env.EVENT_JSON).action != 'closed' }}
51+ run : echo "COMPOSE_FILE_HASH=$(md5sum docker-compose.rendered.yml | awk '{ print $1 }')" >> $GITHUB_ENV
52+ - name : Cache Rendered Compose File
53+ if : ${{ fromJSON(env.EVENT_JSON).action != 'closed' }}
54+ uses : actions/cache@v3
55+ with :
56+ path : docker-compose.rendered.yml
57+ key : ${{ env.COMPOSE_FILE_HASH }}
58+
59+ - name : Read PR Number From Event Object
60+ id : pr
61+ run : echo "PR_NUMBER=${{ fromJSON(env.EVENT_JSON).number }}" >> $GITHUB_ENV
62+
63+ - name : DEBUG - Print Job Outputs
64+ if : ${{ runner.debug }}
65+ run : |
66+ echo "PR number: ${{ env.PR_NUMBER }}"
67+ echo "Compose file hash: ${{ env.COMPOSE_FILE_HASH }}"
68+ cat event.json
69+ deploy-uffizzi-preview :
70+ name : Use Remote Workflow to Preview on Uffizzi
71+ needs :
72+ - cache-compose-file
73+ uses :
UffizziCloud/preview-action/.github/workflows/[email protected] 74+ with :
75+ # If this workflow was triggered by a PR close event, cache-key will be an empty string
76+ # and this reusable workflow will delete the preview deployment.
77+ compose-file-cache-key : ${{ needs.cache-compose-file.outputs.compose-file-cache-key }}
78+ compose-file-cache-path : docker-compose.rendered.yml
79+ server : https://app.uffizzi.com
80+ pr-number : ${{ needs.cache-compose-file.outputs.pr-number }}
81+ permissions :
82+ contents : read
83+ pull-requests : write
84+ id-token : write
0 commit comments