From 70b0fc09a026e3bcf11a0d42c03a6444cd1e8d1d Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Wed, 27 Sep 2023 13:37:02 -0400 Subject: [PATCH] feat: use shared cache for go --- .github/workflows/pr_push_checks_go.yaml | 9 +--- .../workflows/pr_push_checks_go_cache.yaml | 51 +++++++++++++++++++ .github/workflows/pr_push_checks_go_lint.yaml | 19 +++---- 3 files changed, 59 insertions(+), 20 deletions(-) create mode 100644 .github/workflows/pr_push_checks_go_cache.yaml diff --git a/.github/workflows/pr_push_checks_go.yaml b/.github/workflows/pr_push_checks_go.yaml index eeba4fee29f..028c4aa3ccc 100644 --- a/.github/workflows/pr_push_checks_go.yaml +++ b/.github/workflows/pr_push_checks_go.yaml @@ -1,12 +1,7 @@ name: Go PR Checks on: - pull_request: - paths: - - '**.go' - - '**.mod' - - '**.sum' - - '.github/workflows/pr_push_checks_go.yaml' + workflow_dispatch: {} concurrency: group: pr-go-${{ github.event.pull_request.number || github.ref }} @@ -29,10 +24,10 @@ jobs: ~/.cache/go-build ~/go/pkg/mod key: porter-go-${{ hashFiles('**/go.sum') }} + restore-keys: porter-go- - uses: actions/setup-go@v4 with: cache: false - go-version: '1.20.5' go-version-file: go.mod - name: Download Go Modules run: go mod download diff --git a/.github/workflows/pr_push_checks_go_cache.yaml b/.github/workflows/pr_push_checks_go_cache.yaml new file mode 100644 index 00000000000..e30b6ed51c5 --- /dev/null +++ b/.github/workflows/pr_push_checks_go_cache.yaml @@ -0,0 +1,51 @@ +name: Go PR Checks + +on: + push: + paths: + - '**.go' + - '**.mod' + - '**.sum' + - '.github/golangci-lint.yaml' + - '.github/workflows/pr_push_checks_go.yaml' + - '.github/workflows/pr_push_checks_go_cache.yaml' + - '.github/workflows/pr_push_checks_go_lint.yaml' + +concurrency: + group: pr-go-cache-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + testing_matrix: + 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 + with: + path: | + ~/.cache/go-build + ~/go/pkg/mod + key: porter-go-${{ hashFiles('**/go.sum') }} + restore-keys: porter-go- + - uses: actions/setup-go@v4 + with: + cache: false + go-version-file: go.mod + - name: Download Go Modules + run: go mod download + - name: Trigger lint workflow + run: | + if [[ -n "$GITHUB_HEAD_REF" ]]; then + branch="$GITHUB_HEAD_REF" + elif [[ -n "$GITHUB_REF_NAME" ]]; then + branch="$GITHUB_REF_NAME" + fi + + gh workflow run pr_push_checks_go_lint.yml -r "$branch" + gh workflow run pr_push_checks_go.yml -r "$branch" diff --git a/.github/workflows/pr_push_checks_go_lint.yaml b/.github/workflows/pr_push_checks_go_lint.yaml index ad10f1d8a13..0fdededf90b 100644 --- a/.github/workflows/pr_push_checks_go_lint.yaml +++ b/.github/workflows/pr_push_checks_go_lint.yaml @@ -1,13 +1,7 @@ name: Go Lint PR Checks on: - pull_request: - paths: - - '**.go' - - '**.mod' - - '**.sum' - - '.github/golangci-lint.yaml' - - '.github/workflows/pr_push_checks_go_lint.yaml' + workflow_dispatch: {} concurrency: group: pr-go-lint-${{ github.event.pull_request.number || github.ref }} @@ -18,11 +12,6 @@ jobs: 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 @@ -31,7 +20,11 @@ jobs: ~/.cache/go-build ~/go/pkg/mod key: porter-go-${{ hashFiles('**/go.sum') }} - restore-keys: porter-go-` + restore-keys: porter-go- + - uses: actions/setup-go@v4 + with: + cache: false + go-version-file: go.mod - name: golangci-lint uses: golangci/golangci-lint-action@v3 with: