Skip to content

Test PR and Upload to Docker Hub #4

Test PR and Upload to Docker Hub

Test PR and Upload to Docker Hub #4

Workflow file for this run

name: Test PR and Upload to Docker Hub
on:
workflow_run:
workflows: ["Build Pull Request"]
types:
- completed
env:
PUID: '1000'
PGID: '1000'
PHP_TZ: 'UTC'
jobs:
upload:
runs-on: ubuntu-latest
if: >
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success'
outputs:
PR_NO: ${{ steps.get_pull.outputs.PR_NO }}
check_id: ${{ fromJson(steps.create_check.outputs.result).data.id }}
permissions:
actions: read
checks: write
contents: read
pull-requests: write
steps:
-
name: 'Download artifact'
uses: actions/[email protected]
with:
script: |
var artifacts = await github.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{ github.event.workflow_run.id }},
});
var matchArtifact = artifacts.data.artifacts.filter((artifact) => {
return artifact.name == "artifact"
})[0];
var download = await github.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
var fs = require('fs');
fs.writeFileSync('${{github.workspace}}/artifact.zip', Buffer.from(download.data));
-
name: "Unzip"
run: unzip artifact.zip && sha256sum invoiceshelf.tar
-
name: "Get Pull Request number and SHA"
id: get_pull
run: |
cat pr && echo "PR_NO=`cat pr`" >> $GITHUB_OUTPUT
cat sha && echo "PR_SHA=`cat sha`" >> $GITHUB_OUTPUT
-
name: "Create check"
id: create_check
uses: actions/github-script@v6
env:
parameter_url: '${{ github.event.workflow_run.html_url }}'
with:
script: |
return await github.rest.checks.create({
owner: context.repo.owner,
repo: context.repo.repo,
head_sha: "${{ steps.get_pull.outputs.PR_SHA }}",
name: "Test Image",
status: "in_progress",
details_url: process.env.parameter_url,
});
-
name: debug
run: echo '${{ steps.create_check.outputs.result }}'
-
name: "Import image"
run: docker image load -i ./invoiceshelf.tar
-
name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Push
run: docker image push invoiceshelf/invoiceshelf:testing-${{ github.event.workflow_run.id }}
retag:
needs: [upload]
runs-on: ubuntu-latest
container:
image: gcr.io/go-containerregistry/crane:debug
steps:
-
name: Retag image
env:
PR_NO: ${{ needs.upload.outputs.PR_NO }}
run: |
crane auth login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_TOKEN }} index.docker.io
crane tag invoiceshelf/invoiceshelf:testing-${{ github.event.workflow_run.id }} testing-pull$PR_NO
update_check:
if: github.event.workflow_run.conclusion == 'success'
needs: [upload,retag]
runs-on: ubuntu-latest
permissions:
actions: read
checks: write
contents: read
pull-requests: write
steps:
-
name: "Update check"
uses: actions/github-script@v6
with:
script: |
await github.rest.checks.update({
owner: context.repo.owner,
repo: context.repo.repo,
check_run_id: ${{ needs.upload.outputs.check_id }},
name: "Test Image",
status: "completed",
conclusion: "${{ needs.retag.result }}",
});