From c14e827cc53ee63ee59d255c4ad9180088ed5676 Mon Sep 17 00:00:00 2001 From: Arkadii Yakovets <2201626+arkid15r@users.noreply.github.com> Date: Fri, 5 Jul 2024 05:58:54 -0700 Subject: [PATCH] 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 --- .github/workflows/build.yml | 54 ++++++++++++++++++++++++++++ .github/workflows/main.yml | 71 ++++++++++++------------------------- 2 files changed, 76 insertions(+), 49 deletions(-) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 000000000..0e50adfd4 --- /dev/null +++ b/.github/workflows/build.yml @@ -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 diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d074dd6f0..48039ed36 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,29 +1,25 @@ name: main + on: push: branches: - - master - cluster - paths-ignore: - - "docs/**" - - "**.md" - - "dashboards/**" - - "deployment/**.yml" + - master + paths: + - '**.go' pull_request: branches: - - master - cluster - paths-ignore: - - "docs/**" - - "**.md" - - "dashboards/**" - - "deployment/**.yml" + - master + paths: + - '**.go' + permissions: contents: read concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} cancel-in-progress: true + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} jobs: lint: @@ -37,16 +33,16 @@ jobs: id: go uses: actions/setup-go@v5 with: - go-version: stable cache: false + go-version: stable - name: Cache Go artifacts uses: actions/cache@v4 with: path: | ~/.cache/go-build - ~/go/pkg/mod ~/go/bin + ~/go/pkg/mod 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- @@ -55,41 +51,18 @@ jobs: make check-all 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: + name: test needs: lint + runs-on: ubuntu-latest + strategy: matrix: - scenario: ["test-full", "test-pure", "test-full-386"] - name: test - runs-on: ubuntu-latest + scenario: + - 'test-full' + - 'test-full-386' + - 'test-pure' + steps: - name: Code checkout uses: actions/checkout@v4 @@ -98,20 +71,20 @@ jobs: id: go uses: actions/setup-go@v5 with: - go-version: stable cache: false + go-version: stable - name: Cache Go artifacts uses: actions/cache@v4 with: path: | ~/.cache/go-build - ~/go/pkg/mod ~/go/bin + ~/go/pkg/mod 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 }}- - - name: run tests + - name: Run tests run: make ${{ matrix.scenario}} - name: Publish coverage