From ff17a961fc45e42bca2bd14419eb928b0c4ed536 Mon Sep 17 00:00:00 2001 From: mmetc <92726601+mmetc@users.noreply.github.com> Date: Tue, 28 Feb 2023 17:25:09 +0100 Subject: [PATCH] CI: Cache all built go modules (#2081) --- .github/workflows/bats-hub.yml | 22 ++++++++-- .github/workflows/bats-mysql.yml | 20 ++++++++- .github/workflows/bats-postgres.yml | 20 ++++++++- .github/workflows/ci-windows-build-msi.yml | 25 ++++++++++- .github/workflows/go-tests-windows.yml | 21 +++++++-- .github/workflows/release_publish-package.yml | 44 +++++++++++++++++-- LICENSE | 2 +- 7 files changed, 137 insertions(+), 17 deletions(-) diff --git a/.github/workflows/bats-hub.yml b/.github/workflows/bats-hub.yml index 36d083a42..bfbd6f054 100644 --- a/.github/workflows/bats-hub.yml +++ b/.github/workflows/bats-hub.yml @@ -13,6 +13,10 @@ env: jobs: build: + strategy: + matrix: + go-version: ["1.20.1"] + name: "Build + tests" runs-on: ubuntu-latest timeout-minutes: 20 @@ -23,18 +27,30 @@ jobs: sudo chmod +w /etc/machine-id echo githubciXXXXXXXXXXXXXXXXXXXXXXXX | sudo tee /etc/machine-id - - name: "Set up Go 1.20" + - name: "Set up Go ${{ matrix.go-version }}" uses: actions/setup-go@v3 with: - go-version: 1.20.1 + go-version: ${{ matrix.go-version }} id: go - - name: "Clone CrowdSec" + - name: "Check out CrowdSec repository" uses: actions/checkout@v3 with: fetch-depth: 0 submodules: true + - name: Cache Go modules + uses: actions/cache@v3 + with: + path: | + ~/go/pkg/mod + ~/.cache/go-build + ~/Library/Caches/go-build + %LocalAppData%\go-build + key: ${{ runner.os }}-${{ matrix.go-version }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-${{ matrix.go-version }}-go- + - name: "Install bats dependencies" env: GOBIN: /usr/local/bin diff --git a/.github/workflows/bats-mysql.yml b/.github/workflows/bats-mysql.yml index bb3c693be..6b785fcdc 100644 --- a/.github/workflows/bats-mysql.yml +++ b/.github/workflows/bats-mysql.yml @@ -12,6 +12,10 @@ env: jobs: build: + strategy: + matrix: + go-version: ["1.20.1"] + name: "Build + tests" runs-on: ubuntu-latest timeout-minutes: 20 @@ -30,10 +34,10 @@ jobs: sudo chmod +w /etc/machine-id echo githubciXXXXXXXXXXXXXXXXXXXXXXXX | sudo tee /etc/machine-id - - name: "Set up Go 1.20" + - name: "Set up Go ${{ matrix.go-version }}" uses: actions/setup-go@v3 with: - go-version: 1.20.1 + go-version: ${{ matrix.go-version }} id: go - name: "Check out CrowdSec repository" @@ -42,6 +46,18 @@ jobs: fetch-depth: 0 submodules: true + - name: Cache Go modules + uses: actions/cache@v3 + with: + path: | + ~/go/pkg/mod + ~/.cache/go-build + ~/Library/Caches/go-build + %LocalAppData%\go-build + key: ${{ runner.os }}-${{ matrix.go-version }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-${{ matrix.go-version }}-go- + - name: "Install bats dependencies" env: GOBIN: /usr/local/bin diff --git a/.github/workflows/bats-postgres.yml b/.github/workflows/bats-postgres.yml index dac019558..488a143cf 100644 --- a/.github/workflows/bats-postgres.yml +++ b/.github/workflows/bats-postgres.yml @@ -8,6 +8,10 @@ env: jobs: build: + strategy: + matrix: + go-version: ["1.20.1"] + name: "Build + tests" runs-on: ubuntu-latest timeout-minutes: 20 @@ -31,10 +35,10 @@ jobs: sudo chmod +w /etc/machine-id echo githubciXXXXXXXXXXXXXXXXXXXXXXXX | sudo tee /etc/machine-id - - name: "Set up Go 1.20" + - name: "Set up Go ${{ matrix.go-version }}" uses: actions/setup-go@v3 with: - go-version: 1.20.1 + go-version: ${{ matrix.go-version }} id: go - name: "Check out CrowdSec repository" @@ -43,6 +47,18 @@ jobs: fetch-depth: 0 submodules: true + - name: Cache Go modules + uses: actions/cache@v3 + with: + path: | + ~/go/pkg/mod + ~/.cache/go-build + ~/Library/Caches/go-build + %LocalAppData%\go-build + key: ${{ runner.os }}-${{ matrix.go-version }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-${{ matrix.go-version }}-go- + - name: "Install bats dependencies" env: GOBIN: /usr/local/bin diff --git a/.github/workflows/ci-windows-build-msi.yml b/.github/workflows/ci-windows-build-msi.yml index 4ea2dbc43..5c07dcaf6 100644 --- a/.github/workflows/ci-windows-build-msi.yml +++ b/.github/workflows/ci-windows-build-msi.yml @@ -22,18 +22,39 @@ on: jobs: build: + strategy: + matrix: + go-version: ["1.20.1"] + name: Build runs-on: windows-2019 + steps: - - name: Set up Go 1.20 + + - name: "Set up Go ${{ matrix.go-version }}" uses: actions/setup-go@v3 with: - go-version: 1.20.1 + go-version: ${{ matrix.go-version }} id: go + - name: Check out code into the Go module directory uses: actions/checkout@v3 with: fetch-depth: 0 + submodules: false + + - name: Cache Go modules + uses: actions/cache@v3 + with: + path: | + ~/go/pkg/mod + ~/.cache/go-build + ~/Library/Caches/go-build + %LocalAppData%\go-build + key: ${{ runner.os }}-${{ matrix.go-version }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-${{ matrix.go-version }}-go- + - name: Build run: make windows_installer - name: Upload MSI diff --git a/.github/workflows/go-tests-windows.yml b/.github/workflows/go-tests-windows.yml index a00d0c5d8..60ced8efb 100644 --- a/.github/workflows/go-tests-windows.yml +++ b/.github/workflows/go-tests-windows.yml @@ -19,17 +19,20 @@ env: CROWDSEC_FEATURE_DISABLE_HTTP_RETRY_BACKOFF: true jobs: - build: + strategy: + matrix: + go-version: ["1.20.1"] + name: "Build + tests" runs-on: windows-2022 steps: - - name: "Set up Go 1.20" + - name: "Set up Go ${{ matrix.go-version }}" uses: actions/setup-go@v3 with: - go-version: 1.20.1 + go-version: ${{ matrix.go-version }} id: go - name: Check out CrowdSec repository @@ -38,6 +41,18 @@ jobs: fetch-depth: 0 submodules: false + - name: Cache Go modules + uses: actions/cache@v3 + with: + path: | + ~/go/pkg/mod + ~/.cache/go-build + ~/Library/Caches/go-build + %LocalAppData%\go-build + key: ${{ runner.os }}-${{ matrix.go-version }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-${{ matrix.go-version }}-go- + - name: Build run: | make build diff --git a/.github/workflows/release_publish-package.yml b/.github/workflows/release_publish-package.yml index fa3aa8589..ed215c43d 100644 --- a/.github/workflows/release_publish-package.yml +++ b/.github/workflows/release_publish-package.yml @@ -8,18 +8,36 @@ on: jobs: build: + strategy: + matrix: + go-version: ["1.20.1"] + name: Build and upload binary package runs-on: ubuntu-latest steps: - - name: Set up Go 1.20 + - name: "Set up Go ${{ matrix.go-version }}" uses: actions/setup-go@v3 with: - go-version: 1.20.1 + go-version: ${{ matrix.go-version }} id: go - name: Check out code into the Go module directory uses: actions/checkout@v3 with: fetch-depth: 0 + submodules: false + + - name: Cache Go modules + uses: actions/cache@v3 + with: + path: | + ~/go/pkg/mod + ~/.cache/go-build + ~/Library/Caches/go-build + %LocalAppData%\go-build + key: ${{ runner.os }}-${{ matrix.go-version }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-${{ matrix.go-version }}-go- + - name: Build the binaries run: make release - name: Upload to release @@ -28,19 +46,37 @@ jobs: args: crowdsec-release.tgz application/x-gzip env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + build_static: + strategy: + matrix: + go-version: ["1.20.1"] name: Build and upload binary package runs-on: ubuntu-latest steps: - - name: Set up Go 1.20 + - name: "Set up Go ${{ matrix.go-version }}" uses: actions/setup-go@v3 with: - go-version: 1.20.1 + go-version: ${{ matrix.go-version }} id: go - name: Check out code into the Go module directory uses: actions/checkout@v3 with: fetch-depth: 0 + submodules: false + + - name: Cache Go modules + uses: actions/cache@v3 + with: + path: | + ~/go/pkg/mod + ~/.cache/go-build + ~/Library/Caches/go-build + %LocalAppData%\go-build + key: ${{ runner.os }}-${{ matrix.go-version }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-${{ matrix.go-version }}-go- + - name: Build the binaries run: | make release BUILD_STATIC=yes diff --git a/LICENSE b/LICENSE index 8a85fc9db..de4dbbfbb 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2020-2022 Crowdsec +Copyright (c) 2020-2023 Crowdsec Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal