From 886dd96299f3548bcccb546f8fdfa59be7e9fbca Mon Sep 17 00:00:00 2001 From: Dylan Page Date: Sun, 5 Nov 2023 21:41:32 -0500 Subject: [PATCH] refactor(ci): reduce complexity in required workflows (#3925) * refactor(ci): builds upon work in tests to reduce complexity in requiring workflows * fix: tweaks and missing outputs * fix: make sure the new workflows actually run * fix: consistency with non-required testing image --- .github/workflows/atlantis-image-required.yml | 26 ---------- .github/workflows/atlantis-image.yml | 42 +++++++++++++--- .github/workflows/codeql-required.yml | 40 --------------- .github/workflows/codeql.yml | 47 +++++++++++++----- .github/workflows/lint-required.yml | 32 ------------ .github/workflows/lint.yml | 36 +++++++++++--- .github/workflows/pr-lint.yml | 2 +- .github/workflows/stale.yml | 2 +- .github/workflows/test.yml | 10 ++-- .github/workflows/testing-env-image.yml | 38 +++++++++++--- .github/workflows/website-required.yml | 38 -------------- .github/workflows/website.yml | 49 +++++++++++++------ 12 files changed, 174 insertions(+), 188 deletions(-) delete mode 100644 .github/workflows/atlantis-image-required.yml delete mode 100644 .github/workflows/codeql-required.yml delete mode 100644 .github/workflows/lint-required.yml delete mode 100644 .github/workflows/website-required.yml diff --git a/.github/workflows/atlantis-image-required.yml b/.github/workflows/atlantis-image-required.yml deleted file mode 100644 index 28a47bc4c..000000000 --- a/.github/workflows/atlantis-image-required.yml +++ /dev/null @@ -1,26 +0,0 @@ -# For required checks when path filtering doesn't trigger the other job -# https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/defining-the-mergeability-of-pull-requests/troubleshooting-required-status-checks#handling-skipped-but-required-checks - -name: atlantis-image - -on: - pull_request: - paths-ignore: - - 'Dockerfile' - - 'docker-entrypoint.sh' - - '.github/workflows/atlantis-image.yml' - - '**.go' - - 'go.*' - -concurrency: - group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} - cancel-in-progress: true - -jobs: - build: - strategy: - matrix: - image_type: [alpine, debian] - runs-on: ubuntu-latest - steps: - - run: 'echo "No build required"' diff --git a/.github/workflows/atlantis-image.yml b/.github/workflows/atlantis-image.yml index 02829ed31..beb9a7b41 100644 --- a/.github/workflows/atlantis-image.yml +++ b/.github/workflows/atlantis-image.yml @@ -4,16 +4,14 @@ on: push: branches: - 'main' + - 'releases-**' tags: - v*.*.* # stable release like, v0.19.2 - v*.*.*-pre.* # pre release like, v0.19.0-pre.calendardate pull_request: - paths: - - 'Dockerfile' - - 'docker-entrypoint.sh' - - '.github/workflows/atlantis-image.yml' - - '**.go' - - 'go.*' + branches: + - 'main' + - 'releases-**' workflow_dispatch: concurrency: @@ -21,7 +19,28 @@ concurrency: cancel-in-progress: true jobs: + changes: + outputs: + should-run-build: ${{ steps.changes.outputs.src == 'true' }} + if: github.event.pull_request.draft == false + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v4 + - uses: dorny/paths-filter@v2 + id: changes + with: + filters: | + src: + - 'Dockerfile' + - 'docker-entrypoint.sh' + - '.github/workflows/atlantis-image.yml' + - '**.go' + - 'go.*' + build: + needs: [changes] + if: needs.changes.outputs.should-run-build == 'true' + name: Build Image strategy: matrix: image_type: [alpine, debian] @@ -123,3 +142,14 @@ jobs: target: ${{ matrix.image_type }} labels: ${{ steps.meta.outputs.labels }} outputs: type=image,name=target,annotation-index.org.opencontainers.image.description=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.description'] }} + + skip-build: + needs: [changes] + if: needs.changes.outputs.should-run-build == 'false' + name: Build Image + strategy: + matrix: + image_type: [alpine, debian] + runs-on: ubuntu-22.04 + steps: + - run: 'echo "No build required"' \ No newline at end of file diff --git a/.github/workflows/codeql-required.yml b/.github/workflows/codeql-required.yml deleted file mode 100644 index 05736bb69..000000000 --- a/.github/workflows/codeql-required.yml +++ /dev/null @@ -1,40 +0,0 @@ -# For required checks when path filtering doesn;'t trigger the other job -# https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/defining-the-mergeability-of-pull-requests/troubleshooting-required-status-checks#handling-skipped-but-required-checks - -name: "CodeQL" - -on: - push: - branches: [ "main" ] - paths-ignore: - - '**.go' - - '**.js' - pull_request: - # The branches below must be a subset of the branches above - types: - - opened - - reopened - - synchronize - - ready_for_review - branches: [ "main" ] - paths-ignore: - - '**.go' - - '**.js' - -jobs: - analyze: - name: Analyze - if: github.event.pull_request.draft == false - runs-on: ubuntu-latest - permissions: - actions: read - contents: read - security-events: write - - strategy: - fail-fast: false - matrix: - language: [ 'go', 'javascript' ] - - steps: - - run: 'echo "No build required"' diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 57eb36244..5903b805d 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -13,10 +13,9 @@ name: "CodeQL" on: push: - branches: [ "main" ] - paths: - - '**.go' - - '**.js' + branches: + - 'main' + - 'releases-**' pull_request: # The branches below must be a subset of the branches above types: @@ -24,19 +23,34 @@ on: - reopened - synchronize - ready_for_review - branches: [ "main" ] - paths: - - '**.go' - - '**.js' + branches: + - 'main' + - 'releases-**' schedule: - cron: '17 9 * * 5' jobs: - analyze: - name: Analyze + changes: + outputs: + should-run-analyze: ${{ steps.changes.outputs.src == 'true' }} if: github.event.pull_request.draft == false - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v4 + - uses: dorny/paths-filter@v2 + id: changes + with: + filters: | + src: + - '**.go' + - '**.js4' + + analyze: + needs: [changes] + name: Analyze + if: github.event.pull_request.draft == false && needs.changes.outputs.should-run-analyze == 'true' + runs-on: ubuntu-22.04 permissions: actions: read contents: read @@ -87,3 +101,14 @@ jobs: uses: github/codeql-action/analyze@v2 with: category: "/language:${{matrix.language}}" + + skip-analyze: + needs: [changes] + if: needs.changes.outputs.should-run-analyze == 'false' + name: Analyze + strategy: + matrix: + language: [ 'go', 'javascript' ] + runs-on: ubuntu-22.04 + steps: + - run: 'echo "No build required"' diff --git a/.github/workflows/lint-required.yml b/.github/workflows/lint-required.yml deleted file mode 100644 index 6f5451f8d..000000000 --- a/.github/workflows/lint-required.yml +++ /dev/null @@ -1,32 +0,0 @@ -# For required checks when path filtering doesn;'t trigger the other job -# https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/defining-the-mergeability-of-pull-requests/troubleshooting-required-status-checks#handling-skipped-but-required-checks - -name: linter - -on: - pull_request: - types: - - opened - - reopened - - synchronize - - ready_for_review - branches: - - "main" - paths-ignore: - - '**.go' - - 'go.*' - - '.github/workflows/lint.yml' - - '.github/workflows/lint-required.yml' - - '.golangci.yml' - -concurrency: - group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} - cancel-in-progress: true - -jobs: - golangci-lint: - if: github.event.pull_request.draft == false - name: runner / golangci-lint - runs-on: ubuntu-22.04 - steps: - - run: 'echo "No build required"' diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 2b39dec60..805586e53 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -9,20 +9,34 @@ on: - ready_for_review branches: - "main" - paths: - - '**.go' - - 'go.*' - - '.github/workflows/lint.yml' - - '.golangci.yml' + - 'releases-**' concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} cancel-in-progress: true jobs: - golangci-lint: + changes: + outputs: + should-run-linting: ${{ steps.changes.outputs.go == 'true' }} if: github.event.pull_request.draft == false - name: runner / golangci-lint + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v4 + - uses: dorny/paths-filter@v2 + id: changes + with: + filters: | + go: + - '**.go' + - 'go.*' + - '.github/workflows/lint.yml' + - '.golangci.yml' + + golangci-lint: + needs: [changes] + if: github.event.pull_request.draft == false && needs.changes.outputs.should-run-linting == 'true' + name: Linting runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v4 @@ -30,3 +44,11 @@ jobs: uses: reviewdog/action-golangci-lint@v2 with: tool_name: golangci-lint + + skip-lint: + needs: [changes] + if: needs.changes.outputs.should-run-linting == 'false' + name: Linting + runs-on: ubuntu-22.04 + steps: + - run: 'echo "No build required"' diff --git a/.github/workflows/pr-lint.yml b/.github/workflows/pr-lint.yml index d54e17496..e3a5b647a 100644 --- a/.github/workflows/pr-lint.yml +++ b/.github/workflows/pr-lint.yml @@ -13,7 +13,7 @@ permissions: jobs: main: name: Validate PR title - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 steps: - uses: amannn/action-semantic-pull-request@v5 env: diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index 979b3428e..e2ff5c463 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -4,7 +4,7 @@ on: - cron: '30 1 * * *' jobs: stale: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 steps: - uses: actions/stale@v8 with: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a5e3cdc13..120dcee82 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -3,7 +3,8 @@ name: tester on: push: branches: - - "main" + - 'main' + - 'releases-**' pull_request: types: - opened @@ -11,7 +12,8 @@ on: - synchronize - ready_for_review branches: - - "main" + - 'main' + - 'releases-**' concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} @@ -36,7 +38,7 @@ jobs: test: needs: [changes] if: needs.changes.outputs.should-run-tests == 'true' - name: runner / gotest + name: Tests runs-on: ubuntu-22.04 container: ghcr.io/runatlantis/testing-env:latest steps: @@ -86,7 +88,7 @@ jobs: skip-test: needs: [changes] if: needs.changes.outputs.should-run-tests == 'false' - name: runner / gotest + name: Tests runs-on: ubuntu-22.04 steps: - run: 'echo "No build required"' diff --git a/.github/workflows/testing-env-image.yml b/.github/workflows/testing-env-image.yml index 4c37a4587..9658c7287 100644 --- a/.github/workflows/testing-env-image.yml +++ b/.github/workflows/testing-env-image.yml @@ -2,15 +2,13 @@ name: testing-env-image on: push: - paths: - - "testing/**" - - ".github/workflows/testing-env-image.yml" branches: - - "main" + - 'main' + - 'release-**' pull_request: - paths: - - 'testing/**' - - '.github/workflows/testing-env-image.yml' + branches: + - 'main' + - 'release-**' workflow_dispatch: concurrency: @@ -18,7 +16,25 @@ concurrency: cancel-in-progress: true jobs: + changes: + outputs: + should-run-build: ${{ steps.changes.outputs.src == 'true' }} + if: github.event.pull_request.draft == false + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v4 + - uses: dorny/paths-filter@v2 + id: changes + with: + filters: | + src: + - 'testing/**' + - '.github/workflows/testing-env-image.yml' + build: + needs: [changes] + if: needs.changes.outputs.should-run-build == 'true' + name: Build Testing Env Image runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v4 @@ -51,3 +67,11 @@ jobs: tags: | ghcr.io/runatlantis/testing-env:${{env.TODAY}} ghcr.io/runatlantis/testing-env:latest + + skip-build: + needs: [changes] + if: needs.changes.outputs.should-run-build == 'false' + name: Build Testing Env Image + runs-on: ubuntu-22.04 + steps: + - run: 'echo "No build required"' \ No newline at end of file diff --git a/.github/workflows/website-required.yml b/.github/workflows/website-required.yml deleted file mode 100644 index de35d5c06..000000000 --- a/.github/workflows/website-required.yml +++ /dev/null @@ -1,38 +0,0 @@ -name: website - -on: - push: - branches: - - "main" - paths-ignore: - - '**.js' - - 'yarn.lock' - - 'package.json' - - '.github/workflows/website.yml' - pull_request: - types: - - opened - - reopened - - synchronize - - ready_for_review - branches: - - "main" - paths-ignore: - - '**.js' - - 'yarn.lock' - - 'package.json' - - '.github/workflows/website.yml' - -concurrency: - group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} - cancel-in-progress: true - -jobs: - # Check that there's no missing links for the website. - # This job builds the website, starts a server to serve it, and then uses - # muffet (https://github.com/raviqqe/muffet) to perform the link check. - link_check: - if: github.event.pull_request.draft == false - runs-on: ubuntu-22.04 - steps: - - run: 'echo "No testing required"' diff --git a/.github/workflows/website.yml b/.github/workflows/website.yml index 6db5acdf5..7f8c11033 100644 --- a/.github/workflows/website.yml +++ b/.github/workflows/website.yml @@ -3,12 +3,8 @@ name: website on: push: branches: - - "main" - paths: - - '**.js' - - 'yarn.lock' - - 'package.json' - - '.github/workflows/website.yml' + - 'main' + - 'release-**' pull_request: types: - opened @@ -16,24 +12,39 @@ on: - synchronize - ready_for_review branches: - - "main" - paths: - - '**.js' - - 'yarn.lock' - - 'package.json' - - '.github/workflows/website.yml' + - 'main' + - 'release-**' concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} cancel-in-progress: true jobs: + changes: + outputs: + should-run-link-check: ${{ steps.changes.outputs.src == 'true' }} + if: github.event.pull_request.draft == false + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v4 + - uses: dorny/paths-filter@v2 + id: changes + with: + filters: | + src: + - '**.js' + - 'yarn.lock' + - 'package.json' + - '.github/workflows/website.yml' + # Check that the website builds and there's no missing links. # This job builds the website, starts a server to serve it, and then uses # muffet (https://github.com/raviqqe/muffet) to perform the link check. - link_check: - if: github.event.pull_request.draft == false - runs-on: ubuntu-22.04 + link-check: + needs: [changes] + if: github.event.pull_request.draft == false && needs.changes.outputs.should-run-link-check == 'true' + name: Website Link Check + runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -68,3 +79,11 @@ jobs: --header 'Accept-Encoding:deflate, gzip' \ --buffer-size 8192 \ http://localhost:8080/ + + skip-link-check: + needs: [changes] + if: needs.changes.outputs.should-run-link-check == 'false' + name: Website Link Check + runs-on: ubuntu-latest + steps: + - run: 'echo "No build required"' \ No newline at end of file