Optimize CI workflows (#6551)

### Describe Your Changes

This PR is aimed to change the currently in place configuration of
running Go related jobs for code changes that don't contain actual Go
files ([example
1](https://github.com/VictoriaMetrics/VictoriaMetrics/pull/6517/checks)
- 2m32s , [example
2](https://github.com/VictoriaMetrics/VictoriaMetrics/pull/6543/checks)
- 4m11s).

In order to do that the `build` workflow was extracted from Go related
workflow (now it doesn't require lint as a `need` step -- let me know if
it's something we want to keep). It will run upon the same triggers as
before the change.

The `main` workflow now will be triggered by `**.go` pattern only and
contains lint/test steps that are relevant for Go file changes.

I expect this PR +
https://github.com/VictoriaMetrics/VictoriaMetrics/pull/6540 to improve
CI minutes usage.

### Checklist

The following checks are **mandatory**:

- [x] My change adheres [VictoriaMetrics contributing
guidelines](https://docs.victoriametrics.com/contributing/).

---------

Signed-off-by: Arkadii Yakovets <ark@victoriametrics.com>
This commit is contained in:
Arkadii Yakovets 2024-07-05 05:58:54 -07:00 committed by GitHub
parent d5e4857a27
commit c14e827cc5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 76 additions and 49 deletions

54
.github/workflows/build.yml vendored Normal file
View file

@ -0,0 +1,54 @@
name: build
on:
push:
branches:
- cluster
- master
paths:
- '**.go'
- '**/Dockerfile*' # The trailing * is for app/vmui/Dockerfile-*.
- '**/Makefile'
pull_request:
branches:
- cluster
- master
paths:
- '**.go'
- '**/Dockerfile*' # The trailing * is for app/vmui/Dockerfile-*.
- '**/Makefile'
permissions:
contents: read
concurrency:
cancel-in-progress: true
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Code checkout
uses: actions/checkout@v4
- name: Setup Go
id: go
uses: actions/setup-go@v5
with:
go-version: stable
cache: false
- name: Cache Go artifacts
uses: actions/cache@v4
with:
path: |
~/.cache/go-build
~/go/bin
~/go/pkg/mod
key: go-artifacts-${{ runner.os }}-crossbuild-${{ steps.go.outputs.go-version }}-${{ hashFiles('go.sum', 'Makefile', 'app/**/Makefile') }}
restore-keys: go-artifacts-${{ runner.os }}-crossbuild-
- name: Run crossbuild
run: make crossbuild

View file

@ -1,29 +1,25 @@
name: main name: main
on: on:
push: push:
branches: branches:
- master
- cluster - cluster
paths-ignore: - master
- "docs/**" paths:
- "**.md" - '**.go'
- "dashboards/**"
- "deployment/**.yml"
pull_request: pull_request:
branches: branches:
- master
- cluster - cluster
paths-ignore: - master
- "docs/**" paths:
- "**.md" - '**.go'
- "dashboards/**"
- "deployment/**.yml"
permissions: permissions:
contents: read contents: read
concurrency: concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true cancel-in-progress: true
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
jobs: jobs:
lint: lint:
@ -37,16 +33,16 @@ jobs:
id: go id: go
uses: actions/setup-go@v5 uses: actions/setup-go@v5
with: with:
go-version: stable
cache: false cache: false
go-version: stable
- name: Cache Go artifacts - name: Cache Go artifacts
uses: actions/cache@v4 uses: actions/cache@v4
with: with:
path: | path: |
~/.cache/go-build ~/.cache/go-build
~/go/pkg/mod
~/go/bin ~/go/bin
~/go/pkg/mod
key: go-artifacts-${{ runner.os }}-check-all-${{ steps.go.outputs.go-version }}-${{ hashFiles('go.sum', 'Makefile', 'app/**/Makefile') }} key: go-artifacts-${{ runner.os }}-check-all-${{ steps.go.outputs.go-version }}-${{ hashFiles('go.sum', 'Makefile', 'app/**/Makefile') }}
restore-keys: go-artifacts-${{ runner.os }}-check-all- restore-keys: go-artifacts-${{ runner.os }}-check-all-
@ -55,41 +51,18 @@ jobs:
make check-all make check-all
git diff --exit-code git diff --exit-code
build:
needs: lint
name: build
runs-on: ubuntu-latest
steps:
- name: Code checkout
uses: actions/checkout@v4
- name: Setup Go
id: go
uses: actions/setup-go@v5
with:
go-version: stable
cache: false
- name: Cache Go artifacts
uses: actions/cache@v4
with:
path: |
~/.cache/go-build
~/go/pkg/mod
~/go/bin
key: go-artifacts-${{ runner.os }}-crossbuild-${{ steps.go.outputs.go-version }}-${{ hashFiles('go.sum', 'Makefile', 'app/**/Makefile') }}
restore-keys: go-artifacts-${{ runner.os }}-crossbuild-
- name: Build
run: make crossbuild
test: test:
name: test
needs: lint needs: lint
runs-on: ubuntu-latest
strategy: strategy:
matrix: matrix:
scenario: ["test-full", "test-pure", "test-full-386"] scenario:
name: test - 'test-full'
runs-on: ubuntu-latest - 'test-full-386'
- 'test-pure'
steps: steps:
- name: Code checkout - name: Code checkout
uses: actions/checkout@v4 uses: actions/checkout@v4
@ -98,20 +71,20 @@ jobs:
id: go id: go
uses: actions/setup-go@v5 uses: actions/setup-go@v5
with: with:
go-version: stable
cache: false cache: false
go-version: stable
- name: Cache Go artifacts - name: Cache Go artifacts
uses: actions/cache@v4 uses: actions/cache@v4
with: with:
path: | path: |
~/.cache/go-build ~/.cache/go-build
~/go/pkg/mod
~/go/bin ~/go/bin
~/go/pkg/mod
key: go-artifacts-${{ runner.os }}-${{ matrix.scenario }}-${{ steps.go.outputs.go-version }}-${{ hashFiles('go.sum', 'Makefile', 'app/**/Makefile') }} key: go-artifacts-${{ runner.os }}-${{ matrix.scenario }}-${{ steps.go.outputs.go-version }}-${{ hashFiles('go.sum', 'Makefile', 'app/**/Makefile') }}
restore-keys: go-artifacts-${{ runner.os }}-${{ matrix.scenario }}- restore-keys: go-artifacts-${{ runner.os }}-${{ matrix.scenario }}-
- name: run tests - name: Run tests
run: make ${{ matrix.scenario}} run: make ${{ matrix.scenario}}
- name: Publish coverage - name: Publish coverage