Publish #5
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: | |
| download: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - 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)}`); | |
| 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" | |
| uses: actions/github-script@v7 | |
| with: | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| script: | | |
| const fs = require('fs'); | |
| const path = require('path'); | |
| const temp = '${{ runner.temp }}/artifacts'; | |
| const message = fs.readFileSync(path.join(temp, 'output.txt')); | |
| console.log(`The message is: ${message}`); |