diff --git a/.github/workflows/ci-build-image.yml b/.github/workflows/ci-build-image.yml index 09c18f24d5..a0b20983d0 100644 --- a/.github/workflows/ci-build-image.yml +++ b/.github/workflows/ci-build-image.yml @@ -1,3 +1,5 @@ +name: build cryostat image + on: workflow_call: inputs: @@ -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 @@ -42,6 +40,8 @@ jobs: build-image: runs-on: ubuntu-latest + permissions: + pull-requests: write needs: [get-pom-properties] steps: - name: Install qemu @@ -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 }} @@ -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 + 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 @@ -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 diff --git a/.github/workflows/integrated-test.yml b/.github/workflows/integrated-test.yml new file mode 100644 index 0000000000..5f60f808f9 --- /dev/null +++ b/.github/workflows/integrated-test.yml @@ -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' }} + 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 diff --git a/.github/workflows/pr-ci.yml b/.github/workflows/pr-ci.yml index d32dc2a23a..f3abd44d7d 100644 --- a/.github/workflows/pr-ci.yml +++ b/.github/workflows/pr-ci.yml @@ -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 @@ -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 }} @@ -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: + - 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] @@ -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: @@ -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 }} @@ -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: + 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: + 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 + });