Repository: vmware/govmomi
Pull request #2829 (2022-04-26 09:47:26)

chore: Optimize Go CI workflows
## Description

- [x] Caching per `go` version
- [x] Cancel long-running workflows, e.g. `build` when concurrent jobs are queued (only for PRs)
- [x] Do not fail on matrix tests

Closes: #2828
Signed-off-by: Michael Gasch <mgasch@vmware.com>

## Type of change

Please mark options that are relevant:

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to
  not work as expected)
- [ ] This change requires a documentation update
- [x] Build related change

## How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide
instructions so we can reproduce. If applicable, please also list any relevant
details for your test configuration.

- [x] CI passes and PR synchronization (pushes) cancel build/govc tests workflows

## Checklist:

- [ ] My code follows the CONTRIBUTION [guidelines](./../CONTRIBUTING.md) of
  this project
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [ ] I have added tests that prove my fix is effective or that my feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged


Patch:
diff --git a/.github/workflows/govmomi-build.yaml b/.github/workflows/govmomi-build.yaml
index b021852a..e6f00fad 100644
--- a/.github/workflows/govmomi-build.yaml
+++ b/.github/workflows/govmomi-build.yaml
@@ -27,6 +27,10 @@ on:
   
   workflow_dispatch:
 
+concurrency:
+  group: govmomi-build-${{ github.head_ref || github.run_id }}
+  cancel-in-progress: true
+
 jobs:
   artifacts:
     name: Build Snapshot Release (no upload)
@@ -50,9 +54,9 @@ jobs:
           path: |
             ~/.cache/go-build
             ~/go/pkg/mod
-          key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
+          key: ${{ runner.os }}-go-1.18-${{ hashFiles('**/go.sum') }}
           restore-keys: |
-            ${{ runner.os }}-go-
+            ${{ runner.os }}-go-1.18-
 
       - name: Create CHANGELOG
         env:


Test patch:
diff --git a/.github/workflows/govmomi-go-tests.yaml b/.github/workflows/govmomi-go-tests.yaml
index 1cc36926..52de2cbb 100644
--- a/.github/workflows/govmomi-go-tests.yaml
+++ b/.github/workflows/govmomi-go-tests.yaml
@@ -28,6 +28,7 @@ jobs:
       matrix:
         go-version: ["1.17", "1.18"]
         platform: ["ubuntu-20.04"]
+      fail-fast: false
 
     runs-on: ${{ matrix.platform }}
     timeout-minutes: 10
@@ -48,9 +49,9 @@ jobs:
           path: |
             ~/.cache/go-build
             ~/go/pkg/mod
-          key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
+          key: ${{ runner.os }}-go-${{ matrix.go-version }}-${{ hashFiles('**/go.sum') }}
           restore-keys: |
-            ${{ runner.os }}-go-
+            ${{ runner.os }}-go-${{ matrix.go-version }}-
 
       - name: Run Tests
         env:
diff --git a/.github/workflows/govmomi-govc-tests.yaml b/.github/workflows/govmomi-govc-tests.yaml
index bdc80a95..7bbc856d 100644
--- a/.github/workflows/govmomi-govc-tests.yaml
+++ b/.github/workflows/govmomi-govc-tests.yaml
@@ -21,16 +21,21 @@ on:
   pull_request:
     branches: ["main", "master"]
 
+concurrency:
+  group: govmomi-govc-tests-${{ github.head_ref || github.run_id }}
+  cancel-in-progress: true
+
 jobs:
   govc-tests:
     name: Run govc Tests
     strategy:
+      fail-fast: false
       matrix:
         go-version: ["1.17", "1.18"]
         platform: ["ubuntu-20.04"]
         cmd: ["govc-test"]
         experimental: [false]
-        timeout: [10]
+        timeout: [20]
         include:
           - go-version: "1.18"
             platform: "ubuntu-20.04"
@@ -63,9 +68,9 @@ jobs:
           path: |
             ~/.cache/go-build
             ~/go/pkg/mod
-          key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
+          key: ${{ runner.os }}-go-${{ matrix.go-version }}-${{ hashFiles('**/go.sum') }}
           restore-keys: |
-            ${{ runner.os }}-go-
+            ${{ runner.os }}-go-${{ matrix.go-version }}-
 
       - name: Run ${{ matrix.cmd }}
         run: |
@@ -97,9 +102,9 @@ jobs:
           path: |
             ~/.cache/go-build
             ~/go/pkg/mod
-          key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
+          key: ${{ runner.os }}-go-${{ matrix.go-version }}-${{ hashFiles('**/go.sum') }}
           restore-keys: |
-            ${{ runner.os }}-go-
+            ${{ runner.os }}-go-${{ matrix.go-version }}-
 
       - name: Run "make doc"
         run: |