Skip to content

refactor: build improvements #59

refactor: build improvements

refactor: build improvements #59

Workflow file for this run

---
name: CI/CD Pipeline
on:
push:
tags:
- v*
pull_request:
branches:
- "*"
types:
- opened
- synchronize
permissions:
contents: write
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: "18"
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: 1.21
- name: Install Dependencies
run: >
sudo add-apt-repository -y ppa:ethereum/ethereum
sudo apt-get update
sudo apt-get install -y npm ethereum
npm install
go get -d github.com/ethereum/[email protected] \
&& go install github.com/ethereum/go-ethereum/cmd/[email protected] \
&& go install github.com/mattn/[email protected] \
&& go install github.com/ory/[email protected] \
&& go install github.com/golangci/golangci-lint/cmd/[email protected]
- name: Run make setup for mainnet
run: make setup
- name: Run gofmt
run: |
gofmt
- name: Run golangci-lint
run: |
golangci-lint run -v --timeout 5m
- name: Execute test case
run: >
go-acc ./... --ignore razor/accounts/mocks --ignore razor/cmd/mocks
--ignore razor/utils/mocks --ignore pkg --ignore razor/path/mocks
--output coverage.txt
- name: Run benchmarks
run: |
go test ./... -bench=. -run=^#
- name: Publish Coverage to Coveralls.io
env:
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: goveralls -coverprofile=coverage.txt -service=github
- uses: bissolli/gh-action-persist-workspace@v1
with:
action: persist
build-amd:
runs-on: ubuntu-latest
needs: test
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: "18"
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: 1.21
- name: Install Dependencies
run: >
sudo add-apt-repository -y ppa:ethereum/ethereum
sudo apt-get update
sudo apt-get install -y npm ethereum
npm install
go get -d github.com/ethereum/[email protected] \
&& go install github.com/ethereum/go-ethereum/cmd/[email protected] \
&& go install github.com/mattn/[email protected] \
&& go install github.com/ory/[email protected] \
&& go install github.com/golangci/golangci-lint/cmd/[email protected]
- name: Create AMD Artifact
run: |
# ... [commands to create AMD artifact]
make setup
GOOS=linux GOARCH=amd64 go build -o ./build/bin/razor_go.linux-amd64 main.go
cd build/bin
tar -czvf razor_go.linux-amd64.tar.gz razor_go.linux-amd64
mv razor_go.linux-amd64.tar.gz ../../
- name: Upload AMD Artifact
uses: actions/upload-artifact@v2
with:
name: razor_go.linux-amd64.tar.gz
path: razor_go.linux-amd64.tar.gz
build-arm:
runs-on: ubuntu-latest
needs: test
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: "18"
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: 1.21
- name: Install Dependencies
run: >
sudo add-apt-repository -y ppa:ethereum/ethereum
sudo apt-get update
sudo apt-get install -y npm ethereum
npm install
go get -d github.com/ethereum/[email protected] \
&& go install github.com/ethereum/go-ethereum/cmd/[email protected] \
&& go install github.com/mattn/[email protected] \
&& go install github.com/ory/[email protected] \
&& go install github.com/golangci/golangci-lint/cmd/[email protected]
- name: Create ARM Artifact
run: |
# ... [commands to create ARM artifact]
make setup
GOOS=linux GOARCH=arm64 go build -o ./build/bin/razor_go.linux-arm64 main.go
cd build/bin
tar -czvf razor_go.linux-arm64.tar.gz razor_go.linux-arm64
mv razor_go.linux-arm64.tar.gz ../../
- name: Upload ARM Artifact
uses: actions/upload-artifact@v2
with:
name: razor_go.linux-arm64.tar.gz
path: razor_go.linux-arm64.tar.gz
publish-github-release:
runs-on: ubuntu-latest
needs:
- build-amd
- build-arm
if: startsWith(github.ref, 'refs/tags/v')
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: "18"
- name: Download Artifacts AMD
uses: actions/download-artifact@v2
with:
name: razor_go.linux-amd64.tar.gz
- name: Download Artifacts ARM
uses: actions/download-artifact@v2
with:
name: razor_go.linux-arm64.tar.gz
- name: Display structure of downloaded files
run: ls -R
- name: Publish Release on GitHub
uses: softprops/action-gh-release@v1
with:
draft: true
generate_release_notes: true
files: |
razor_go.linux-arm64.tar.gz
razor_go.linux-amd64.tar.gz
push-docker-build:
runs-on: ubuntu-latest
needs: test
if: startsWith(github.ref, 'refs/tags/v')
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Extract tag name
id: extract_tag
run: echo "::set-output name=tag_name::${GITHUB_REF#refs/tags/}"
- name: Update version.json
run: |
TAG_NAME=${{ steps.get_tag.outputs.tag }}
VERSION_ARRAY=(${TAG_NAME//-/ }) # Split 'vMajor.Minor.Patch-Meta' into 'vMajor.Minor.Patch' and 'Meta'
VERSION_STRING=${VERSION_ARRAY[0]} # 'vMajor.Minor.Patch'
VERSION_STRING=${VERSION_STRING/v/} # Remove the 'v' prefix if present
META=${VERSION_ARRAY[1]:-} # 'Meta', if any, default to empty
IFS='.' read -r VERSION_MAJOR VERSION_MINOR VERSION_PATCH <<< "$VERSION_STRING"
echo "{
\"VersionMajor\": $VERSION_MAJOR,
\"VersionMinor\": $VERSION_MINOR,
\"VersionPatch\": $VERSION_PATCH,
\"VersionMeta\": \"$META\"
}" > version.json