|
| 1 | +name: Upload Docker Image (On PR - after build) |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_run: |
| 5 | + workflows: ["Receive PR"] |
| 6 | + types: |
| 7 | + - completed |
| 8 | + |
| 9 | +jobs: |
| 10 | + upload-docker-pr: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + if: > |
| 13 | + github.event.workflow_run.event == 'pull_request' && |
| 14 | + github.event.workflow_run.conclusion == 'success' |
| 15 | + outputs: |
| 16 | + imagename: ${{ steps.extract_image.outputs.imagename }} |
| 17 | + steps: |
| 18 | + - name: Download PR Image |
| 19 | + |
| 20 | + with: |
| 21 | + script: | |
| 22 | + var artifacts = await github.actions.listWorkflowRunArtifacts({ |
| 23 | + owner: context.repo.owner, |
| 24 | + repo: context.repo.repo, |
| 25 | + run_id: ${{github.event.workflow_run.id }}, |
| 26 | + }); |
| 27 | + var matchArtifact = artifacts.data.artifacts.filter((artifact) => { |
| 28 | + return artifact.name == "pr" |
| 29 | + })[0]; |
| 30 | + var download = await github.actions.downloadArtifact({ |
| 31 | + owner: context.repo.owner, |
| 32 | + repo: context.repo.repo, |
| 33 | + artifact_id: matchArtifact.id, |
| 34 | + archive_format: 'zip', |
| 35 | + }); |
| 36 | + var fs = require('fs'); |
| 37 | + fs.writeFileSync('${{github.workspace}}/pr.zip', Buffer.from(download.data)); |
| 38 | + - run: ls -hal |
| 39 | + - name: Unzip PR Image |
| 40 | + run: | |
| 41 | + unzip pr.zip |
| 42 | + - run: ls -hal |
| 43 | + - name: Check PR Metadata |
| 44 | + run: | |
| 45 | + cat ./pr/prnumber |
| 46 | + cat ./pr/branchname |
| 47 | + cat ./pr/imagename |
| 48 | + - name: Extract image name |
| 49 | + shell: bash |
| 50 | + run: echo "imagename="$(cat test)"" | tr / - >> $GITHUB_OUTPUT |
| 51 | + id: extract_image |
| 52 | + - name: Load PR Image |
| 53 | + run: | |
| 54 | + docker load --input ./pr/untrusted-pr-image.tar |
| 55 | + docker image ls -a |
| 56 | +
|
| 57 | + - name: Set up Docker Buildx |
| 58 | + uses: docker/setup-buildx-action@v3 |
| 59 | + - name: Login to DockerHub |
| 60 | + uses: docker/login-action@v3 |
| 61 | + with: |
| 62 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 63 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 64 | + - name: Build and Push |
| 65 | + id: docker_build |
| 66 | + uses: docker/build-push-action@v6 |
| 67 | + with: |
| 68 | + file: docker/Dockerfile |
| 69 | + push: true |
| 70 | + tags: ${{ steps.extract_image.outputs.imagename }} |
| 71 | + |
| 72 | + comment_docker_image: |
| 73 | + needs: upload-docker-pr |
| 74 | + runs-on: ubuntu-latest |
| 75 | + steps: |
| 76 | + - name: Comment name of docker image |
| 77 | + id: comment_docker_image |
| 78 | + uses: actions/github-script@v6 |
| 79 | + with: |
| 80 | + script: | |
| 81 | + github.rest.issues.createComment({ |
| 82 | + issue_number: context.issue.number, |
| 83 | + owner: context.repo.owner, |
| 84 | + repo: context.repo.repo, |
| 85 | + body: 'Created image with name `${{ needs.upload-docker-pr.outputs.imagename }}`.' |
| 86 | + }) |
0 commit comments