uffizzi-preview.yml 3.1 KB

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