Skip to content

Commit

Permalink
ci: Add automated semantic release using Goreleaser (#357)
Browse files Browse the repository at this point in the history
Co-authored-by: Ankur Banerjee <ankurdotb@users.noreply.github.com>
  • Loading branch information
Andrew Nikitin and ankurdotb authored Aug 13, 2022
1 parent 5a30740 commit 4517a19
Show file tree
Hide file tree
Showing 12 changed files with 10,517 additions and 94 deletions.
47 changes: 16 additions & 31 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
name: "Build"
on:
workflow_call:
outputs:
VERSION:
description: "Build version number"
value: ${{ jobs.build-binary.outputs.VERSION }}
defaults:
run:
shell: bash
Expand All @@ -13,10 +9,8 @@ defaults:
jobs:

build-binary:
name: "Build node binary"
name: "Node binary"
runs-on: ubuntu-latest
outputs:
VERSION: ${{ steps.set-version.outputs.VERSION }}

steps:
- uses: actions/checkout@v3
Expand All @@ -26,39 +20,29 @@ jobs:
- uses: actions/setup-go@v3
with:
go-version-file: ./go.mod
cache: true

- name: Run Golang unit tests
run: go test -v ./...

# - uses: bufbuild/buf-setup-action@v1.7.0
# env:
# BUF_TOKEN: ${{ secrets.BUF_TOKEN }}

# Calls a section in Makefile > Makefile > make/proto.mk > protocgen.sh
- name: Generate Protobufs
run: make proto-gen
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v3
with:
distribution: goreleaser
version: latest
args: build --rm-dist --snapshot --single-target

- name: Build node binary
run: |
make build
- name: Store artifact
uses: actions/upload-artifact@v3
with:
name: cheqd-noded
path: build/cheqd-noded
path: dist/**/cheqd-noded

- name: Set version number
id: set-version
run: |
VERSION=$(build/cheqd-noded version 2>&1)
echo ::set-output name=VERSION::"$VERSION"
- name: Run Golang unit tests
run: go test -v ./...

build-docker:
name: "Build Docker image"
name: "Docker image"
runs-on: ubuntu-latest
env:
DOCKER_TEST_IMAGE: ${{ github.repository }}:test
DOCKER_TEST_IMAGE: ${{ github.repository }}:${{ github.sha }}

steps:
- uses: actions/checkout@v3
Expand All @@ -68,11 +52,12 @@ jobs:
- uses: actions/setup-go@v3
with:
go-version-file: ./go.mod
cache: true

- name: Generate Protobufs
run: make proto-gen

- name: Set up Docker Buildx
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v2
id: buildx
with:
Expand All @@ -90,7 +75,7 @@ jobs:
tags: ${{ env.DOCKER_TEST_IMAGE }}
outputs: type=docker,dest=/tmp/cheqd-node-image.tar

- name: Store Docker test image artifact
- name: Upload Docker test image
uses: actions/upload-artifact@v3
with:
name: cheqd-node-image.tar
Expand Down
4 changes: 0 additions & 4 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ jobs:
with:
go-version-file: ./go.mod

- uses: bufbuild/buf-setup-action@v1.7.0
env:
BUF_TOKEN: ${{ secrets.BUF_TOKEN }}

- uses: actions/checkout@v3
with:
fetch-depth: 0 # Required to fetch version
Expand Down
17 changes: 7 additions & 10 deletions .github/workflows/dispatch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,11 @@ jobs:
# name: "Test"
# needs: call-build
# uses: ./.github/workflows/test.yml
# with:
# VERSION: ${{ needs.call-build.outputs.VERSION }}

# call-release:
# name: "Release"
# # needs: [call-test, call-build]
# needs: call-build
# if: ${{ github.ref_protected == true }}
# uses: ./.github/workflows/release.yml
# with:
# RELEASE_VERSION: ${{ needs.call-build.outputs.VERSION }}
call-release:
name: "Release"
# needs: [call-test, call-build]
needs: call-build
if: ${{ github.ref_protected == true }}
uses: ./.github/workflows/release.yml
secrets: inherit
135 changes: 86 additions & 49 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,86 +1,123 @@
name: "Release"
on:
workflow_call:
inputs:
RELEASE_VERSION:
description: "Release version number"
type: string
defaults:
run:
shell: bash
permissions:
contents: write
packages: write


jobs:

release-packages:
name: "Release cheqd-noded binary"
release-binary:
name: "Node binary"
runs-on: ubuntu-latest
permissions:
contents: write
env:
RELEASE_VERSION: ${{ inputs.RELEASE_VERSION }}
outputs:
RELEASE_VERSION: ${{ steps.set-version.outputs.RELEASE_VERSION }}

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Required to fetch version

- name: Download node binary from build stage
uses: actions/download-artifact@v3
- uses: actions/setup-go@v3
with:
name: cheqd-noded
path: build-tools
go-version-file: ./go.mod
cache: true

- name: Restore binary permissions
run: sudo chmod +x build-tools/cheqd-noded
# Node.js setup is needed to run Semantic Release
- uses: actions/setup-node@v3
with:
node-version: 16
cache: 'npm'
cache-dependency-path: '**/package-lock.json'

- name: "Obtain Github App token"
id: app-token
uses: getsentry/action-github-app-token@v1.0.6
with:
app_id: ${{ secrets.BOT_APP_ID }}
private_key: ${{ secrets.BOT_APP_PRIVATE_KEY }}

- name: "Install Semantic Release dependencies"
run: npm ci

- name: "Execute Semantic Release"
run: npx semantic-release
env:
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}

