diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 2355e1bd0e4..f551058dffe 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,7 +1,6 @@ name: ci -on: - - pull_request +on: [pull_request] concurrency: group: ${{ github.workflow }}-${{ github.event.pull-request.number || github.ref }} @@ -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 + - 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 @@ -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 @@ -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 @@ -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' }} 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/go-licenses@v1.0.0 go-licenses check ./...