Skip to content

Commit

Permalink
feat: setup the release CICD and github workflow (backport #34) (#35)
Browse files Browse the repository at this point in the history
* feat: setup the release CICD and github workflow (#34)

* github workflow

* minor update

(cherry picked from commit 17f7ed4)

* minor fix

---------

Co-authored-by: Master Engineer <[email protected]>
Co-authored-by: mastereng12 <[email protected]>
  • Loading branch information
3 people authored Apr 29, 2024
1 parent 389f6d3 commit 8cf2714
Show file tree
Hide file tree
Showing 9 changed files with 227 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# CODEOWNERS: https://help.github.com/articles/about-codeowners/

# NOTE: Order is important; the last matching pattern takes the most precedence

# Primary repo maintainers

* @Lagrange-Labs/lsc-core-dev
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
version: 2
updates:
- package-ecosystem: "gomod"
directory: "/"
schedule:
interval: "daily"
12 changes: 12 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## Context

Closes: #XXXX

<!-- Add a description of the changes that this PR introduces. -->

---

## Reviewers

- @XXX
- @YYY
27 changes: 27 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Lint
# Lint runs golangci-lint over the entire repository
# This workflow is run on every pull request and push to master
# The `golangci` will pass without running if no *.{go, mod, sum} files have been changed.
on:
pull_request:
push:
branches:
- develop
- main
tags:
- "v[0-9]+.[0-9]+.[0-9]+*" # Push events to matching tags v1.0.0, v1.0.1, v1.1.0, v2.0.0, etc.

jobs:
golangci:
name: golangci-lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: 1.21
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.55.2
args: --timeout=10m
30 changes: 30 additions & 0 deletions .github/workflows/push-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Push Docker Image
on:
push:
branches:
- develop
- main

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Get the branch name
run: echo "BRANCH=${GITHUB_REF##*/}" >> $GITHUB_ENV
- name: Build and push
id: docker_build
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: |
lagrangelabs/lagrange-cli:${{ env.BRANCH }}
82 changes: 82 additions & 0 deletions .github/workflows/tag-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Auto Tag and Push Docker Release Image

on:
pull_request:
types: [closed]
branches:
- release/v*

jobs:
auto-tag-and-push:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Identify and Create New Tag
id: new_tag
run: |
# Extract major and minor version from the branch name
BRANCH_NAME="${GITHUB_REF#refs/heads/}"
VERSION_PREFIX=$(echo $BRANCH_NAME | sed -E 's/release\/v([0-9]+\.[0-9]+).*/\1/')
# Fetch tags and find the latest tag with the same major and minor version
git fetch --tags
LATEST_TAG=$(git tag -l "v$VERSION_PREFIX.*" | sort -V | tail -n1)
echo "Latest tag for version $VERSION_PREFIX: $LATEST_TAG"
# Check if a tag was found, if not, start with x.0
if [ -z "$LATEST_TAG" ]; then
NEW_TAG="v${VERSION_PREFIX}.0"
else
# Increment the patch version
NEW_TAG=$(echo $LATEST_TAG | awk -F. '{print $1"."$2"."$3+1}')
fi
echo "New tag: $NEW_TAG"
# Create and push the new tag
git tag $NEW_TAG
git push origin $NEW_TAG
echo "::set-output name=tag::$NEW_TAG"
- name: Get Title For Release
id: get_pr_details
run: |
# Fetch the full commit message of the most recent commit
FULL_COMMIT_MESSAGE=$(git log -1 --pretty=format:%B)
echo "Full commit message: $FULL_COMMIT_MESSAGE"
# Extract the main title from the commit message
# This regex captures the string before the first "(" and removes trailing spaces
PR_TITLE=$(echo "$FULL_COMMIT_MESSAGE" | sed -n '1p' | sed 's/ *([^()]*) *//g')
echo "::set-output name=title::$PR_TITLE"
- name: Create Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.new_tag.outputs.tag }}
release_name: ${{ steps.get_pr_details.outputs.title }}
draft: false
prerelease: false

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push
id: docker_build
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: |
lagrangelabs/lagrange-cli:${{ steps.new_tag.outputs.tag }}
24 changes: 24 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Test
on:
push:
branches:
- develop
- main
tags:
- "v[0-9]+.[0-9]+.[0-9]+*" # Push events to matching tags v1.0.0, v1.0.1, v1.1.0, v2.0.0, etc.
pull_request:

jobs:
Test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: "1.21" # The Go version to download (if necessary) and use.
- name: test & coverage report creation
run: |
make test
env:
CGO_CFLAGS: "-O -D__BLST_PORTABLE__"
CGO_CFLAGS_ALLOW: "-O -D__BLST_PORTABLE__"
19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# CONTAINER FOR BUILDING BINARY
FROM golang:1.21-alpine AS build

RUN apk add --no-cache --update gcc g++ make

ENV CGO_CFLAGS="-O -D__BLST_PORTABLE__"
ENV CGO_CFLAGS_ALLOW="-O -D__BLST_PORTABLE__"

# INSTALL DEPENDENCIES
COPY go.mod go.sum /src/
RUN cd /src && go mod download

# BUILD BINARY
COPY . /src
RUN cd /src && make build

FROM alpine:edge
COPY --from=build /src/dist/lagrange-cli /app/lagrange-cli
CMD ["/bin/sh", "-c", "/app/lagrange-cli version"]
19 changes: 19 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,22 @@ build: ## Builds the binary locally into ./dist
scgen: # Generate the go bindings for the smart contracts
@ cd scinterface && sh generator.sh

# Linting, Teseting, Benchmarking
golangci_lint_cmd=github.com/golangci/golangci-lint/cmd/[email protected]

install-linter:
@echo "--> Installing linter"
@go install $(golangci_lint_cmd)

lint:
@echo "--> Running linter"
@ $$(go env GOPATH)/bin/golangci-lint run --timeout=10m
.PHONY: lint install-linter

test:
trap '$(STOP)' EXIT; go test ./... --timeout=10m
.PHONY: test

docker-build: ## Builds a docker image with the cli binary
docker build -t lagrange-cli -f ./Dockerfile .
.PHONY: docker-build

0 comments on commit 8cf2714

Please sign in to comment.