- uses: "marvinpinto/action-automatic-releases@latest"
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v3
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
automatic_release_tag: "${{ env.GITHUB_REF_NAME }}"
prerelease: true
draft: true
files: |
build-tools/cheqd-noded
release-docker-images:
name: "Publish Docker images for new version"
distribution: goreleaser
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Set release version number
id: set-version
run: |
RELEASE_VERSION=$( git describe --tags ${{ github.sha }})
echo ::set-output name=RELEASE_VERSION::"$RELEASE_VERSION"
release-docker:
name: "Docker image"
needs: release-binary
runs-on: ubuntu-latest
env:
REGISTRY: ghcr.io
RELEASE_VERSION: ${{ inputs.RELEASE_VERSION }}

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Required to fetch version

- uses: actions/setup-go@v3
with:
go-version-file: ./go.mod
cache: true

- name: Generate golang code
run: make proto-gen

- name: Build cheqd-cli Docker image 'cheqd-noded' as entrypoint and no build args
run: docker build --target base -t cheqd-cli -f docker/Dockerfile .

- name: Build cheqd-node Docker image with 'node-start' as entrypoint and no build args
run: docker build --target node -t cheqd-node -f docker/Dockerfile .
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
id: buildx
with:
version: latest

- name: Login to Container registry
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Configure Docker image metadata
id: meta
uses: docker/metadata-action@v4
with:
images: ghcr.io/${{ github.repository}}
flavor: |
latest=auto
tags: |
type=semver,pattern={{version}},value=${{ needs.release-binary.outputs.RELEASE_VERSION }}
labels: |
org.opencontainers.image.title="cheqd Node Docker Image"
org.opencontainers.image.description="Node for cheqd network"
org.opencontainers.image.source="https://github.com/cheqd/cheqd-node"
org.opencontainers.image.vendor="Cheqd Foundation Limited"
org.opencontainers.image.created={{date 'dddd, MMMM Do YYYY, h:mm:ss a'}}
org.opencontainers.image.documentation="https://docs.cheqd.io/node"
- name: Push cheqd-node image
run: |
docker tag cheqd-node ghcr.io/${{ github.repository }}:${{ env.RELEASE_VERSION }}
docker tag cheqd-node ghcr.io/${{ github.repository }}:latest
docker push ghcr.io/${{ github.repository }}:${{ env.RELEASE_VERSION }}
docker push ghcr.io/${{ github.repository }}:latest
- name: Push cheqd-cli image
run: |
docker tag cheqd-cli ghcr.io/${{ github.repository_owner }}/cheqd-cli:${{ env.RELEASE_VERSION }}
docker tag cheqd-cli ghcr.io/${{ github.repository_owner }}/cheqd-cli:latest
docker push ghcr.io/${{ github.repository_owner }}/cheqd-cli:${{ env.RELEASE_VERSION }}
docker push ghcr.io/${{ github.repository_owner }}/cheqd-cli:latest
- name: Build and push image
uses: docker/build-push-action@v3
with:
context: .
file: docker/Dockerfile
platforms: linux/amd64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
### APP-SPECIFIC EXCLUSIONS ###
build/
dist/

# Tests
**/network-config
Expand Down
Loading

0 comments on commit 4517a19

Please sign in to comment.