From 18672691da843ccdac56a3c06171a92f53a85059 Mon Sep 17 00:00:00 2001 From: jose-fully-ported <141160579+jose-fully-ported@users.noreply.github.com> Date: Wed, 27 Sep 2023 14:43:06 -0400 Subject: [PATCH] feat: use shared cache in tests and always run all tests (#3660) --- .github/workflows/pr_push_checks_go.yaml | 91 +++++++++++++++++-- .github/workflows/pr_push_checks_go_lint.yaml | 41 --------- .github/workflows/pr_push_checks_node.yaml | 24 ++++- 3 files changed, 100 insertions(+), 56 deletions(-) delete mode 100644 .github/workflows/pr_push_checks_go_lint.yaml diff --git a/.github/workflows/pr_push_checks_go.yaml b/.github/workflows/pr_push_checks_go.yaml index eeba4fee29..8f23b22bbb 100644 --- a/.github/workflows/pr_push_checks_go.yaml +++ b/.github/workflows/pr_push_checks_go.yaml @@ -1,40 +1,111 @@ name: Go PR Checks on: - pull_request: - paths: - - '**.go' - - '**.mod' - - '**.sum' - - '.github/workflows/pr_push_checks_go.yaml' + - pull_request concurrency: group: pr-go-${{ github.event.pull_request.number || github.ref }} cancel-in-progress: true jobs: + cache: + name: Setup cache + runs-on: ubuntu-latest + outputs: + go-changes: ${{ steps.changed-files.outputs.test_any_changed }} + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Get changed go files + id: changed-files + uses: tj-actions/changed-files@v35 + with: + files: | + *.go + *.mod + *.sum + **/*.go + **/*.mod + **/*.sum + - name: List all changed files + run: | + for file in ${{ steps.changed-files.outputs.all_changed_files }}; do + echo "$file was changed" + done + - name: Setup Go Cache + uses: actions/cache@v3 + if: steps.changed-files.outputs.test_any_changed == 'true' + with: + path: | + ~/.cache/go-build + ~/go/pkg/mod + key: porter-go-${{ hashFiles('**/go.sum') }} + restore-keys: porter-go- + - uses: actions/setup-go@v4 + if: steps.changed-files.outputs.test_any_changed == 'true' + with: + cache: false + go-version-file: go.mod + - name: Download Go Modules + if: steps.changed-files.outputs.test_any_changed == 'true' + run: go mod download + testing_matrix: + name: Running Go Tests + runs-on: ${{ matrix.os }} + needs: cache strategy: matrix: os: [ubuntu-latest] folder: [cli, api, cmd, internal, provisioner] - name: Running Go Tests - runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v3 - name: Setup Go Cache - uses: actions/cache@v3 + uses: actions/cache/restore@v3 + if: needs.cache.outputs.go-changes == 'true' with: path: | ~/.cache/go-build ~/go/pkg/mod key: porter-go-${{ hashFiles('**/go.sum') }} - uses: actions/setup-go@v4 + if: needs.cache.outputs.go-changes == 'true' with: cache: false - go-version: '1.20.5' go-version-file: go.mod - name: Download Go Modules + if: needs.cache.outputs.go-changes == 'true' run: go mod download - name: Run Go tests + if: needs.cache.outputs.go-changes == 'true' run: go test ./${{ matrix.folder }}/... + + linting: + name: Go Linter + runs-on: ubuntu-latest + needs: cache + steps: + - uses: actions/checkout@v3 + - name: Setup Go Cache + uses: actions/cache/restore@v3 + if: needs.cache.outputs.go-changes == 'true' + with: + path: | + ~/.cache/go-build + ~/go/pkg/mod + key: porter-go-${{ hashFiles('**/go.sum') }} + - uses: actions/setup-go@v4 + if: needs.cache.outputs.go-changes == 'true' + with: + cache: false + go-version-file: go.mod + - name: golangci-lint + uses: golangci/golangci-lint-action@v3 + if: needs.cache.outputs.go-changes == 'true' + with: + version: latest + args: -c .github/golangci-lint.yaml --verbose + skip-pkg-cache: true + only-new-issues: true # this is needed until the following is merged: https://github.com/golangci/golangci-lint-action/issues/820 diff --git a/.github/workflows/pr_push_checks_go_lint.yaml b/.github/workflows/pr_push_checks_go_lint.yaml deleted file mode 100644 index ad10f1d8a1..0000000000 --- a/.github/workflows/pr_push_checks_go_lint.yaml +++ /dev/null @@ -1,41 +0,0 @@ -name: Go Lint PR Checks - -on: - pull_request: - paths: - - '**.go' - - '**.mod' - - '**.sum' - - '.github/golangci-lint.yaml' - - '.github/workflows/pr_push_checks_go_lint.yaml' - -concurrency: - group: pr-go-lint-${{ github.event.pull_request.number || github.ref }} - cancel-in-progress: true - -jobs: - linting: - name: Go Linter - runs-on: ubuntu-latest - steps: - - uses: actions/setup-go@v4 - with: - cache: false - go-version: '1.20.5' - go-version-file: go.mod - - uses: actions/checkout@v3 - - name: Setup Go Cache - uses: actions/cache@v3 - with: - path: | - ~/.cache/go-build - ~/go/pkg/mod - key: porter-go-${{ hashFiles('**/go.sum') }} - restore-keys: porter-go-` - - name: golangci-lint - uses: golangci/golangci-lint-action@v3 - with: - version: latest - args: -c .github/golangci-lint.yaml --verbose - skip-pkg-cache: true - only-new-issues: true # this is needed until the following is merged: https://github.com/golangci/golangci-lint-action/issues/820 diff --git a/.github/workflows/pr_push_checks_node.yaml b/.github/workflows/pr_push_checks_node.yaml index c04e1d5cbe..4877bc272f 100644 --- a/.github/workflows/pr_push_checks_node.yaml +++ b/.github/workflows/pr_push_checks_node.yaml @@ -1,10 +1,7 @@ name: Node PR Checks on: - pull_request: - paths: - - 'dashboard/*' - - '.github/workflows/pr_push_checks_node.yaml' + - pull_request concurrency: group: pr-node-${{ github.event.pull_request.number || github.ref }} @@ -16,12 +13,27 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Get changed dashboard files + id: changed-files + uses: tj-actions/changed-files@v35 + with: + files: | + dashboard/** + - name: List all changed files + run: | + for file in ${{ steps.changed-files.outputs.all_changed_files }}; do + echo "$file was changed" + done - name: Setup Node uses: actions/setup-node@v3 + if: steps.changed-files.outputs.test_any_changed == 'true' with: node-version: 16 - name: Setup NPM + if: steps.changed-files.outputs.test_any_changed == 'true' working-directory: dashboard run: | # installing updated npm @@ -38,10 +50,12 @@ jobs: npm --version 2>&1 1>/dev/null echo "npm $(npm --version) installed" - name: Install NPM Dependencies + if: steps.changed-files.outputs.test_any_changed == 'true' working-directory: dashboard run: | npm i --legacy-peer-deps - name: Run NPM Build + if: steps.changed-files.outputs.test_any_changed == 'true' working-directory: dashboard run: | npm run build