Publish all execution images #20
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 all execution images" | |
| on: | |
| workflow_run: | |
| workflows: | |
| - Publish base image | |
| types: | |
| - completed | |
| env: | |
| # Those workflows should not be triggered when a new base image has been rebuilt. | |
| EXCLUDE_WORKFLOWS: "all.yml dependabot.yml phusion.yml" | |
| GITHUB_TOKEN: ${{ secrets.OPENHPI_BOT_TOKEN }} | |
| jobs: | |
| docker: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Download branch name artifact | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| 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 == "branch_name" | |
| })[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); | |
| } | |
| fs.writeFileSync(path.join(temp, 'branch_name.zip'), Buffer.from(download.data)); | |
| - name: Unzip branch name artifact | |
| run: unzip ${{ runner.temp }}/artifacts/branch_name.zip -d ${{ runner.temp }}/artifacts | |
| - name: Trigger other workflows | |
| run: | | |
| for workflow in .github/workflows/*.yml; do | |
| if [[ ! " ${EXCLUDE_WORKFLOWS[@]} " =~ " $(basename $workflow) " ]]; then | |
| echo "Triggering workflow run $(basename $workflow) for $(cat ${{ runner.temp }}/artifacts/branch_name)" | |
| gh workflow run $(basename $workflow) --ref $(cat ${{ runner.temp }}/artifacts/branch_name) | |
| fi | |
| done |