Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ci): build_test command enhancements #1683

Merged
merged 22 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 10 additions & 52 deletions .github/workflows/ci-build-image.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
name: build cryostat image

on:
workflow_call:
inputs:
Expand All @@ -10,10 +12,6 @@ on:
build-arch:
required: true
type: string
skip-itests:
required: false
type: boolean
default: false
outputs:
image-version:
description: the Cryostat application version that will be built
Expand Down Expand Up @@ -42,6 +40,8 @@ jobs:

build-image:
runs-on: ubuntu-latest
permissions:
pull-requests: write
needs: [get-pom-properties]
steps:
- name: Install qemu
Expand All @@ -51,7 +51,6 @@ jobs:
sudo apt-get update
sudo apt-get install -y qemu-user-static
- uses: actions/checkout@v4
if: always()
with:
repository: ${{ inputs.checkout-repo }}
ref: ${{ inputs.checkout-ref }}
Expand All @@ -64,8 +63,13 @@ jobs:
- name: maven-settings
uses: s4u/maven-settings-action@v2
with:
servers: '[{"id": "github", "username": "dummy", "password": "${env.GITHUB_TOKEN_REF}"}]'
githubServer: false
- name: ghcr login
uses: redhat-actions/podman-login@v1
andrewazores marked this conversation as resolved.
Show resolved Hide resolved
with:
registry: ghcr.io/${{ github.repository_owner }}
username: ${{ github.event.comment.user.login }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: skjolber/maven-cache-github-action@v1
with:
step: restore
Expand All @@ -83,49 +87,3 @@ jobs:
- uses: skjolber/maven-cache-github-action@v1
with:
step: save

integration-tests:
runs-on: ubuntu-latest
needs: [build-image]
if: ${{ ! inputs.skip-itests }}
steps:
- name: Install xpath
run: |
sudo apt-get update
sudo apt-get install -y libxml-xpath-perl
- name: Install qemu
if: ${{ inputs.build-arch != 'amd64' }}
continue-on-error: true
run: |
sudo apt-get update
sudo apt-get install -y qemu-user-static
- uses: actions/checkout@v4
if: always()
with:
repository: ${{ inputs.checkout-repo }}
ref: ${{ inputs.checkout-ref }}
submodules: true
fetch-depth: 0
- uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- uses: actions/download-artifact@v3
with:
name: cryostat-${{ inputs.build-arch }}
- name: Load cryostat image
run: podman load -i cryostat-${{ inputs.build-arch }}.tar
- uses: skjolber/maven-cache-github-action@v1
with:
step: restore
- name: Run integration tests
run: POD_NAME=cryostat-itests CONTAINER_NAME=cryostat-itest ITEST_IMG_VERSION=latest bash repeated-integration-tests.bash
- name: Print itest logs
if: failure()
run: ls -1dt target/cryostat-itest-*.log | head -n1 | xargs cat
- name: Print itest container logs
if: failure()
run: ls -1dt target/cryostat-*.server.log | head -n1 | xargs cat
- uses: skjolber/maven-cache-github-action@v1
with:
step: save
77 changes: 77 additions & 0 deletions .github/workflows/integrated-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Retest Integration Tests

on:
workflow_call:
inputs:
checkout-repo:
required: false
type: string
checkout-ref:
required: false
type: string
build-arch:
required: true
type: string
pr-number:
required: false
type: string
sha-value:
required: false
type: string
skip-itests:
required: false
type: boolean
default: false

permissions:
contents: read
packages: read

jobs:
integration-tests:
runs-on: ubuntu-latest
steps:
- name: Install xpath
run: |
sudo apt-get update
sudo apt-get install -y libxml-xpath-perl
- name: Install qemu
if: ${{ inputs.build-arch != 'amd64' }}
andrewazores marked this conversation as resolved.
Show resolved Hide resolved
continue-on-error: true
run: |
sudo apt-get update
sudo apt-get install -y qemu-user-static
- uses: actions/checkout@v4
with:
repository: ${{ inputs.checkout-repo }}
ref: ${{ inputs.checkout-ref }}
submodules: true
fetch-depth: 0
- uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: maven-settings
uses: s4u/maven-settings-action@v2
with:
githubServer: true
- name: ghcr login
uses: redhat-actions/podman-login@v1
with:
registry: ghcr.io/${{ github.repository_owner }}
username: ${{ github.event.comment.user.login }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Pull cryostat image
run: podman pull ghcr.io/${{ github.repository_owner }}/cryostat:pr-${{ inputs.pr-number }}-${{ inputs.sha-value }}-linux-${{ inputs.build-arch }}
- name: retag image as quay
run: podman tag ghcr.io/${{ github.repository_owner }}/cryostat:pr-${{ inputs.pr-number }}-${{ inputs.sha-value }}-linux-${{ inputs.build-arch}} quay.io/cryostat/cryostat
- name: Run integration tests
run: POD_NAME=cryostat-itests CONTAINER_NAME=cryostat-itest ITEST_IMG_VERSION=latest bash repeated-integration-tests.bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Print itest logs
if: failure()
run: ls -1dt target/cryostat-itest-*.log | head -n1 | xargs cat
- name: Print itest container logs
if: failure()
run: ls -1dt target/cryostat-*.server.log | head -n1 | xargs catyea
136 changes: 123 additions & 13 deletions .github/workflows/pr-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ on:
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')
if: github.repository_owner == 'cryostatio' && github.event.issue.pull_request && (startsWith(github.event.comment.body, '/build_test') || startsWith(github.event.comment.body, '/retest'))
permissions:
pull-requests: write
steps:
- name: Fail if needs-triage label applied
- name: Fail if needs-triage label applied
if: ${{ contains(github.event.issue.labels.*.name, 'needs-triage') }}
run: exit 1
- name: Show warning if permission is denied
Expand All @@ -43,12 +43,12 @@ jobs:
repo,
comment_id: context.payload.comment.id,
content: "+1",
});
});

