fix: refactor: use temporary context for cleaner error handling #2975
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build | |
on: | |
push: | |
branches: | |
- develop | |
- athens2-develop | |
tags: | |
- "*" | |
pull_request: | |
branches: | |
- develop | |
- athens2-develop | |
types: | |
- synchronize | |
- opened | |
- reopened | |
- ready_for_review | |
concurrency: | |
group: ${{ github.head_ref || github.run_id }} | |
cancel-in-progress: true | |
env: | |
S3_BUCKET_PATH: "zetachain-deployment-files/builds/zeta-node" | |
S3_PUBLIC_BUCKET_PATH: "zetachain-external-files" | |
AWS_REGION: "us-east-1" | |
GITHUB_REF_NAME: "$(echo ${{ github.ref_name }} | tr '//' '-')" | |
jobs: | |
build-and-test: | |
strategy: | |
matrix: | |
runs-on: | |
[ | |
buildjet-4vcpu-ubuntu-2204-arm, | |
buildjet-4vcpu-ubuntu-2204, | |
buildjet-4vcpu-ubuntu-2004 | |
] | |
runs-on: ${{matrix.runs-on}} | |
timeout-minutes: 30 | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set CPU Architecture | |
shell: bash | |
run: | | |
if [ "$(uname -m)" == "aarch64" ]; then | |
echo "CPU_ARCH=arm64" >> $GITHUB_ENV | |
elif [ "$(uname -m)" == "x86_64" ]; then | |
echo "CPU_ARCH=amd64" >> $GITHUB_ENV | |
else | |
echo "Unsupported architecture" >&2 | |
exit 1 | |
fi | |
- name: Install Pipeline Dependencies | |
uses: ./.github/actions/install-dependencies | |
timeout-minutes: 8 | |
with: | |
cpu_architecture: ${{ env.CPU_ARCH }} | |
skip_python: "true" | |
skip_aws_cli: "true" | |
skip_docker_compose: "true" | |
- name: setup-git-credentials | |
uses: de-vri-es/[email protected] | |
with: | |
credentials: ${{ secrets.PAT_GITHUB_SERVICE_ACCT }} | |
# - uses: buildjet/cache | |
# timeout-minutes: 5 | |
# with: | |
# path: | | |
# ~/.cache/go-build | |
# ~/go/pkg/mod | |
# key: ${{ matrix.runs-on }}-go-${{ hashFiles('**/go.sum') }} | |
# restore-keys: | | |
# ${{ matrix.runs-on }}-go- | |
- name: Build zetacored and zetaclientd | |
env: | |
CGO_ENABLED: 1 | |
GOOS: linux | |
GOARCH: ${{ env.CPU_ARCH }} | |
run: | | |
make clean | |
make install-testnet | |
cp "$HOME"/go/bin/* ./ | |
- name: Test | |
run: | | |
echo "Running Build Tests" | |
make test | |
chmod a+x ./zetacored | |
./zetacored version | |
- name: Name Binaries | |
if: startsWith(github.ref, 'refs/tags/') || startsWith(github.ref, 'refs/heads/develop') | |
env: | |
CPU_ARCH: ${{ env.CPU_ARCH }} | |
run: | | |
OS_VERSION=$(cat /etc/lsb-release | grep DISTRIB_RELEASE | cut -d '=' -f 2 | cut -d '.' -f 1) | |
cp zetacored zetacored-ubuntu-$OS_VERSION-$CPU_ARCH | |
cp zetaclientd zetaclientd-ubuntu-$OS_VERSION-$CPU_ARCH | |
- name: Save Binaries as Artifacts | |
uses: actions/upload-artifact@v3 | |
if: startsWith(github.ref, 'refs/tags/') || startsWith(github.ref, 'refs/heads/develop') | |
with: | |
name: binaries-${{ github.sha }} | |
path: | | |
zetacored-ubuntu-* | |
zetaclientd-ubuntu-* | |
- name: Clean Up Workspace | |
if: always() | |
shell: bash | |
run: rm -rf * | |
build-alpine-and-test: | |
runs-on: ["ubuntu-latest"] | |
timeout-minutes: 30 | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set CPU Architecture | |
shell: bash | |
run: | | |
if [ "$(uname -m)" == "aarch64" ]; then | |
echo "CPU_ARCH=arm64" >> $GITHUB_ENV | |
elif [ "$(uname -m)" == "x86_64" ]; then | |
echo "CPU_ARCH=amd64" >> $GITHUB_ENV | |
else | |
echo "Unsupported architecture" >&2 | |
exit 1 | |
fi | |
- name: Install Pipeline Dependencies | |
uses: ./.github/actions/install-dependencies | |
timeout-minutes: 8 | |
with: | |
cpu_architecture: ${{ env.CPU_ARCH }} | |
skip_python: "true" | |
skip_aws_cli: "true" | |
skip_docker_compose: "false" | |
- uses: jirutka/setup-alpine@v1 | |
with: | |
branch: v3.17 | |
arch: x86_64 | |
packages: > | |
build-base | |
pkgconf | |
lld | |
go | |
gcc | |
g++ | |
libusb-dev | |
linux-headers | |
shell-name: alpine.sh | |
- name: setup-git-credentials | |
uses: de-vri-es/[email protected] | |
with: | |
credentials: ${{ secrets.PAT_GITHUB_SERVICE_ACCT }} | |
- name: Build zetacored and zetaclientd | |
env: | |
CGO_ENABLED: 1 | |
GOOS: linux | |
GOARCH: ${{ env.CPU_ARCH }} | |
shell: alpine.sh --root {0} | |
run: | | |
apk add --no-cache --update | |
go mod tidy | |
make clean | |
make install-testnet | |
cp "$HOME"/go/bin/* ./ | |
- name: Test | |
shell: alpine.sh --root {0} | |
run: | | |
echo "Running Build Tests" | |
make test | |
- name: Binary Docker Test | |
env: | |
CPU_ARCH: ${{ env.CPU_ARCH }} | |
shell: alpine.sh --root {0} | |
run: | | |
chmod a+x ./zetacored | |
./zetacored version | |
mv zetacored zetacored-alpine-$CPU_ARCH | |
mv zetaclientd zetaclientd-alpine-$CPU_ARCH | |
- name: Save Binaries as Artifacts | |
if: startsWith(github.ref, 'refs/tags/') || startsWith(github.ref, 'refs/heads/develop') | |
uses: actions/upload-artifact@v3 | |
with: | |
name: binaries-${{ github.sha }} | |
path: | | |
zetacored-alpine-* | |
zetaclientd-alpine-* | |
- name: Clean Up Alpine Workspace | |
if: always() | |
shell: alpine.sh --root {0} | |
run: | | |
set -e # fail on error | |
rm -rf * | |
- name: Clean Up Workspace | |
if: always() | |
shell: bash | |
run: rm -rf * | |
smoke-test: | |
runs-on: ["zeta-runners"] | |
#runs-on: ubuntu-latest | |
timeout-minutes: 20 | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set CPU Architecture | |
shell: bash | |
run: | | |
if [ "$(uname -m)" == "aarch64" ]; then | |
echo "CPU_ARCH=arm64" >> $GITHUB_ENV | |
elif [ "$(uname -m)" == "x86_64" ]; then | |
echo "CPU_ARCH=amd64" >> $GITHUB_ENV | |
else | |
echo "Unsupported architecture" >&2 | |
exit 1 | |
fi | |
- name: Install Pipeline Dependencies | |
uses: ./.github/actions/install-dependencies | |
timeout-minutes: 8 | |
with: | |
cpu_architecture: ${{ env.CPU_ARCH }} | |
skip_python: "false" | |
skip_aws_cli: "true" | |
skip_docker_compose: "false" | |
- name: Start Private Network | |
run: | | |
make zetanode | |
cd contrib/localnet/ | |
docker compose up -d zetacore0 zetacore1 zetaclient0 zetaclient1 eth bitcoin | |
- name: Run Smoke Test | |
run: | | |
cd contrib/localnet | |
docker-compose up orchestrator --exit-code-from orchestrator | |
if [ $? -ne 0 ]; then | |
echo "Smoke Test Failed" | |
exit 1 | |
fi | |
- name: Stop Private Network | |
if: always() | |
run: | | |
cd contrib/localnet/ | |
docker compose down | |
- name: Clean Up Workspace | |
if: always() | |
shell: bash | |
run: rm -rf * | |
upload: | |
runs-on: ["zeta-runners"] | |
#runs-on: ubuntu-latest | |
timeout-minutes: 15 | |
if: startsWith(github.ref, 'refs/tags/') || startsWith(github.ref, 'refs/heads/develop') | |
needs: | |
- build-and-test | |
- smoke-test | |
- build-alpine-and-test | |
steps: | |
- uses: actions/checkout@v3 | |
- name: setup-git-credentials | |
uses: de-vri-es/[email protected] | |
with: | |
credentials: ${{ secrets.PAT_GITHUB_SERVICE_ACCT }} | |
- name: Install Pipeline Dependencies | |
uses: ./.github/actions/install-dependencies | |
timeout-minutes: 8 | |
with: | |
cpu_architecture: ${{ env.CPU_ARCH }} | |
skip_python: "true" | |
skip_aws_cli: "false" | |
skip_docker_compose: "true" | |
- name: Get branch name | |
id: branch-name | |
uses: tj-actions/branch-names@v6 | |
- name: Git Hash | |
run: | | |
echo "GIT_HASH=$(git rev-parse --short HEAD)" >> ${GITHUB_ENV} | |
echo "WORKSPACE_DIR=$(pwd)" >> ${GITHUB_ENV} | |
- name: set-branch-name | |
uses: ./.github/actions/set-branch-name | |
with: | |
github_ref: "${{github.ref}}" | |
github_event: "${{ github.event_name }}" | |
github_head_ref: "${{ github.event.pull_request.head.ref }}" | |
github_commit_sha: "${{ env.GIT_HASH }}" | |
current_branch_name: "${{ steps.branch-name.outputs.current_branch }}" | |
- uses: actions/download-artifact@v3 | |
with: | |
name: binaries-${{ github.sha }} | |
path: ./ | |
- name: Configure AWS Credentials | |
uses: aws-actions/configure-aws-credentials@v1 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: ${{ env.AWS_REGION }} | |
- name: upload-files-to-s3 | |
uses: ./.github/actions/upload-to-s3 | |
with: | |
bucket-name: ${{ env.S3_BUCKET_PATH }} | |
release-name: ${{ env.RELEASE_NAME }} | |
git-sha: ${{ github.sha }} | |
files: | | |
zetacored-alpine-amd64 | |
zetaclientd-alpine-amd64 | |
zetacored-ubuntu-22-arm64 | |
zetaclientd-ubuntu-22-arm64 | |
zetacored-ubuntu-22-amd64 | |
zetaclientd-ubuntu-22-amd64 | |
zetacored-ubuntu-20-amd64 | |
zetaclientd-ubuntu-20-amd64 | |
# # Approval will be required closer to mainnet | |
# - name: Require Approval To Create a Release | |
# uses: softprops/action-gh-release@v1 | |
# if: startsWith(github.ref, 'refs/tags/v') | |
# with: | |
# token: ${{ secrets.PAT_GITHUB_SERVICE_ACCT }} | |
# files: | | |
# zetacored-alpine-amd64 | |
# zetaclientd-alpine-amd64 | |
# zetacored-ubuntu-22-arm64 | |
# zetaclientd-ubuntu-22-arm64 | |
# zetacored-ubuntu-22-amd64 | |
# zetaclientd-ubuntu-22-amd64 | |
# zetacored-ubuntu-20-amd64 | |
# zetaclientd-ubuntu-20-amd64 | |
- name: Build, tag, and push docker images | |
uses: ./.github/actions/build-docker-images | |
with: | |
DOCKER_FILENAME: Dockerfile | |
REPOSITORY_NAME: zeta-node | |
IMAGE_TAG: ${{ env.TAG_NAME }} | |
GHCR_USERNAME: ${{ secrets.PAT_GITHUB_SERVICE_ACCT_USERNAME }} | |
GHCR_TOKEN: ${{ secrets.PAT_GITHUB_SERVICE_ACCT }} | |
- name: Create GitHub Release for ZetaCore/ZetaClient | |
uses: softprops/action-gh-release@v1 | |
if: startsWith(github.ref, 'refs/tags/v') | |
with: | |
token: ${{ secrets.PAT_GITHUB_SERVICE_ACCT }} | |
generate_release_notes: true | |
files: | | |
zetacored-alpine-amd64 | |
zetaclientd-alpine-amd64 | |
zetacored-ubuntu-22-arm64 | |
zetaclientd-ubuntu-22-arm64 | |
zetacored-ubuntu-22-amd64 | |
zetaclientd-ubuntu-22-amd64 | |
zetacored-ubuntu-20-amd64 | |
zetaclientd-ubuntu-20-amd64 | |
- name: Clean Up Workspace | |
if: always() | |
shell: bash | |
run: rm -rf * | |
upgrade_path_testing: | |
runs-on: ["buildjet-4vcpu-ubuntu-2204"] | |
timeout-minutes: 60 | |
if: startsWith(github.ref, 'refs/tags/') || startsWith(github.ref, 'refs/heads/release') | |
needs: | |
- build-and-test | |
- build-alpine-and-test | |
- upload | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Major Version in Upgrade Handler Must Match Tag | |
if: startsWith(github.ref, 'refs/tags/v') || startsWith(github.ref, 'refs/heads/release') | |
run: | | |
UPGRADE_HANDLER_MAJOR_VERSION=$(cat app/setup_handlers.go | grep "const releaseVersion" | cut -d ' ' -f4 | tr -d '"' | cut -d '.' -f1) | |
echo $UPGRADE_HANDLER_MAJOR_VERSION | |
GITHUB_TAG_MAJOR_VERSION=$(echo ${{ github.ref_name }} | cut -d '.' -f1) | |
if [ $GITHUB_TAG_MAJOR_VERSION != $UPGRADE_HANDLER_MAJOR_VERSION ]; then | |
echo "ERROR: The major version of this release (${{ github.ref_name }}) does not match the major version in the releaseVersion constant ($UPGRADE_HANDLER_MAJOR_VERSION) found in app/setup_handlers.go" | |
echo "Did you forget to update the 'releaseVersion' in app/setup_handlers.go?" | |
exit 1 | |
fi | |
echo "The major version found in 'releaseVersion' in app/setup_handlers.go matches this tagged release - Moving Forward!" | |
- name: Clean Up Workspace | |
if: always() | |
shell: bash | |
run: rm -rf * | |
upload_s3_public: | |
#runs-on: ubuntu-latest | |
runs-on: ["zeta-runners"] | |
timeout-minutes: 15 | |
if: startsWith(github.ref, 'refs/tags/') | |
needs: | |
- upgrade_path_testing | |
steps: | |
- uses: actions/checkout@v3 | |
- name: setup-git-credentials | |
uses: de-vri-es/[email protected] | |
with: | |
credentials: ${{ secrets.PAT_GITHUB_SERVICE_ACCT }} | |
- name: Install Pipeline Dependencies | |
uses: ./.github/actions/install-dependencies | |
timeout-minutes: 8 | |
with: | |
cpu_architecture: ${{ env.CPU_ARCH }} | |
skip_python: "true" | |
skip_aws_cli: "false" | |
skip_docker_compose: "true" | |
- uses: actions/download-artifact@v3 | |
with: | |
name: binaries-${{ github.sha }} | |
path: ./ | |
- name: Configure AWS Credentials | |
uses: aws-actions/configure-aws-credentials@v1 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: ${{ env.AWS_REGION }} | |
- name: Get Version | |
run: | | |
VERSION=$(cat app/setup_handlers.go | grep "const releaseVersion" | cut -d ' ' -f4 | tr -d '"') | |
echo "BINARY_VERSION=${VERSION}" >> ${GITHUB_ENV} | |
- name: upload-files-to-s3 | |
uses: ./.github/actions/upload-to-s3 | |
with: | |
bucket-name: ${{ env.S3_PUBLIC_BUCKET_PATH }} | |
release-name: "binaries/athens3/${{ env.BINARY_VERSION }}" | |
git-sha: ${{ github.sha }} | |
files: | | |
zetacored-alpine-amd64 | |
zetaclientd-alpine-amd64 | |
zetacored-ubuntu-22-arm64 | |
zetaclientd-ubuntu-22-arm64 | |
zetacored-ubuntu-22-amd64 | |
zetaclientd-ubuntu-22-amd64 | |
zetacored-ubuntu-20-amd64 | |
zetaclientd-ubuntu-20-amd64 | |
- name: Determine Release Type | |
run: | | |
if [[ "${{ env.BINARY_VERSION }}" =~ ^v[0-9]+\.0\.0+$ ]]; then | |
echo "RELEASE_TYPE=major" >> ${GITHUB_ENV} | |
elif [[ "${{ env.BINARY_VERSION }}" =~ ^v[0-9]+\.[0-9]+\.[1-9]+$ ]]; then | |
echo "RELEASE_TYPE=minor" >> ${GITHUB_ENV} | |
else | |
echo "RELEASE_TYPE=unknown" >> ${GITHUB_ENV} | |
fi | |
id: determine_release_type | |
- name: "SEND:DISCORD:MESSAGE" | |
if: steps.determine_release_type.outputs.RELEASE_TYPE == 'major' | |
uses: gzukel/CosmosComposites/send_discord_message@main | |
with: | |
discord_token: "${{ secrets.DISCORD_TOKEN }}" | |
discord_channel_id: "${{ secrets.DISCORD_CHANNEL_ID }}" | |
discord_message: | | |
Hey <@&1122981184255840306>! A new version of the zetachain node has been released. | |
Major Version Upgrade (e.g. v5.x.x to V6.x.x) must be completed through a governance proposal. | |
We will submit a governance proposal in the next few days with a 12-hour voting period. | |
More specific information including block height will be shared as part of the governance proposal. | |
See the release notes for more details. https://github.com/zeta-chain/node/releases/tag/${{ env.BINARY_VERSION }} | |
# - name: "SEND:DISCORD:MESSAGE" | |
# if: steps.determine_release_type.outputs.RELEASE_TYPE == 'minor' | |
# uses: gzukel/CosmosComposites/send_discord_message@main | |
# with: | |
# discord_token: "${{ secrets.DISCORD_TOKEN }}" | |
# discord_channel_id: "${{ secrets.DISCORD_CHANNEL_ID }}" | |
# discord_message: | | |
# Hey <@&1122981184255840306>! A new version of the zetachain node has been released. | |
# Minor Version Upgrade (e.g. v5.0.x to v5.1.x) can be applied without a governance proposal. | |
# Please review the release notes for any specific upgrade instructions or considerations. | |
# See the release notes for more details. https://github.com/zeta-chain/node/releases/tag/${{ env.BINARY_VERSION }} | |
- name: Clean Up Workspace | |
if: always() | |
shell: bash | |
run: rm -rf * |