Skip to content
This repository has been archived by the owner on Aug 19, 2024. It is now read-only.

Commit

Permalink
chore: only generate PR previews and next... (#161)
Browse files Browse the repository at this point in the history
* chore: only generate PR previews and next builds for paths listed in the GH action (exclude changes to doc, etc.)

Signed-off-by: Nick Boldt <[email protected]>

* indent

Signed-off-by: Nick Boldt <[email protected]>

* use a check-changes stage to set an env.CHANGES with either a list of changed files or a nullstring; if null, don't build anything

Signed-off-by: Nick Boldt <[email protected]>

* run 'PR Publish' stage for all PRs, but if no changes, skip the subsequent setup/build/publish stages

Signed-off-by: Nick Boldt <[email protected]>

---------

Signed-off-by: Nick Boldt <[email protected]>
  • Loading branch information
nickboldt authored Jan 29, 2024
1 parent 24d39ce commit 46e6c31
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 7 deletions.
21 changes: 18 additions & 3 deletions .github/workflows/next-container-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ name: Build and push operator, bundle, and catalog images
on:
push:
branches:
- main
- rhdh-1.[0-9]+
- 1.[0-9]+.x
- main
- rhdh-1.[0-9]+
- 1.[0-9]+.x

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand All @@ -30,9 +30,24 @@ env:
REGISTRY: quay.io

jobs:
check-changes:
# check if the change for this PR necessitates a rebuild of containers
runs-on: ubuntu-latest
steps:
- name: check-changes
# check changes in this commit for regex include and exclude matches; pipe to an env var
run: |
CHANGES="$(git diff --name-only | \
grep -E "/docker/|\.dockerignore|workflows/.+-container-build.yaml|Makefile|/bundle/|/config/|go.mod|go.sum|.+\.go" | \
grep -v -E ".+_test.go|/.rhdh/")" \
>> $GITHUB_ENV
next-build:
name: Next build
runs-on: ubuntu-latest
needs: check-changes
# run this stage only if there are changes that match the includes and not the excludes
if: ${{ env.CHANGES != '' }}
permissions:
contents: read
packages: write
Expand Down
31 changes: 27 additions & 4 deletions .github/workflows/pr-container-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ on:
pull_request_target:
types: [opened, synchronize, reopened, ready_for_review]
branches:
- main
- rhdh-1.[0-9]+
- 1.[0-9]+.x
- main
- rhdh-1.[0-9]+
- 1.[0-9]+.x

concurrency:
group: ${{ github.workflow }}-${{ github.event.number || github.event.pull_request.head.ref }}
Expand All @@ -48,10 +48,23 @@ jobs:
run: |
echo "✓"
check-changes:
# check if the change for this PR necessitates a rebuild of containers
runs-on: ubuntu-latest
needs: authorize
steps:
- name: check-changes
# check changes in this commit for regex include and exclude matches; pipe to an env var
run: |
CHANGES="$(git diff --name-only | \
grep -E "/docker/|\.dockerignore|workflows/.+-container-build.yaml|Makefile|/bundle/|/config/|go.mod|go.sum|.+\.go" | \
grep -v -E ".+_test.go|/.rhdh/")" \
>> $GITHUB_ENV
pr-build:
name: PR Publish
runs-on: ubuntu-latest
needs: authorize
needs: [authorize, check-changes]
permissions:
contents: read
packages: write
Expand All @@ -66,25 +79,33 @@ jobs:
repository: ${{ github.event.pull_request.head.repo.full_name }}

- name: Setup Go
# run this stage only if there are changes that match the includes and not the excludes
if: ${{ env.CHANGES != '' }}
uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'

- name: Get the last commit short SHA of the PR
# run this stage only if there are changes that match the includes and not the excludes
if: ${{ env.CHANGES != '' }}
run: |
SHORT_SHA=$(git rev-parse --short ${{ github.event.pull_request.head.sha }})
echo "SHORT_SHA=$SHORT_SHA" >> $GITHUB_ENV
BASE_VERSION=$(grep -E "^VERSION \?=" Makefile | sed -r -e "s/.+= //") # 0.0.1
echo "BASE_VERSION=$BASE_VERSION" >> $GITHUB_ENV
- name: Login to quay.io
# run this stage only if there are changes that match the includes and not the excludes
if: ${{ env.CHANGES != '' }}
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ vars.QUAY_USERNAME }}
password: ${{ secrets.QUAY_TOKEN }}

- name: Build and push operator, bundle, and catalog images
# run this stage only if there are changes that match the includes and not the excludes
if: ${{ env.CHANGES != '' }}
run: |
# install skopeo, podman
sudo apt-get -y update; sudo apt-get -y install skopeo podman
Expand All @@ -104,6 +125,8 @@ jobs:
skopeo --insecure-policy copy --all docker://quay.io/janus-idp/${image}:${VERSION} docker://quay.io/janus-idp/${image}:${VERSION%-*}
done
- name: Comment image links in PR
# run this stage only if there are changes that match the includes and not the excludes
if: ${{ env.CHANGES != '' }}
uses: actions/github-script@v6
with:
script: |
Expand Down

0 comments on commit 46e6c31

Please sign in to comment.