From 39dacb5fb257f82d89c3df30b24a8f64ccf573af Mon Sep 17 00:00:00 2001 From: Romain Dartigues Date: Fri, 24 May 2024 11:53:32 +0200 Subject: [PATCH] CI: add automatic release on tag --- .github/workflows/goreleaser.yml | 61 ++++++++++++++++++++++++++++++++ .github/workflows/unit-tests.yml | 2 +- 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/goreleaser.yml diff --git a/.github/workflows/goreleaser.yml b/.github/workflows/goreleaser.yml new file mode 100644 index 0000000..2fd8eb3 --- /dev/null +++ b/.github/workflows/goreleaser.yml @@ -0,0 +1,61 @@ +name: goreleaser + +on: + push: + # do not consider simple commit + branches: + - '!*' + # consider only release and pre-release tags + tags: + - 'v[0-9]+.[0-9]+.[0-9]+' + - 'v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+' + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: set up go + uses: actions/setup-go@v5 + with: + go-version: "1.22" + + - name: cache go modules + uses: actions/cache@v4 + with: + path: ~/go/pkg/mod + key: "${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}" + restore-keys: | + ${{ runner.os }}-go- + + - name: tests modules + run: | + go mod vendor + if [ ! -z "$(git status --porcelain)" ]; then + echo "::error::vendor directory if not synced with go.mod, please run go mod vendor" + exit 1 + fi + + go mod tidy + if [ ! -z "$(git status --porcelain)" ]; then + echo "::error::modules are not tidy, please run go mod tidy" + exit 1 + fi + + - name: tests + run: | + go test -v ./... + + - name: run goreleaser + uses: goreleaser/goreleaser-action@v5 + if: success() && startsWith(github.ref, 'refs/tags/') + with: + version: latest + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + USER: github-actions diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 6157eac..554cf27 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -16,7 +16,7 @@ jobs: - name: set up go uses: actions/setup-go@v5 with: - go-version: 1.22 + go-version: "1.22" - name: cache go modules uses: actions/cache@v4