From b053ac8302225286f33456fd08a28aa9d19b12c1 Mon Sep 17 00:00:00 2001 From: Runchao Han Date: Fri, 11 Oct 2024 18:03:06 +1100 Subject: [PATCH] ci: GH actions for goreleaser, changelog reminder, and backport (#48) --- .github/workflows/backport.yml | 38 ++++++++++++ .github/workflows/changelog-reminder.yml | 11 ++++ .github/workflows/ci.yml | 4 +- .github/workflows/goreleaser.yml | 11 ++++ .github/workflows/publish.yml | 4 +- .gitignore | 1 + .goreleaser.yml | 73 ++++++++++++++++++++++++ CHANGELOG.md | 5 ++ Makefile | 55 ++++++++++++++++++ 9 files changed, 198 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/backport.yml create mode 100644 .github/workflows/changelog-reminder.yml create mode 100644 .github/workflows/goreleaser.yml create mode 100644 .goreleaser.yml diff --git a/.github/workflows/backport.yml b/.github/workflows/backport.yml new file mode 100644 index 0000000..47c9985 --- /dev/null +++ b/.github/workflows/backport.yml @@ -0,0 +1,38 @@ +# Adapted from https://github.com/marketplace/actions/backporting +# +# Usage: +# - Let's say you want to backport a pull request on a branch named `production`. +# - Then label it with `backport production`. +# - That's it! When the pull request gets merged, it will be backported to +# the `production` branch. If the pull request cannot be backported, a comment +# explaining why will automatically be posted. +# +# Note: multiple backport labels can be added. For example, if a pull request +# has the labels `backport staging` and `backport production` it will be +# backported to both branches: `staging` and `production`. +name: Backport +on: + pull_request_target: + types: + - closed + - labeled + +jobs: + backport: + name: Backport + runs-on: ubuntu-latest + # Only react to merged PRs for security reasons. + # See https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_target. + if: > + github.event.pull_request.merged + && ( + github.event.action == 'closed' + || ( + github.event.action == 'labeled' + && contains(github.event.label.name, 'backport') + ) + ) + steps: + - uses: tibdex/backport@v2 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/changelog-reminder.yml b/.github/workflows/changelog-reminder.yml new file mode 100644 index 0000000..ebe2a55 --- /dev/null +++ b/.github/workflows/changelog-reminder.yml @@ -0,0 +1,11 @@ +name: Changelog Reminder +on: + pull_request: + types: [assigned, opened, synchronize, reopened, labeled, unlabeled] + branches: + - main + +jobs: + changelog_reminder: + uses: babylonlabs-io/.github/.github/workflows/reusable_changelog_reminder.yml@v0.7.0 + secrets: inherit diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 68d40bd..5f332af 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,14 +7,14 @@ on: jobs: lint_test: - uses: babylonlabs-io/.github/.github/workflows/reusable_go_lint_test.yml@v0.1.0 + uses: babylonlabs-io/.github/.github/workflows/reusable_go_lint_test.yml@v0.7.0 with: run-unit-tests: true run-integration-tests: true run-lint: true docker_pipeline: - uses: babylonlabs-io/.github/.github/workflows/reusable_docker_pipeline.yml@v0.1.0 + uses: babylonlabs-io/.github/.github/workflows/reusable_docker_pipeline.yml@v0.7.0 secrets: inherit with: publish: false diff --git a/.github/workflows/goreleaser.yml b/.github/workflows/goreleaser.yml new file mode 100644 index 0000000..7e304dc --- /dev/null +++ b/.github/workflows/goreleaser.yml @@ -0,0 +1,11 @@ +name: goreleaser + +on: + push: + tags: + - '*' + +jobs: + release: + uses: babylonlabs-io/.github/.github/workflows/reusable_go_releaser.yml@v0.7.0 + secrets: inherit \ No newline at end of file diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 1c4254b..70f9e7b 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -9,7 +9,7 @@ on: jobs: lint_test: - uses: babylonlabs-io/.github/.github/workflows/reusable_go_lint_test.yml@v0.1.0 + uses: babylonlabs-io/.github/.github/workflows/reusable_go_lint_test.yml@v0.7.0 with: run-unit-tests: true run-integration-tests: true @@ -17,7 +17,7 @@ jobs: docker_pipeline: needs: ["lint_test"] - uses: babylonlabs-io/.github/.github/workflows/reusable_docker_pipeline.yml@v0.1.0 + uses: babylonlabs-io/.github/.github/workflows/reusable_docker_pipeline.yml@v0.7.0 secrets: inherit with: publish: true diff --git a/.gitignore b/.gitignore index 23533da..414aecc 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,4 @@ main tmp/ build/ +dist/ diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..1297fec --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,73 @@ +project_name: btc-staker + +builds: + - id: stakerd-linux-amd64 + main: ./cmd/stakerd/main.go + binary: stakerd + hooks: + pre: + - wget https://github.com/CosmWasm/wasmvm/releases/download/{{ .Env.COSMWASM_VERSION }}/libwasmvm_muslc.x86_64.a -O /usr/lib/libwasmvm_muslc.x86_64.a + goos: + - linux + goarch: + - amd64 + env: + - GO111MODULE=on + flags: + - -mod=readonly + - -trimpath + tags: + - netgo + - osusergo + + - id: stakercli-linux-amd64 + main: ./cmd/stakercli/main.go + binary: stakercli + hooks: + pre: + - wget https://github.com/CosmWasm/wasmvm/releases/download/{{ .Env.COSMWASM_VERSION }}/libwasmvm_muslc.x86_64.a -O /usr/lib/libwasmvm_muslc.x86_64.a + goos: + - linux + goarch: + - amd64 + env: + - GO111MODULE=on + flags: + - -mod=readonly + - -trimpath + tags: + - netgo + - osusergo + +archives: + - id: zipped + builds: + - stakerd-linux-amd64 + - stakercli-linux-amd64 + name_template: "{{.ProjectName}}-{{ .Version }}-{{ .Os }}-{{ .Arch }}" + format: tar.gz + files: + - none* + - id: binaries + builds: + - stakerd-linux-amd64 + - stakercli-linux-amd64 + name_template: "{{.ProjectName}}-{{ .Version }}-{{ .Os }}-{{ .Arch }}" + format: binary + files: + - none* + +checksum: + name_template: "{{ .ProjectName }}_{{ .Version }}_checksums.txt" + algorithm: sha256 + +release: + github: + owner: babylonlabs-io + name: btc-staker + +# Docs: https://goreleaser.com/customization/changelog/ +changelog: + disable: true + +dist: dist diff --git a/CHANGELOG.md b/CHANGELOG.md index 0be8df8..c992585 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) * [44](https://github.com/babylonlabs-io/btc-staker/pull/44) Implement pre-approval flow support +### Improvements + +* [#48](https://github.com/babylonlabs-io/btc-staker/pull/48) Add Github actions + for goreleaser, changelog reminder, and backport + ## v0.6.0 ### Bug fixes diff --git a/Makefile b/Makefile index 882c431..dd5597b 100644 --- a/Makefile +++ b/Makefile @@ -63,3 +63,58 @@ update-changelog: ./scripts/update_changelog.sh $(sinceTag) $(upcomingTag) .PHONY: update-changelog + + +############################################################################### +### Release ### +############################################################################### + +# The below is adapted from https://github.com/osmosis-labs/osmosis/blob/main/Makefile +GO_VERSION := $(shell grep -E '^go [0-9]+\.[0-9]+' go.mod | awk '{print $$2}') +GORELEASER_IMAGE := ghcr.io/goreleaser/goreleaser-cross:v$(GO_VERSION) +COSMWASM_VERSION := $(shell go list -m github.com/CosmWasm/wasmvm/v2 | sed 's/.* //') + +.PHONY: release-dry-run release-snapshot release +release-dry-run: + docker run \ + --rm \ + -e COSMWASM_VERSION=$(COSMWASM_VERSION) \ + -v /var/run/docker.sock:/var/run/docker.sock \ + -v `pwd`:/go/src/babylon \ + -w /go/src/babylon \ + $(GORELEASER_IMAGE) \ + release \ + --clean \ + --skip=publish + +release-snapshot: + docker run \ + --rm \ + -e COSMWASM_VERSION=$(COSMWASM_VERSION) \ + -v /var/run/docker.sock:/var/run/docker.sock \ + -v `pwd`:/go/src/babylon \ + -w /go/src/babylon \ + $(GORELEASER_IMAGE) \ + release \ + --clean \ + --snapshot \ + --skip=publish,validate + +# NOTE: By default, the CI will handle the release process. +# this is for manually releasing. +ifdef GITHUB_TOKEN +release: + docker run \ + --rm \ + -e GITHUB_TOKEN=$(GITHUB_TOKEN) \ + -e COSMWASM_VERSION=$(COSMWASM_VERSION) \ + -v /var/run/docker.sock:/var/run/docker.sock \ + -v `pwd`:/go/src/babylon \ + -w /go/src/babylon \ + $(GORELEASER_IMAGE) \ + release \ + --clean +else +release: + @echo "Error: GITHUB_TOKEN is not defined. Please define it before running 'make release'." +endif \ No newline at end of file