From 25b95e6697e1cbf034f3873de55a0483058ecf62 Mon Sep 17 00:00:00 2001 From: bussyjd Date: Mon, 3 Feb 2025 20:19:48 +0400 Subject: [PATCH 1/2] feat: add arm releases --- .github/actions/setup-go/action.yml | 11 ++ .github/workflows/build-release-binaries.yml | 102 +++++++++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 .github/workflows/build-release-binaries.yml diff --git a/.github/actions/setup-go/action.yml b/.github/actions/setup-go/action.yml index 9cc2fdd9e..f7b26bbb2 100644 --- a/.github/actions/setup-go/action.yml +++ b/.github/actions/setup-go/action.yml @@ -1,9 +1,20 @@ name: Setup go +outputs: + go-version: + description: "The Go version that was set up" + value: ${{ steps.setup-go.outputs.go-version }} + runs: using: 'composite' steps: - name: Setup go + id: setup-go uses: actions/setup-go@v4 with: go-version: '1.23' + + - name: Verify setup + shell: bash + run: | + echo "Go version: $(go version)" diff --git a/.github/workflows/build-release-binaries.yml b/.github/workflows/build-release-binaries.yml new file mode 100644 index 000000000..8b105dedb --- /dev/null +++ b/.github/workflows/build-release-binaries.yml @@ -0,0 +1,102 @@ +name: Build and Release Binaries + +on: + workflow_run: + workflows: ["Publish Release"] + types: + - completed + +jobs: + build-binaries: + # Only run if the triggering workflow succeeded and it was triggered by a tag + if: > + github.event.workflow_run.conclusion == 'success' && + startsWith(github.event.workflow_run.head_branch, 'refs/tags/v') + runs-on: ubuntu-24.04 + name: Build Cross-Platform Binaries + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - uses: ./.github/actions/setup-go + id: setup-go + + - name: Get app/version.Version from the code + if: github.ref_type == 'branch' + run: | + VERSION=$(grep 'var version' app/version/version.go | cut -d'"' -f2) + echo "APP_VERSION=$VERSION" >> $GITHUB_ENV + echo "RELEASE_VERSION=$VERSION" >> $GITHUB_ENV + + - name: Set version from git tag + if: github.ref_type == 'tag' + run: | + echo "APP_VERSION=${{ github.ref_name }}" >> $GITHUB_ENV + echo "RELEASE_VERSION=${{ github.ref_name }}" >> $GITHUB_ENV + echo "GO_BUILD_FLAG=-ldflags=-X github.com/obolnetwork/charon/app/version.version=${{ github.ref_name }}" >> $GITHUB_ENV + + - name: Set build flags for branch + if: github.ref_type == 'branch' + run: | + echo "GO_BUILD_FLAG=-ldflags=-X github.com/obolnetwork/charon/app/version.version=${{ env.APP_VERSION }}" >> $GITHUB_ENV + + - name: Install cross-compilation dependencies + run: | + sudo apt-get update + sudo apt-get install -y build-essential gcc-aarch64-linux-gnu + + - name: Build x86_64 binary + run: | + mkdir -p dist + docker run --rm --platform linux/amd64 \ + -v $(pwd):/workspace -w /workspace \ + golang:${{ steps.setup-go.outputs.go-version }}-bookworm \ + bash -c "apt-get update && apt-get install -y build-essential && \ + env CGO_ENABLED=1 GOOS=linux GOARCH=amd64 \ + go build -tags='netgo osusergo' ${{ env.GO_BUILD_FLAG }} \ + -o dist/charon-${{ env.RELEASE_VERSION }}-linux-amd64" + + - name: Build ARM64 binary + run: | + docker run --rm --platform linux/amd64 \ + -v $(pwd):/workspace -w /workspace \ + golang:${{ steps.setup-go.outputs.go-version }}-bookworm \ + bash -c "apt-get update && apt-get install -y gcc-aarch64-linux-gnu && \ + env CGO_ENABLED=1 GOOS=linux GOARCH=arm64 CC=aarch64-linux-gnu-gcc \ + go build -tags='netgo osusergo' ${{ env.GO_BUILD_FLAG }} \ + -o dist/charon-${{ env.RELEASE_VERSION }}-linux-arm64" + + - name: Create release archives + run: | + cd dist + tar czf charon-${{ env.RELEASE_VERSION }}-linux-amd64.tar.gz charon-${{ env.RELEASE_VERSION }}-linux-amd64 + tar czf charon-${{ env.RELEASE_VERSION }}-linux-arm64.tar.gz charon-${{ env.RELEASE_VERSION }}-linux-arm64 + echo "# Linux AMD64 (x86_64)" > checksums.txt + sha256sum charon-${{ env.RELEASE_VERSION }}-linux-amd64.tar.gz >> checksums.txt + echo -e "\n# Linux ARM64 (aarch64)" >> checksums.txt + sha256sum charon-${{ env.RELEASE_VERSION }}-linux-arm64.tar.gz >> checksums.txt + + - name: Upload artifacts + uses: actions/upload-artifact@v3 + with: + name: charon-${{ env.RELEASE_VERSION }}-binaries + path: | + dist/charon-${{ env.RELEASE_VERSION }}-linux-amd64 + dist/charon-${{ env.RELEASE_VERSION }}-linux-arm64 + dist/charon-${{ env.RELEASE_VERSION }}-linux-amd64.tar.gz + dist/charon-${{ env.RELEASE_VERSION }}-linux-arm64.tar.gz + dist/checksums.txt + + - name: Attach to GitHub Release + if: github.event.workflow_run.conclusion == 'success' + uses: softprops/action-gh-release@v1 + with: + files: | + dist/charon-${{ env.RELEASE_VERSION }}-linux-amd64.tar.gz + dist/charon-${{ env.RELEASE_VERSION }}-linux-arm64.tar.gz + dist/checksums.txt + draft: true + tag_name: ${{ github.event.workflow_run.head_branch }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 0bb9beb784cddcb1d7c62824d6104d5c643636e1 Mon Sep 17 00:00:00 2001 From: bussyjd Date: Tue, 4 Feb 2025 19:07:19 +0400 Subject: [PATCH 2/2] feat: add arm releases --- .github/actions/setup-go/action.yml | 2 +- .github/workflows/build-release-binaries.yml | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/actions/setup-go/action.yml b/.github/actions/setup-go/action.yml index f7b26bbb2..ae15aba69 100644 --- a/.github/actions/setup-go/action.yml +++ b/.github/actions/setup-go/action.yml @@ -10,7 +10,7 @@ runs: steps: - name: Setup go id: setup-go - uses: actions/setup-go@v4 + uses: actions/setup-go@v5 with: go-version: '1.23' diff --git a/.github/workflows/build-release-binaries.yml b/.github/workflows/build-release-binaries.yml index 8b105dedb..7b54f342f 100644 --- a/.github/workflows/build-release-binaries.yml +++ b/.github/workflows/build-release-binaries.yml @@ -15,7 +15,7 @@ jobs: runs-on: ubuntu-24.04 name: Build Cross-Platform Binaries steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 0 @@ -78,7 +78,7 @@ jobs: sha256sum charon-${{ env.RELEASE_VERSION }}-linux-arm64.tar.gz >> checksums.txt - name: Upload artifacts - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: charon-${{ env.RELEASE_VERSION }}-binaries path: | @@ -90,7 +90,7 @@ jobs: - name: Attach to GitHub Release if: github.event.workflow_run.conclusion == 'success' - uses: softprops/action-gh-release@v1 + uses: softprops/action-gh-release@v2 with: files: | dist/charon-${{ env.RELEASE_VERSION }}-linux-amd64.tar.gz