|
| 1 | +# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json |
| 2 | +name: 🚀 Publish |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + sign_run_id: |
| 7 | + description: Sign workflow run id to publish from (defaults to latest successful run) |
| 8 | + required: false |
| 9 | + type: string |
| 10 | + workflow_call: |
| 11 | + inputs: |
| 12 | + sign_run_id: |
| 13 | + required: false |
| 14 | + type: string |
| 15 | + secrets: |
| 16 | + AWS_ACCESS_KEY_ID: |
| 17 | + required: true |
| 18 | + AWS_SECRET_ACCESS_KEY: |
| 19 | + required: true |
| 20 | + CF_AUTH: |
| 21 | + required: true |
| 22 | + CF_ENDPOINT: |
| 23 | + required: true |
| 24 | + CF_ZONE_ID: |
| 25 | + required: true |
| 26 | + ARTIFACTS_APP_ID: |
| 27 | + required: false |
| 28 | + ARTIFACTS_APP_PRIVATE_KEY: |
| 29 | + required: false |
| 30 | +permissions: |
| 31 | + contents: read |
| 32 | + actions: read |
| 33 | +jobs: |
| 34 | + prepare: |
| 35 | + name: 🧭 Resolve sign metadata |
| 36 | + runs-on: ubuntu-slim |
| 37 | + outputs: |
| 38 | + sign_run_id: "${{ steps.resolve.outputs.sign_run_id }}" |
| 39 | + display_version: "${{ steps.meta.outputs.VERSION_DISPLAY }}" |
| 40 | + pre_release: "${{ steps.meta.outputs.PRE_RELEASE }}" |
| 41 | + commit_sha: "${{ steps.meta.outputs.COMMIT_SHA }}" |
| 42 | + steps: |
| 43 | + - name: 🧭 Resolve sign run |
| 44 | + id: resolve |
| 45 | + uses: actions/github-script@v8 |
| 46 | + env: |
| 47 | + SIGN_RUN_ID_INPUT: "${{ inputs.sign_run_id }}" |
| 48 | + with: |
| 49 | + script: | |
| 50 | + const provided = process.env.SIGN_RUN_ID_INPUT; |
| 51 | + if (provided) { |
| 52 | + core.setOutput('sign_run_id', provided.trim()); |
| 53 | + return; |
| 54 | + } |
| 55 | + const runs = await github.paginate(github.rest.actions.listWorkflowRuns, { |
| 56 | + owner: context.repo.owner, |
| 57 | + repo: context.repo.repo, |
| 58 | + workflow_id: 'sign.yml', |
| 59 | + status: 'success', |
| 60 | + per_page: 1, |
| 61 | + }); |
| 62 | + if (!runs.length) { |
| 63 | + throw new Error('No successful sign workflow runs found to publish.'); |
| 64 | + } |
| 65 | + core.setOutput('sign_run_id', `${runs[0].id}`); |
| 66 | + - name: 🛑 Require GitHub App credentials for manual publish |
| 67 | + if: ${{ github.event_name == 'workflow_dispatch' }} |
| 68 | + env: |
| 69 | + ARTIFACTS_APP_ID: ${{ secrets.ARTIFACTS_APP_ID }} |
| 70 | + ARTIFACTS_APP_PRIVATE_KEY: ${{ secrets.ARTIFACTS_APP_PRIVATE_KEY }} |
| 71 | + run: | |
| 72 | + if [[ -z "$ARTIFACTS_APP_ID" || -z "$ARTIFACTS_APP_PRIVATE_KEY" ]]; then |
| 73 | + echo "Missing required secrets for manual publish: ARTIFACTS_APP_ID and/or ARTIFACTS_APP_PRIVATE_KEY" >&2 |
| 74 | + exit 1 |
| 75 | + fi |
| 76 | + - name: 🔑 Create GitHub App token (manual publish) |
| 77 | + if: ${{ github.event_name == 'workflow_dispatch' }} |
| 78 | + id: app_token |
| 79 | + uses: actions/create-github-app-token@v1 |
| 80 | + with: |
| 81 | + app-id: ${{ secrets.ARTIFACTS_APP_ID }} |
| 82 | + private-key: ${{ secrets.ARTIFACTS_APP_PRIVATE_KEY }} |
| 83 | + - name: ↓ Download sign metadata (manual publish) |
| 84 | + if: ${{ github.event_name == 'workflow_dispatch' }} |
| 85 | + uses: actions/download-artifact@v7 |
| 86 | + with: |
| 87 | + github-token: ${{ steps.app_token.outputs.token }} |
| 88 | + name: sign-metadata |
| 89 | + path: sign-metadata |
| 90 | + run-id: "${{ steps.resolve.outputs.sign_run_id }}" |
| 91 | + - name: ↓ Download sign metadata |
| 92 | + if: ${{ github.event_name != 'workflow_dispatch' }} |
| 93 | + uses: actions/download-artifact@v7 |
| 94 | + with: |
| 95 | + name: sign-metadata |
| 96 | + path: sign-metadata |
| 97 | + run-id: "${{ steps.resolve.outputs.sign_run_id }}" |
| 98 | + - name: 📄 Load sign metadata |
| 99 | + id: meta |
| 100 | + run: | |
| 101 | + cat sign-metadata/build-metadata.env >> "$GITHUB_ENV" |
| 102 | + while IFS='=' read -r key value; do |
| 103 | + if [[ -n "$key" ]]; then |
| 104 | + echo "$key=$value" >> "$GITHUB_OUTPUT" |
| 105 | + fi |
| 106 | + done < sign-metadata/build-metadata.env |
| 107 | + stage: |
| 108 | + name: 🎭 Deploy to Staging |
| 109 | + needs: |
| 110 | + - prepare |
| 111 | + uses: ./.github/workflows/stage.yml |
| 112 | + with: |
| 113 | + DISPLAY_VERSION: "${{ needs.prepare.outputs.display_version }}" |
| 114 | + PRE_RELEASE: "${{ needs.prepare.outputs.pre_release }}" |
| 115 | + SIGN_RUN_ID: "${{ needs.prepare.outputs.sign_run_id }}" |
| 116 | + secrets: |
| 117 | + AWS_ACCESS_KEY_ID: "${{ secrets.AWS_ACCESS_KEY_ID }}" |
| 118 | + AWS_SECRET_ACCESS_KEY: "${{ secrets.AWS_SECRET_ACCESS_KEY }}" |
| 119 | + CF_ENDPOINT: "${{ secrets.CF_ENDPOINT }}" |
| 120 | + production: |
| 121 | + name: 🚀 Deploy to Production |
| 122 | + needs: |
| 123 | + - stage |
| 124 | + uses: ./.github/workflows/production.yml |
| 125 | + with: |
| 126 | + COMMIT_SHA: "${{ needs.prepare.outputs.commit_sha }}" |
| 127 | + PRE_RELEASE: "${{ needs.prepare.outputs.pre_release }}" |
| 128 | + DISPLAY_VERSION: "${{ needs.prepare.outputs.display_version }}" |
| 129 | + secrets: |
| 130 | + AWS_ACCESS_KEY_ID: "${{ secrets.AWS_ACCESS_KEY_ID }}" |
| 131 | + AWS_SECRET_ACCESS_KEY: "${{ secrets.AWS_SECRET_ACCESS_KEY }}" |
| 132 | + CF_AUTH: "${{ secrets.CF_AUTH }}" |
| 133 | + CF_ENDPOINT: "${{ secrets.CF_ENDPOINT }}" |
| 134 | + CF_ZONE_ID: "${{ secrets.CF_ZONE_ID }}" |
0 commit comments