|
| 1 | +name: Build |
| 2 | + |
| 3 | +on: |
| 4 | + repository_dispatch: |
| 5 | + types: [Build] |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +concurrency: |
| 9 | + group: ${{ github.workflow }}-${{ github.event.client_payload.tag || github.run_id }} |
| 10 | + cancel-in-progress: true |
| 11 | + |
| 12 | +jobs: |
| 13 | + build: |
| 14 | + if: > |
| 15 | + github.event_name == 'repository_dispatch' && |
| 16 | + github.event.client_payload.tag != '' |
| 17 | + runs-on: ${{ github.event.repository.visibility == 'public' && 'ubuntu-latest' || 'self-hosted' }} |
| 18 | + permissions: |
| 19 | + contents: write |
| 20 | + actions: read |
| 21 | + steps: |
| 22 | + - name: Verify source workflow not cancelled |
| 23 | + id: source_run |
| 24 | + uses: actions/github-script@v7 |
| 25 | + with: |
| 26 | + script: | |
| 27 | + const runId = Number(context.payload.client_payload?.source_run_id || 0); |
| 28 | + if (!runId) { |
| 29 | + core.setOutput('proceed', 'true'); |
| 30 | + return; |
| 31 | + } |
| 32 | +
|
| 33 | + try { |
| 34 | + const { data } = await github.rest.actions.getWorkflowRun({ |
| 35 | + owner: context.repo.owner, |
| 36 | + repo: context.repo.repo, |
| 37 | + run_id: runId, |
| 38 | + }); |
| 39 | +
|
| 40 | + const cancelled = data.status === 'completed' && data.conclusion === 'cancelled'; |
| 41 | + core.setOutput('proceed', cancelled ? 'false' : 'true'); |
| 42 | +
|
| 43 | + if (cancelled) { |
| 44 | + core.info(`Source workflow run ${runId} was cancelled. Skipping build.`); |
| 45 | + } |
| 46 | + } catch (error) { |
| 47 | + core.warning(`Could not verify source workflow run ${runId}: ${error.message}`); |
| 48 | + core.setOutput('proceed', 'true'); |
| 49 | + } |
| 50 | +
|
| 51 | + - uses: actions/checkout@v5 |
| 52 | + if: steps.source_run.outputs.proceed == 'true' |
| 53 | + with: |
| 54 | + ref: ${{ github.event.client_payload.tag }} |
| 55 | + |
| 56 | + - name: Setup Node.js |
| 57 | + if: steps.source_run.outputs.proceed == 'true' |
| 58 | + uses: actions/setup-node@v5 |
| 59 | + with: |
| 60 | + node-version: '20' |
| 61 | + cache: 'npm' |
| 62 | + cache-dependency-path: package-lock.json |
| 63 | + |
| 64 | + - name: Create package |
| 65 | + if: steps.source_run.outputs.proceed == 'true' |
| 66 | + run: | |
| 67 | + rm -rf *.tar.gz |
| 68 | + npx --yes wspackager@latest |
| 69 | +
|
| 70 | + - name: Check package output |
| 71 | + id: check_files |
| 72 | + if: steps.source_run.outputs.proceed == 'true' |
| 73 | + run: | |
| 74 | + if ls *.tar.gz >/dev/null 2>&1; then |
| 75 | + echo "files_exists=true" >> "$GITHUB_OUTPUT" |
| 76 | + else |
| 77 | + echo "files_exists=false" >> "$GITHUB_OUTPUT" |
| 78 | + fi |
| 79 | +
|
| 80 | + - name: On Build Failure |
| 81 | + if: steps.source_run.outputs.proceed == 'true' && steps.check_files.outputs.files_exists == 'false' |
| 82 | + run: | |
| 83 | + echo "Packaging FAILED" && exit 1 |
| 84 | +
|
| 85 | + - name: Release Build |
| 86 | + if: steps.source_run.outputs.proceed == 'true' && steps.check_files.outputs.files_exists == 'true' |
| 87 | + uses: softprops/action-gh-release@v2 |
| 88 | + with: |
| 89 | + tag_name: ${{ github.event.client_payload.tag }} |
| 90 | + files: "*.tar.gz" |
0 commit comments