Skip to content

Commit

Permalink
ci(oci): push PR test images to ghcr (#1133)
Browse files Browse the repository at this point in the history
* ci(mergify): auto-apply safe-to-test label for PRs from reviewers

* only run integration tests when safe-to-test label is applied

* add CI job to push test image to ghcr.io

* fail steps if tests not allowed to run

* trigger on more PR event types

* fixup! fail steps if tests not allowed to run

* tag downloaded artifact with PR before pushing to ghcr

* use pull_request_target event for privileged context

* only run these actions on PR, not push

* update test image message

* correcet event names

* split PR and push workflows, set concurrency levels

* remove redundant curly brace syntax

* pr-ci uses reusable

* use 'sibling' reusables in same subdirectory/at same ref

* correct reusable dependencies

* remove unnecessary event type checking

* use event repo owner instead of hardcoded

* fixup! remove unnecessary event type checking

* rename reuse jobs

* slim check deps

* fixup! rename reuse jobs

* move label check into top-level workflow

* add owner check to top-level workflows

* use action output for registry link in comment

* fixup! fixup! rename reuse jobs

* update readme CI badge
  • Loading branch information
andrewazores authored Oct 26, 2022
1 parent 62a7f9a commit 71b1810
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 71 deletions.
72 changes: 2 additions & 70 deletions .github/workflows/ci.yaml → .github/workflows/ci-jobs.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
name: CI build and push

on:
push:
branches:
- main
- v[0-9]+
- v[0-9]+.[0-9]+
- cryostat-v[0-9]+.[0-9]+
pull_request:
branches:
- main
- v[0-9]+
- v[0-9]+.[0-9]+
- cryostat-v[0-9]+.[0-9]+
workflow_call:

jobs:
get-pom-properties:
Expand Down Expand Up @@ -110,30 +97,21 @@ jobs:
- 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() }}
if: failure()
run: ls -1dt target/cryostat-itest-*.log | head -n1 | xargs cat
- uses: skjolber/maven-cache-github-action@v1
with:
step: save

spotless:
runs-on: ubuntu-latest
needs: [build-image]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v2
with:
java-version: '17'
distribution: 'adopt'
- uses: skjolber/maven-cache-github-action@v1
with:
step: restore
- name: Run spotless
run: mvn spotless:check

spotbugs:
runs-on: ubuntu-latest
needs: [build-image]
steps:
- uses: actions/checkout@v2
with:
Expand All @@ -151,53 +129,7 @@ jobs:

shellcheck:
runs-on: ubuntu-latest
needs: [build-image]
steps:
- uses: actions/checkout@v2
- uses: skjolber/maven-cache-github-action@v1
with:
step: restore
- name: Run shellcheck
run: mvn shellcheck:check

push-to-quay:
runs-on: ubuntu-latest
needs: [get-pom-properties, integration-tests, spotless, spotbugs, shellcheck]
env:
CRYOSTAT_IMG: quay.io/cryostat/cryostat
steps:
- uses: actions/download-artifact@v3
with:
name: cryostat
if: ${{ github.event_name == 'push' && github.repository_owner == 'cryostatio' }}
- name: Load cryostat image
run: podman load -i cryostat.tar
if: ${{ github.event_name == 'push' && github.repository_owner == 'cryostatio' }}
- name: Tag images
id: tag-image
env:
IMAGE_VERSION: ${{ needs.get-pom-properties.outputs.image-version }}
run: |
podman tag $CRYOSTAT_IMG $CRYOSTAT_IMG:$IMAGE_VERSION
if [ "$GITHUB_REF" == "refs/heads/main" ]; then
podman tag \
${{ env.CRYOSTAT_IMG }}:$IMAGE_VERSION \
${{ env.CRYOSTAT_IMG }}:latest
echo "::set-output name=tags::$IMAGE_VERSION latest"
else
echo "::set-output name=tags::$IMAGE_VERSION"
fi
if: ${{ github.event_name == 'push' && github.repository_owner == 'cryostatio' }}
- name: Push to quay.io
id: push-to-quay
uses: redhat-actions/push-to-registry@v2
with:
image: cryostat
tags: ${{ steps.tag-image.outputs.tags }}
registry: quay.io/cryostat
username: cryostat+bot
password: ${{ secrets.REGISTRY_PASSWORD }}
if: ${{ github.event_name == 'push' && github.repository_owner == 'cryostatio' }}
- name: Print image URL
run: echo "Image pushed to ${{ steps.push-to-quay.outputs.registry-paths }}"
if: ${{ github.event_name == 'push' && github.repository_owner == 'cryostatio' }}
62 changes: 62 additions & 0 deletions .github/workflows/pr-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: CI build and push (PR)

concurrency:
group: pr-${{ github.event.number }}
cancel-in-progress: true

