From a5de60f04a8955ae07b9a55dd0a1885f34b2d254 Mon Sep 17 00:00:00 2001 From: Chris Gianelloni Date: Tue, 29 Aug 2023 12:22:00 -0400 Subject: [PATCH 1/2] chore: create initial build and publish pipelines Signed-off-by: Chris Gianelloni --- .github/dependabot.yml | 11 ++ .github/workflows/ci-docker.yml | 31 +++++ .github/workflows/conventional-commits.yml | 16 +++ .github/workflows/golangci-lint.yml | 36 ++++++ .github/workflows/publish.yml | 143 +++++++++++++++++++++ 5 files changed, 237 insertions(+) create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/ci-docker.yml create mode 100644 .github/workflows/conventional-commits.yml create mode 100644 .github/workflows/golangci-lint.yml create mode 100644 .github/workflows/publish.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..e0871f9 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,11 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for all configuration options: +# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + - package-ecosystem: "gomod" # See documentation for possible values + directory: "/" # Location of package manifests + schedule: + interval: "weekly" diff --git a/.github/workflows/ci-docker.yml b/.github/workflows/ci-docker.yml new file mode 100644 index 0000000..3a861c8 --- /dev/null +++ b/.github/workflows/ci-docker.yml @@ -0,0 +1,31 @@ +name: Docker CI + +on: + pull_request: + branches: ['main'] + paths: ['Dockerfile','*.go','internal/**','go.*','.github/workflows/ci-docker.yml'] + +env: + GHCR_IMAGE_NAME: ghcr.io/blinklabs-io/bursa + +jobs: + docker: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: qemu + uses: docker/setup-qemu-action@v2 + - uses: docker/setup-buildx-action@v2 + - id: meta + uses: docker/metadata-action@v4 + with: + images: ${{ env.GHCR_IMAGE_NAME }} + - name: build + uses: docker/build-push-action@v3 + with: + context: . + push: false + ### TODO: test multiple platforms + # platforms: linux/amd64,linux/arm64 + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/conventional-commits.yml b/.github/workflows/conventional-commits.yml new file mode 100644 index 0000000..d42770b --- /dev/null +++ b/.github/workflows/conventional-commits.yml @@ -0,0 +1,16 @@ +# The below is pulled from upstream and slightly modified +# https://github.com/webiny/action-conventional-commits/blob/master/README.md#usage + +name: Conventional Commits + +on: + pull_request: + +jobs: + build: + name: Conventional Commits + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - uses: webiny/action-conventional-commits@v1.0.3 diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml new file mode 100644 index 0000000..344003a --- /dev/null +++ b/.github/workflows/golangci-lint.yml @@ -0,0 +1,36 @@ +# This file was copied from the following URL and modified: +# https://github.com/golangci/golangci-lint-action/blob/master/README.md#how-to-use + +name: golangci +on: + push: + tags: + - v* + branches: + - master + - main + pull_request: +permissions: + contents: read + pull-requests: read +jobs: + golangci: + name: lint + strategy: + matrix: + go-version: [1.19.x, 1.20.x] + platform: [ubuntu-latest, macos-latest] + runs-on: ${{ matrix.platform }} + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-go@v3 + with: + go-version: ${{ matrix.go-version }} + - name: golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + version: v1.53.3 # current version at time of commit + args: --timeout 10m + only-new-issues: true + - name: go-test + run: go test ./... diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..ce2dab5 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,143 @@ +name: publish + +on: + push: + branches: ['main'] + tags: + - 'v*.*.*' + +concurrency: ${{ github.ref }} + +jobs: + create-draft-release: + runs-on: ubuntu-latest + outputs: + RELEASE_ID: ${{ steps.create-release.outputs.result }} + steps: + - run: "echo \"RELEASE_TAG=${GITHUB_REF#refs/tags/}\" >> $GITHUB_ENV" + - uses: actions/github-script@v6 + id: create-release + if: startsWith(github.ref, 'refs/tags/') + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + result-encoding: string + script: | + try { + const response = await github.rest.repos.createRelease({ + draft: true, + generate_release_notes: true, + name: process.env.RELEASE_TAG, + owner: context.repo.owner, + prerelease: false, + repo: context.repo.repo, + tag_name: process.env.RELEASE_TAG, + }); + + return response.data.id; + } catch (error) { + core.setFailed(error.message); + } + + build-binaries: + strategy: + matrix: + os: [linux, darwin, freebsd, windows] + arch: [amd64, arm64] + runs-on: ubuntu-latest + needs: [create-draft-release] + steps: + - run: "echo \"RELEASE_TAG=${GITHUB_REF#refs/tags/}\" >> $GITHUB_ENV" + - uses: actions/checkout@v3 + - uses: actions/setup-go@v3 + with: + go-version: 1.19 + - name: Build binary + run: GOOS=${{ matrix.os }} GOARCH=${{ matrix.arch }} make build + - name: Upload release asset + if: startsWith(github.ref, 'refs/tags/') + run: | + _filename=bursa-${{ env.RELEASE_TAG }}-${{ matrix.os }}-${{ matrix.arch }} + if [[ ${{ matrix.os }} == windows ]]; then + _filename=${_filename}.exe + fi + mv bursa ${_filename} + curl \ + -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + -H "Content-Type: application/octet-stream" \ + --data-binary @${_filename} \ + https://uploads.github.com/repos/${{ github.repository_owner }}/bursa/releases/${{ needs.create-draft-release.outputs.RELEASE_ID }}/assets?name=${_filename} + + build-images: + runs-on: ubuntu-latest + needs: [create-draft-release] + steps: + - run: "echo \"RELEASE_TAG=${GITHUB_REF#refs/tags/}\" >> $GITHUB_ENV" + - uses: actions/checkout@v3 + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Login to Docker Hub + uses: docker/login-action@v2 + with: + username: blinklabs + password: ${{ secrets.DOCKER_PASSWORD }} # uses token + - name: Login to GHCR + uses: docker/login-action@v2 + with: + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + registry: ghcr.io + - id: meta + uses: docker/metadata-action@v4 + with: + images: | + blinklabs/bursa + ghcr.io/${{ github.repository }} + tags: | + # Only version, no revision + type=match,pattern=v(.*)-(.*),group=1 + # branch + type=ref,event=branch + # semver + type=semver,pattern={{version}} + - name: Build images + uses: docker/build-push-action@v3 + with: + outputs: "type=registry,push=true" + platforms: linux/amd64,linux/arm64 + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + # Update Docker Hub from README + - name: Docker Hub Description + uses: peter-evans/dockerhub-description@v3 + with: + username: blinklabs + password: ${{ secrets.DOCKER_PASSWORD }} + repository: blinklabs/bursa + readme-filepath: ./README.md + short-description: "Snek is a tool for tailing the Cardano blockchain and emitting events" + + finalize-release: + runs-on: ubuntu-latest + needs: [create-draft-release, build-binaries, build-images] + steps: + - uses: actions/github-script@v6 + if: startsWith(github.ref, 'refs/tags/') + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + try { + await github.rest.repos.updateRelease({ + owner: context.repo.owner, + repo: context.repo.repo, + release_id: ${{ needs.create-draft-release.outputs.RELEASE_ID }}, + draft: false, + }); + } catch (error) { + core.setFailed(error.message); + } + # This updates the documentation on pkg.go.dev and the latest version available via the Go module proxy + - name: Pull new module version + if: startsWith(github.ref, 'refs/tags/') + uses: andrewslotin/go-proxy-pull-action@v1.0.3 From 3259b2211f9faba9af0aa90892b6486d97860f67 Mon Sep 17 00:00:00 2001 From: Chris Gianelloni Date: Tue, 29 Aug 2023 14:17:29 -0400 Subject: [PATCH 2/2] fix(ci): use correct description for docker hub Signed-off-by: Chris Gianelloni --- .github/workflows/publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index ce2dab5..172294b 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -116,7 +116,7 @@ jobs: password: ${{ secrets.DOCKER_PASSWORD }} repository: blinklabs/bursa readme-filepath: ./README.md - short-description: "Snek is a tool for tailing the Cardano blockchain and emitting events" + short-description: "Bursa is a programmatic Cardano wallet and CLI tool" finalize-release: runs-on: ubuntu-latest