Skip to content

Commit

Permalink
Rework the k8s content image workflow
Browse files Browse the repository at this point in the history
- Fix its execution by a PR trigger
- Add instructions to deploy PR k8s content image.
  • Loading branch information
yuumasato committed Feb 1, 2024
1 parent e3ce7cf commit 15178b6
Showing 1 changed file with 3 additions and 70 deletions.
73 changes: 3 additions & 70 deletions .github/workflows/k8s-content-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,77 +7,10 @@ on:
- completed

jobs:
get-pr-number:
name: Get PR number
content-image-for-pr:
name: Build a k8s content image from a PR
runs-on: ubuntu-latest
outputs:
pr-number: ${{ steps.get-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 "::set-output name=pr-number::$(cat pr/pr_number)"
container-main:
needs:
- get-pr-number
permissions:
contents: read
id-token: write
packages: write
runs-on: ubuntu-latest
steps:
- name: Checkout PR branch
uses: actions/checkout@v4
with:
ref: refs/pull/${{ needs.get-pr-number.outputs.pr-number }}/head
- name: Build and push container image
uses: metal-toolbox/container-push/.github/workflows/container-push.yml@main
with:
name: k8scontent
tag: ${{ needs.get-pr-number.outputs.pr-number }}
latest: false
registry_org: complianceascode
dockerfile_path: ./Dockerfiles/ocp4_content
licenses: BSD
vendor: ComplianceAsCode authors

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 }}`'
});
echo "Hello World!"

0 comments on commit 15178b6

Please sign in to comment.