on:
pull_request_target:
types:
- opened
- reopened
- synchronize
- labeled
- unlabeled
- edited
branches:
- main
- v[0-9]+
- v[0-9]+.[0-9]+
- cryostat-v[0-9]+.[0-9]+

jobs:
build-and-test:
uses: ./.github/workflows/ci-jobs.yml
if: github.repository_owner == 'cryostatio' && contains(github.event.pull_request.labels.*.name, 'safe-to-test')

push-to-ghcr:
runs-on: ubuntu-latest
needs: [build-and-test]
steps:
- name: Fail if safe-to-test label not applied
if: ${{ !contains(github.event.pull_request.labels.*.name, 'safe-to-test') }}
run: exit 1
- uses: actions/download-artifact@v3
with:
name: cryostat
if: github.repository_owner == 'cryostatio'
- name: Load cryostat image
run: podman load -i cryostat.tar
if: github.repository_owner == 'cryostatio'
- name: Tag cryostat image
run: podman tag cryostat ghcr.io/${{ github.repository_owner }}/cryostat:pr-${{ github.event.number }}
if: github.repository_owner == 'cryostatio'
- 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 }}
registry: ghcr.io/${{ github.repository_owner }}
username: ${{ github.event.pull_request.user.login }}
password: ${{ secrets.CI_GHCR_TEST_SECRET }}
if: github.repository_owner == 'cryostatio'
- name: Comment test image link
uses: thollander/actions-comment-pull-request@v1
with:
message: |-
Test image available:
```
$ CRYOSTAT_IMAGE=${{ steps.push-to-ghcr.outputs.registry-path }} sh smoketest.sh
```
if: github.repository_owner == 'cryostatio'
57 changes: 57 additions & 0 deletions .github/workflows/push-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: CI build and push

concurrency:
group: pr-${{ github.event.number }}

on:
push:
branches:
- main
- v[0-9]+
- v[0-9]+.[0-9]+
- cryostat-v[0-9]+.[0-9]+

jobs:
build-and-test:
uses: ./.github/workflows/ci-jobs.yml
if: github.repository_owner == 'cryostatio'
push-to-quay:
runs-on: ubuntu-latest
needs: [build-and-test]
env:
CRYOSTAT_IMG: quay.io/cryostat/cryostat
steps:
- uses: actions/download-artifact@v3
with:
name: cryostat
if: github.repository_owner == 'cryostatio'
- name: Load cryostat image
run: podman load -i cryostat.tar
if: github.repository_owner == 'cryostatio'
- name: Tag images
id: tag-image
env:
IMAGE_VERSION: ${{ needs.get-pom-properties.outputs.image-version }}
run: |
podman tag $CRYOSTAT_IMG $CRYOSTAT_IMG:$IMAGE_VERSION
if [ "$GITHUB_REF" == "refs/heads/main" ]; then
podman tag \
${{ env.CRYOSTAT_IMG }}:$IMAGE_VERSION \
${{ env.CRYOSTAT_IMG }}:latest
echo "::set-output name=tags::$IMAGE_VERSION latest"
else
echo "::set-output name=tags::$IMAGE_VERSION"
fi
if: github.repository_owner == 'cryostatio'
- name: Push to quay.io
uses: redhat-actions/push-to-registry@v2
with:
image: cryostat
tags: ${{ steps.tag-image.outputs.tags }}
registry: quay.io/cryostat
username: cryostat+bot
password: ${{ secrets.REGISTRY_PASSWORD }}
if: github.repository_owner == 'cryostatio'
- name: Print image URL
run: echo "Image pushed to ${{ steps.push-to-quay.outputs.registry-paths }}"
if: github.repository_owner == 'cryostatio'
8 changes: 8 additions & 0 deletions .mergify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ pull_request_rules:
assignees:
- "{{ author }}"

- name: auto label PRs from reviewers
conditions:
- author=@reviewers
actions:
label:
add:
- safe-to-test

- name: dismiss stale reviews
conditions:
- base=main
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</picture>
</a>

[![CI build](https://github.com/cryostatio/cryostat/actions/workflows/ci.yaml/badge.svg)](https://github.com/cryostatio/cryostat/actions/workflows/ci.yaml)
[![CI build](https://github.com/cryostatio/cryostat/actions/workflows/push-ci.yml/badge.svg)](https://github.com/cryostatio/cryostat/actions/workflows/push-ci.yml)
[![Quay Repository](https://quay.io/repository/cryostat/cryostat/status "Quay Repository")](https://quay.io/repository/cryostat/cryostat)
[![Google Group : Cryostat Development](https://img.shields.io/badge/Google%20Group-Cryostat%20Development-blue.svg)](https://groups.google.com/g/cryostat-development)

Expand Down

0 comments on commit 71b1810

Please sign in to comment.