Skip to content
Open
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
42 changes: 39 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name: ci

on:
- pull_request
on: [pull_request]

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull-request.number || github.ref }}
Expand All @@ -16,9 +15,40 @@ permissions:
checks: write # Used to annotate code in the PR

jobs:
changes:
name: categorize changes
runs-on: ubuntu-latest
outputs:
non-docs: ${{ steps.detect.outputs.non-docs }}
yaml: ${{ steps.detect.outputs.yaml }}
steps:
- name: Get base depth
id: base-depth
run: echo "base-depth=$(expr ${{ github.event.pull_request.commits }} + 1)" >> $GITHUB_OUTPUT
Comment on lines +25 to +27
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could clone the full repository here, but that could take some time and is probably not necessary. This should help the pre-check go much quicker

- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: ${{ steps.base-depth.outputs.base-depth }}
- name: detect
id: detect
run: |
git fetch origin ${{ github.base_ref }}
CHANGED_FILES=$(git diff --name-only ${{ github.event.pull_request.base.sha }}...${{ github.event.pull_request.head.sha }} | tr ' ' '\n')

echo -e "Changed files:\n${CHANGED_FILES}"

# If no files are changed at all, then `grep -v` will match even though no change outputs
# should be true. Skipping output on an empty set of changes eliminates the false positive
if [[ -n "${CHANGED_FILES}" ]]; then
echo "non-docs=$(echo \"${CHANGED_FILES}\" | grep -qv '**\.md' && echo 'true' )" | tee -a $GITHUB_OUTPUT
echo "yaml=$(echo \"${CHANGED_FILES}\" | grep -q '**\.ya\?ml' && echo 'true' )" | tee -a $GITHUB_OUTPUT
fi

build:
name: build
runs-on: ubuntu-latest
needs: [changes]
if: ${{ needs.changes.outputs.non-docs == 'true' }}
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
- uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0
Expand All @@ -30,6 +60,8 @@ jobs:
buildFips:
name: buildFips
runs-on: ubuntu-latest
needs: [changes]
if: ${{ needs.changes.outputs.non-docs == 'true' }}
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
- uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0
Expand All @@ -40,15 +72,16 @@ jobs:
go build -v -tags "disable_spire,disable_tls" ./cmd/entrypoint
echo "Build finished with exit code: $?"
linting:
needs: [build]
name: lint
runs-on: ubuntu-latest
needs: [changes]
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
- uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0
with:
go-version-file: "go.mod"
- name: gofmt
if: ${{ needs.changes.outputs.non-docs == 'true' }}
run: |
gofmt_out=$(gofmt -d $(find * -name '*.go' ! -path 'vendor/*' ! -path 'third_party/*'))
if [[ -n "$gofmt_out" ]]; then
Expand All @@ -57,15 +90,18 @@ jobs:
echo "$gofmt_out"
- name: golangci-lint
uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0
if: ${{ needs.changes.outputs.non-docs == 'true' }}
with:
version: v2.1.6
only-new-issues: true
args: --timeout=10m
- name: yamllint
if: ${{ needs.changes.outputs.yaml == 'true' }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine, however I'm mostly concerned with E2E test. We should skip them if they're not relevant as they take a lot of runners and time. Everything else is small/quick enough that I would not bother touching it at the risk of over-optimising.

run: |
apt-get update && apt-get install -y yamllint
make yamllint
- name: check-license
if: ${{ needs.changes.outputs.non-docs == 'true' }}
run: |
go install github.com/google/[email protected]
go-licenses check ./...
Expand Down
Loading