Kubernetes content image for PR #209
This file contains 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: Kubernetes content image for PR | |
on: | |
workflow_run: | |
workflows: [Kubernetes content image for PR Trigger] | |
types: | |
- completed | |
jobs: | |
get-pr-number: | |
name: Get PR number | |
runs-on: ubuntu-latest | |
outputs: | |
pr-number: ${{ steps.read-pr-number.outputs.pr-number }} | |
steps: | |
- name: 'Download artifacts' | |
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 == "pr_number" | |
})[0]; | |
let download = await github.rest.actions.downloadArtifact({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
artifact_id: matchArtifact.id, | |
archive_format: 'zip', | |
}); | |
let fs = require('fs'); | |
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/pr_number.zip`, Buffer.from(download.data)); | |
- name: 'Unzip artifact' | |
run: unzip pr_number.zip | |
- name: 'Read PR number' | |
run: | | |
echo "pr-number=$(cat pr/pr_number)" >> "$GITHUB_OUTPUT" | |
container-main: | |
needs: | |
- get-pr-number | |
permissions: | |
contents: read | |
id-token: write | |
packages: write | |
runs-on: ubuntu-latest | |
outputs: | |
image-digest: ${{ steps.container_info.outputs.image-digest }} | |
image-tags: ${{ steps.container_info.outputs.image-tags }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
ref: refs/pull/${{ needs.get-pr-number.outputs.pr-number }}/head | |
- name: Login to ghcr.io | |
uses: docker/[email protected] | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v2 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Docker metadata | |
id: meta | |
uses: docker/metadata-action@v4 | |
with: | |
images: ghcr.io/complianceascode/k8scontent | |
tags: | | |
type=raw,value=${{ needs.get-pr-number.outputs.pr-number }} | |
type=sha,format=long | |
labels: | | |
org.opencontainers.image.source=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY} | |
org.opencontainers.image.title=Kubernetes content | |
org.opencontainers.image.version=${{ needs.get-pr-number.outputs.pr-number }} | |
org.opencontainers.image.licenses='BSD-3-Clause' | |
org.opencontainers.image.vendor='Compliance Operator Authors' | |
- name: Build container images and push | |
id: docker_build | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
file: ./Dockerfiles/ocp4_content | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
push: true | |
platforms: 'linux/amd64' | |
- name: Get container info | |
id: container_info | |
run: | | |
image_tags="${{ needs.get-pr-number.outputs.pr-number }}" | |
echo "image-digest=${{ steps.docker_build.outputs.digest }}" >> $GITHUB_OUTPUT | |
echo "image-tags=${{ needs.get-pr-number.outputs.pr-number }}" >> $GITHUB_OUTPUT | |
comment-pr: | |
needs: | |
- container-main | |
- get-pr-number | |
runs-on: ubuntu-latest | |
name: Comment on the PR | |
steps: | |
- uses: actions/github-script@v7 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
await github.rest.issues.createComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: ${{ needs.get-pr-number.outputs.pr-number }}, | |
body: ':robot: The image for this PR is available at: | |
`ghcr.io/complianceascode/k8scontent:${{ needs.get-pr-number.outputs.pr-number }}`' | |
}); |