Publish #9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Publish | |
| on: | |
| workflow_run: | |
| workflows: [Build] | |
| types: | |
| - completed | |
| jobs: | |
| publish: | |
| if: ${{ github.event.workflow_run.conclusion == 'success' }} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Workflow run details | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const commitSha = context.payload.workflow_run.head_sha; | |
| const worflowRunId = context.payload.workflow_run.id; | |
| console.log(`Commit SHA: ${commitSha}`); | |
| console.log(`Workflow run ID: ${worflowRunId}`); | |
| // console.log(`Event: ${JSON.stringify(context.payload, null, 2)}`); | |
| console.log(JSON.stringify(context, null, 2)); | |
| # - run: mkdir -p "${{ runner.temp }}/artifacts" | |
| # - name: "Download artifact" | |
| # uses: actions/download-artifact@v4 | |
| # with: | |
| # name: output | |
| # run-id: ${{ github.event.workflow_run.id }} | |
| # path: "${{ runner.temp }}/artifacts" | |
| - name: "Download artifact" | |
| uses: actions/github-script@v7 | |
| if: ${{ github.event.workflow_run.conclusion == 'success' }} | |
| with: | |
| script: | | |
| console.log(`Event: ${JSON.stringify(context.payload, null, 2)}`); | |
| const commitSha = context.payload.workflow_run.head_sha; | |
| console.log(`Commit SHA: ${commitSha}`); | |
| console.log(`Workflow run ID: ${context.payload.workflow_run.id}`); | |
| let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| run_id: context.payload.workflow_run.id, | |
| }); | |
| let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => { | |
| return artifact.name == "output" | |
| })[0]; | |
| let download = await github.rest.actions.downloadArtifact({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| artifact_id: matchArtifact.id, | |
| archive_format: 'zip', | |
| }); | |
| const fs = require('fs'); | |
| const path = require('path'); | |
| const temp = '${{ runner.temp }}/artifacts'; | |
| if (!fs.existsSync(temp)){ | |
| fs.mkdirSync(temp); | |
| } | |
| const outFile = path.join(temp, 'output.zip'); | |
| fs.writeFileSync(outFile, Buffer.from(download.data)); | |
| console.log(`Artifact downloaded to ${outFile}`); | |
| - name: "Unzip artifact" | |
| run: unzip "${{ runner.temp }}/artifacts/output.zip" -d "${{ runner.temp }}/artifacts" | |
| - name: "Read output" | |
| run: cat "${{ runner.temp }}/artifacts/output.txt" |