uffizzi-preview.yml 3.2 KB

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