feat(ci): build_test PR command #2724
Workflow file for this run
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: CI build and push (PR) | |
concurrency: | |
group: ci-${{ github.run_id }} | |
cancel-in-progress: true | |
on: | |
issue_comment: | |
types: | |
- created | |
jobs: | |
check-before-build: | |
runs-on: ubuntu-latest | |
if: github.repository_owner == 'cryostatio' && github.event.issue.pull_request && startsWith(github.event.comment.body, '/build_test') | |
steps: | |
- name: Comment if needs-triage label applied | |
if: ${{ contains(github.event.issue.labels.*.name, 'needs-triage') }} | |
uses: thollander/actions-comment-pull-request@v2 | |
with: | |
message: |- | |
This PR still has the needs-triage label applied. Please remove it, then try run again. | |
- name: Fail if needs-triage label applied | |
if: ${{ contains(github.event.issue.labels.*.name, 'needs-triage') }} | |
run: exit 1 | |
- name: Check command permission allowed | |
if: | | |
github.event.comment.author_association != 'MEMBER' && | |
github.event.comment.author_association != 'OWNER' && | |
!contains(github.event.issue.labels.*.name, 'safe-to-test') | |
uses: thollander/actions-comment-pull-request@v2 | |
with: | |
message: |- | |
You do not have permission to run the /build_test command. Please ask a member of the cryostatio | |
repository to run it for you or to apply the safe-to-test label. | |
- name: Fail if command permission is not allowed | |
if: | | |
github.event.comment.author_association != 'MEMBER' && | |
github.event.comment.author_association != 'OWNER' && | |
!contains(github.event.issue.labels.*.name, 'safe-to-test') | |
run: exit 1 | |
- name: React to comment | |
uses: actions/github-script@v4 | |
with: | |
script: | | |
const {owner, repo} = context.issue | |
github.reactions.createForIssueComment({ | |
owner, | |
repo, | |
comment_id: context.payload.comment.id, | |
content: "+1", | |
}); | |
checkout-branch: | |
runs-on: ubuntu-latest | |
needs: [check-before-build] | |
permissions: | |
contents: read | |
issues: read | |
pull-requests: read | |
outputs: | |
PR_head_ref: ${{ fromJSON(steps.comment-branch.outputs.result).ref }} | |
PR_head_sha: ${{ fromJSON(steps.comment-branch.outputs.result).sha }} | |
PR_repo: ${{ fromJSON(steps.comment-branch.outputs.result).repo.full_name }} | |
PR_repo_owner: ${{ fromJSON(steps.comment-branch.outputs.result).repo.owner.login }} | |
steps: | |
- uses: actions/github-script@v4 | |
id: comment-branch | |
with: | |
script: | | |
const result = await github.pulls.get ({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
pull_number: context.issue.number | |
}) | |
return result.data.head | |
code-analysis: | |
needs: [checkout-branch] | |
uses: ./.github/workflows/ci-code-analysis.yml | |
with: | |
checkout-repo: ${{ needs.checkout-branch.outputs.PR_repo }} | |
checkout-ref: ${{ needs.checkout-branch.outputs.PR_head_ref }} | |
build-and-test: | |
needs: [code-analysis, checkout-branch] | |
strategy: | |
matrix: | |
arch: [amd64, arm64] | |
uses: ./.github/workflows/ci-build-image.yml | |
with: | |
build-arch: ${{ matrix.arch }} | |
checkout-repo: ${{ needs.checkout-branch.outputs.PR_repo }} | |
checkout-ref: ${{ needs.checkout-branch.outputs.PR_head_ref }} | |
skip-itests: ${{ matrix.arch != 'amd64' }} | |
push-to-ghcr: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
arch: [amd64, arm64] | |
outputs: | |
amd64_image: ${{ steps.amd64_image.outputs.image }} | |
arm64_image: ${{ steps.arm64_image.outputs.image }} | |
needs: [build-and-test, checkout-branch] | |
env: | |
repo_owner: ${{ needs.checkout-branch.outputs.PR_repo_owner }} | |
head_sha: ${{ needs.checkout-branch.outputs.head_sha}} | |
steps: | |
- uses: actions/download-artifact@v3 | |
with: | |
name: cryostat-${{ matrix.arch }} | |
- name: Load cryostat image | |
run: podman load -i cryostat-${{ matrix.arch }}.tar | |
- name: Tag cryostat image | |
run: podman tag cryostat ghcr.io/${{ env.repo_owner }}/cryostat:pr-${{ github.event.number }}-${{ env.head_sha }}-linux-${{ matrix.arch }} | |
- name: Push PR test image to ghcr.io | |
id: push-to-ghcr | |
uses: redhat-actions/push-to-registry@v2 | |
with: | |
image: cryostat | |
tags: pr-${{ github.event.number }}-${{ env.head_sha }}-linux-${{ matrix.arch }} | |
registry: ghcr.io/${{ env.repo_owner }} | |
username: ${{ github.event.comment.user.login }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Store images as output amd64 | |
if: ${{ matrix.arch }} == 'amd64' | |
id: amd64_image | |
run: echo "image=${{ steps.push-to-ghcr.outputs.registry-path }}" >> "$GITHUB_OUTPUT" | |
- name: Store images as output | |
if: ${{ matrix.arch }} == 'arm64' | |
id: arm64_image | |
run: echo "image=${{ steps.push-to-ghcr.outputs.registry-path }}" >> "$GITHUB_OUTPUT" | |
comment-image: | |
runs-on: ubuntu-latest | |
needs: [push-to-ghcr] | |
steps: | |
- name: Create markdown table | |
uses: petems/csv-to-md-table-action@v3.0.0 | |
env: | |
amd64_image: ${{ needs.push-to-ghcr.outputs.amd64_image }} | |
arm64_image: ${{ needs.push-to-ghcr.outputs.arm64_image }} | |
with: | |
csvinput: | | |
ARCH, IMAGE | |
AMD64, ${{ env.amd64_image }} | |
ARM64, ${{ env.arm64_image }} | |
- uses: thollander/actions-comment-pull-request@v2 | |
with: | |
message: |- | |
${{ steps.md-table.outputs.markdown-table }} | |
To run smoketest: | |
``` | |
CRYOSTAT_IMAGE=${{ env.amd64_image }} sh smoketest.sh | |
CRYOSTAT_IMAGE=${{ env.arm64_image }} sh smoketest.sh | |
``` |