CI: Try simplifying builds by reusing already built artifacts #12
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: Build and Publish Docker Image | |
| on: | |
| push: | |
| branches: [ "main" ] | |
| env: | |
| DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} | |
| DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} | |
| IMAGE_NAME: mecoblock/sanitizetelebot | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v2 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v2 | |
| - name: Find Go workflow run | |
| id: find_go_run | |
| uses: actions/github-script@v6 | |
| with: | |
| script: | | |
| const runs = await github.rest.actions.listWorkflowRunsForRepo({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| workflow_id: 'go.yml', | |
| head_sha: context.sha, | |
| event: 'push', | |
| status: 'success', | |
| }); | |
| if (runs.data.workflow_runs.length === 0) { | |
| core.setFailed('No successful Go workflow run found for this commit.'); | |
| } else { | |
| core.setOutput('run_id', runs.data.workflow_runs[0].id); | |
| } | |
| - name: Download Go Artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| pattern: sanitizetelebot-linux-* | |
| repository: ${{ github.repository }} | |
| run-id: ${{ steps.find_go_run.outputs.run_id }} | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| path: ./bin | |
| - name: Login to DockerHub | |
| uses: docker/login-action@v2 | |
| with: | |
| username: ${{ env.DOCKERHUB_USERNAME }} | |
| password: ${{ env.DOCKERHUB_TOKEN }} | |
| - name: Build and push | |
| uses: docker/build-push-action@v4 | |
| with: | |
| context: . | |
| platforms: linux/amd64,linux/arm64 | |
| push: true | |
| tags: ${{ env.IMAGE_NAME }}:latest | |
| # Use a different binary for each platform | |
| build-args: | | |
| APP_BINARY=sanitizetelebot-linux-${TARGETARCH} |