checkout-branch:
checkout-branch:
runs-on: ubuntu-latest
needs: [check-before-build]
outputs:
outputs:
PR_head_ref: ${{ fromJSON(steps.comment-branch.outputs.result).ref }}
PR_head_sha: ${{ fromJSON(steps.comment-branch.outputs.result).sha }}
PR_num: ${{ fromJSON(steps.comment-branch.outputs.result).num }}
Expand All @@ -69,13 +69,33 @@ jobs:

code-analysis:
needs: [checkout-branch]
if: startsWith(github.event.comment.body, '/build_test')
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]

start-comment:
runs-on: ubuntu-latest
needs: [check-before-build]
steps:
mwangggg marked this conversation as resolved.
Show resolved Hide resolved
- name: Leave Actions Run Comment
uses: actions/github-script@v6
with:
script: |
const runURL = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${{ github.run_id }}`;
const currentTime = new Date().toLocaleString('en-US', { timeZone: 'America/Toronto' });
const commentBody = `Workflow started at ${currentTime}. [View Actions Run](${runURL}).`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody
});

build-image:
needs: [checkout-branch]
if: github.event.issue.pull_request && startsWith(github.event.comment.body, '/build_test')
strategy:
matrix:
arch: [amd64, arm64]
Expand All @@ -84,15 +104,14 @@ jobs:
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
needs: [build-and-test, checkout-branch]
needs: [checkout-branch, build-image]
strategy:
matrix:
arch: [amd64, arm64]
outputs:
outputs:
amd64_image: ${{ steps.amd64_image.outputs.image }}
arm64_image: ${{ steps.arm64_image.outputs.image }}
env:
Expand Down Expand Up @@ -138,7 +157,7 @@ jobs:
- name: Create markdown table
id: md-table
uses: petems/csv-to-md-table-action@v3.0.0
with:
with:
csvinput: |
ARCH, IMAGE
amd64, ${{ env.amd64_image }}
Expand All @@ -150,9 +169,100 @@ jobs:

To run smoketest:
```
# amd64
# amd64
CRYOSTAT_IMAGE=${{ env.amd64_image }} sh smoketest.sh

# or arm64
CRYOSTAT_IMAGE=${{ env.arm64_image }} sh smoketest.sh
```

integration-test:
needs: [checkout-branch, push-to-ghcr]
strategy:
matrix:
arch: [amd64]
uses: ./.github/workflows/integrated-test.yml
with:
aali309 marked this conversation as resolved.
Show resolved Hide resolved
build-arch: ${{ matrix.arch }}
pr-number: ${{ github.event.issue.number }}
sha-value: ${{ needs.checkout-branch.outputs.PR_head_sha }}

retest-integration:
needs: [checkout-branch]
if: contains(github.event.comment.body, '/retest')
strategy:
matrix:
arch: [amd64]
uses: ./.github/workflows/integrated-test.yml
with:
build-arch: ${{ matrix.arch }}
pr-number: ${{ github.event.issue.number }}
sha-value: ${{ needs.checkout-branch.outputs.PR_head_sha }}

integration-test-pass:
aali309 marked this conversation as resolved.
Show resolved Hide resolved
runs-on: ubuntu-latest
needs: [integration-test]
steps:
- name: Leave Actions Run Comment
uses: actions/github-script@v6
with:
script: |
const runURL = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${{ github.run_id }}`;
const commentBody = `\`/build_test\` completed successfully ✅. \n[View Actions Run](${runURL}).`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody
});

retest-integration-pass:
runs-on: ubuntu-latest
needs: [retest-integration]
steps:
- name: Leave Actions Run Comment
uses: actions/github-script@v6
with:
script: |
const runURL = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${{ github.run_id }}`;
const commentBody = `\`/retest\` Integration: All tests pass ✅. \n[View Actions Run](${runURL}).`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody
});

comment-integration-test-fail:
if: (always() && contains(needs.*.result, 'failure'))
needs: [integration-test]
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v6
with:
script: |
const runURL = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${{ github.run_id }}`;
const commentBody = `\`/build_test\` : At least one test failed ❌. \n[View Actions Run](${runURL}).`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody
});

comment-retest-integration-fail:
if: (always() && contains(needs.*.result, 'failure'))
needs: [retest-integration]
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v6
with:
script: |
const runURL = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${{ github.run_id }}`;
const commentBody = `\`/retest\` Integration: At least one test failed ❌. \n[View Actions Run](${runURL}).`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody
});
Loading