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

Commit

Permalink
chore: skip the golang build if there's no... (#168)
Browse files Browse the repository at this point in the history
* chore: skip the golang build if there's no changes to the golang files (see regex)

Signed-off-by: Nick Boldt <nboldt@redhat.com>

* don't fail if nothing returned by grep

Signed-off-by: Nick Boldt <nboldt@redhat.com>

---------

Signed-off-by: Nick Boldt <nboldt@redhat.com>
  • Loading branch information
nickboldt committed Jan 29, 2024
1 parent fb48a1f commit b549775
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 16 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/next-container-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ jobs:
- name: check-changes
# check changes in this commit for regex include and exclude matches; pipe to an env var
run: |
# don't fail if nothing returned by grep
set +e
CHANGES="$(git diff --name-only HEAD~1 | \
grep -E "docker/|\.dockerignore|workflows/.+-container-build.yaml|Makefile|bundle/|config/|go.mod|go.sum|.+\.go" | \
grep -v -E ".+_test.go|/.rhdh/")";
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/pr-container-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ jobs:
- name: check-changes
# check changes in this commit for regex include and exclude matches; pipe to an env var
run: |
# don't fail if nothing returned by grep
set +e
CHANGES="$(git diff --name-only HEAD~1 | \
grep -E "docker/|\.dockerignore|workflows/.+-container-build.yaml|Makefile|bundle/|config/|go.mod|go.sum|.+\.go" | \
grep -v -E ".+_test.go|/.rhdh/")";
Expand Down
66 changes: 50 additions & 16 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,61 @@ on:
- 1.[0-9]+.x

jobs:
check-changes:
# check if the change for this PR necessitates a rebuild of containers
runs-on: ubuntu-latest
needs: authorize
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
- name: check-changes
# check changes in this commit for regex include and exclude matches; pipe to an env var
# note regexes are different for the PR check than for *-container-build.yaml
run: |
# don't fail if nothing returned by grep
set +e
CHANGES="$(git diff --name-only | \
grep -E "workflows/pr.yaml|Makefile|bundle/|config/|go.mod|go.sum|.+\.go" | \
grep -v -E "/.rhdh/")";
echo "Changed files for this commit:"
echo "=============================="
echo "$CHANGES"
echo "=============================="
echo "CHANGES=$CHANGES" >> $GITHUB_ENV
pr-validate:
name: PR Validate
runs-on: ubuntu-latest

needs: check-changes
steps:
- uses: actions/checkout@v3
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Go
uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'

- name: Setup Go
uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'
# gosec needs a "build" stage so connect it to the lint step which we always do
- name: build
run: make lint

- name: build
run: |
make lint test
- name: test
# run this stage only if there are changes that match the includes and not the excludes
if: ${{ env.CHANGES != '' }}
run: make test

- name: Run Gosec Security Scanner
run: make gosec
- name: Run Gosec Security Scanner
run: make gosec

- name: Upload SARIF file
uses: github/codeql-action/upload-sarif@v2
with:
# Path to SARIF file relative to the root of the repository
sarif_file: gosec.sarif
- name: Upload SARIF file
uses: github/codeql-action/upload-sarif@v2
with:
# Path to SARIF file relative to the root of the repository
sarif_file: gosec.sarif

0 comments on commit b549775

Please sign in to comment.