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 861896a
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions .github/workflows/k8s-content-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ 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
permissions:
contents: read
id-token: write
packages: write
outputs:
pr-number: ${{ steps.get-pr-number.outputs.pr-number }}
steps:
Expand All @@ -33,25 +37,19 @@ jobs:
});
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:
Expand All @@ -63,21 +61,23 @@ jobs:
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
- name: Upsert comment in PR
uses: thollander/actions-comment-pull-request@v2
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 }}`'
});
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
message: |
:robot: A k8s content image for this PR is available at:
`ghcr.io/complianceascode/k8scontent:${{ needs.get-pr-number.outputs.pr-number }}`
<details>
<summary>Click here to see how to deploy it</summary>
If you alread have Compliance Operator deployed:
```utils/build_ds_container.py -i ghcr.io/complianceascode/k8scontent:${{ needs.get-pr-number.outputs.pr-number }}```
Otherwise deploy the content and operator together by checking out ComplianceAsCode/compliance-operator and:
```CONTENT_IMAGE=ghcr.io/complianceascode/k8scontent:${{ needs.get-pr-number.outputs.pr-number }} make deploy-local```
</details>
comment_tag: kubernetes_content_image
pr_number: ${{ needs.get-pr-number.outputs.pr-number }}

0 comments on commit 861896a

Please sign in to comment.