From 641f9764c73f9d1e4483d83a6c74ca64b2a4e5ad Mon Sep 17 00:00:00 2001 From: Joe Lanford Date: Fri, 17 Nov 2023 17:59:17 -0500 Subject: [PATCH] GH Actions CI and release improvements (#89) - Make sure bin directory exists prior to attempting binary fetches - Bump versions of goreleaser and krew-release-bot - Share goreleaser workflow for PRs, branch pushes, and tags, but with configuration based on event type Signed-off-by: Joe Lanford --- .github/workflows/ci.yml | 13 ++++--------- .github/workflows/release.yml | 24 ++++++++++++++++++------ .goreleaser.yml | 3 +++ Makefile | 4 ++-- scripts/fetch.sh | 1 + 5 files changed, 28 insertions(+), 17 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 619befa..983692d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,19 +1,19 @@ -name: ci +name: test on: push: pull_request: jobs: - goreleaser: + test: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: fetch-depth: 0 - name: Setup Go - uses: actions/setup-go@v3 + uses: actions/setup-go@v4 with: go-version-file: go.mod @@ -22,8 +22,3 @@ jobs: - name: Lint run: make lint - - - name: Run GoReleaser - run: make release - env: - RELEASE_ARGS: release --rm-dist --snapshot diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5881260..5eb0533 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,28 +1,40 @@ name: release on: push: + branches: + - 'main' tags: - 'v*.*.*' + pull_request: + branches: + - 'main' + jobs: - goreleaser: + release: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: fetch-depth: 0 - name: Setup Go - uses: actions/setup-go@v3 + uses: actions/setup-go@v4 with: go-version-file: go.mod + - name: Set the release related variables + if: startsWith(github.ref, 'refs/tags/v') + run: | + echo RELEASE_ARGS="--clean" >> $GITHUB_ENV + echo ENABLE_RELEASE_PIPELINE=true >> $GITHUB_ENV + - name: Run GoReleaser run: make release env: - RELEASE_ARGS: release --rm-dist - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_TOKEN: ${{ github.token }} - name: Update new version in krew-index - uses: rajatjindal/krew-release-bot@v0.0.38 + if: startsWith(github.ref, 'refs/tags/v') + uses: rajatjindal/krew-release-bot@v0.0.46 diff --git a/.goreleaser.yml b/.goreleaser.yml index 7f3d2e7..c2f24e6 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -36,3 +36,6 @@ archives: format: tar.gz files: - LICENSE + +release: + disable: '{{ ne .Env.ENABLE_RELEASE_PIPELINE "true" }}' diff --git a/Makefile b/Makefile index 7cb36a8..ea14c1f 100644 --- a/Makefile +++ b/Makefile @@ -51,6 +51,6 @@ lint: source ./scripts/fetch.sh; fetch golangci-lint 1.50.1 && ./bin/golangci-lint --timeout 3m run .PHONY: release -RELEASE_ARGS?=release --rm-dist --snapshot +RELEASE_ARGS?=release --clean --snapshot release: - source ./scripts/fetch.sh; fetch goreleaser 1.13.0 && ./bin/goreleaser $(RELEASE_ARGS) + source ./scripts/fetch.sh; fetch goreleaser 1.22.1 && ./bin/goreleaser $(RELEASE_ARGS) diff --git a/scripts/fetch.sh b/scripts/fetch.sh index 397b187..b0c71dd 100644 --- a/scripts/fetch.sh +++ b/scripts/fetch.sh @@ -3,6 +3,7 @@ ROOT="$( git rev-parse --show-toplevel )" fetch() { + mkdir -p "${ROOT}/bin" local tool=$1; shift local ver=$1; shift