Skip to content

Commit

Permalink
fix(ci): Binaries creation in release workflow (#150)
Browse files Browse the repository at this point in the history
* fix: update version on sedge

* feat: add instructions for docker buildx

* fix: fix build using buildx

* feat: add workflow for macos on release pipeline

* fix: remove darwin upload from github

* fix: delete unused workflow

* fix: rename github action

* ci: Add script to generate darwin binaries

* ci: Rename script that builds the linux binaries and move Dockerfile

* ci: Rename ci.yml workflow to build.yml

* fix(ci): Dependencies between jobs in release workflow

* ci: Install docker buildx in release workflow

* fix: update load path for docker buildx

* fix: create build folder if doesn't exist

Co-authored-by: AntiD2ta <[email protected]>
Co-authored-by: Miguel Tenorio <[email protected]>
  • Loading branch information
3 people authored Oct 26, 2022
1 parent 7d5dbea commit 22df40a
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 132 deletions.
88 changes: 27 additions & 61 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,72 +1,38 @@
name: 'Release Sedge'
name: sedge CI

on:
workflow_dispatch:
inputs:
tag:
description: 'The version number (e.g: 0.1.2) of the release you want to push'
required: true
default: 'master'

permissions:
contents: write
packages: write
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]

jobs:
build-sedge:
build:
name: Build sedge
runs-on: ubuntu-latest
env:
VERSION: v${{ github.event.inputs.tag }}

steps:
- name: Checkout
uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: '1.18.3'
- run: chmod +x ./scripts/build-go-binaries.sh && ./scripts/build-go-binaries.sh
- uses: actions/upload-artifact@master
name: Uploading sedge darwin amd64 package
with:
name: sedge-${{env.VERSION}}-darwin-amd64
path: build/sedge-${{env.VERSION}}-darwin-amd64
uses: actions/checkout@v2

- uses: actions/upload-artifact@master
name: Uploading sedge darwin arm64 package
- name: Setup Go
uses: actions/setup-go@v2
with:
name: sedge-${{env.VERSION}}-darwin-arm64
path: build/sedge-${{env.VERSION}}-darwin-arm64
go-version: '1.18.2'

- uses: actions/upload-artifact@master
name: Uploading sedge linux amd64 package
with:
name: sedge-${{env.VERSION}}-linux-amd64
path: build/sedge-${{env.VERSION}}-linux-amd64

- uses: actions/upload-artifact@master
name: Uploading sedge linux arm64 package
with:
name: sedge-${{env.VERSION}}-linux-arm64
path: build/sedge-${{env.VERSION}}-linux-arm64
- name: Check Format
run: make format-check

publish-github:
name: "Release and upload binaries to github"
runs-on: ubuntu-latest
env:
VERSION: v${{ github.event.inputs.tag }}
needs: build-sedge
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Download packages
uses: actions/download-artifact@v3
with:
path: /tmp/binaries
- name: Upload release to Github Releases
uses: ncipollo/release-action@v1
with:
artifacts: "/tmp/binaries/sedge-v*/*"
bodyFile: "CHANGELOG.md"
draft: true
tag: v${{ github.event.inputs.tag }}
name: v${{ github.event.inputs.tag }}
- name: Check go mod status
run: |
make gomod_tidy
if [[ ! -z $(git status -s) ]]
then
echo "Go mod - state is not clean:"
git status -s
git diff "$GITHUB_SHA"
exit 1
fi
- name: Check build
run: make compile
38 changes: 0 additions & 38 deletions .github/workflows/ci.yml

This file was deleted.

87 changes: 59 additions & 28 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,81 +1,110 @@
name: 'Release Sedge'

on:
on:
workflow_dispatch:
inputs:
tag:
description: 'The version number (e.g: 0.1.2) of the release you want to push'
required: true
default: 'master'

permissions:
permissions:
contents: write
packages: write

jobs:
build-sedge:
name: Build sedge
runs-on: ubuntu-latest
env:
VERSION: v${{ github.event.inputs.tag }}
sedge-darwin:
name: Build sedge darwin
runs-on: macos-latest
env:
VERSION: ${{ github.event.inputs.tag }}
steps:
- name: Checkout
uses: actions/checkout@v3

- uses: actions/setup-go@v3
with:
go-version: '1.18.3'
- run: chmod +x ./scripts/build-go-binaries.sh && ./scripts/build-go-binaries.sh

- run: chmod +x ./scripts/build-go-darwin-binaries.sh && ./scripts/build-go-darwin-binaries.sh

- uses: actions/upload-artifact@master
name: Uploading sedge darwin amd64 package
with:
name: sedge-${{env.VERSION}}-darwin-amd64
path: build/sedge-${{env.VERSION}}-darwin-amd64
name: sedge-v${{env.VERSION}}-darwin-amd64
path: build/sedge-v${{env.VERSION}}-darwin-amd64

- uses: actions/upload-artifact@master
name: Uploading sedge darwin arm64 package
with:
name: sedge-${{env.VERSION}}-darwin-arm64
path: build/sedge-${{env.VERSION}}-darwin-arm64
name: sedge-v${{env.VERSION}}-darwin-arm64
path: build/sedge-v${{env.VERSION}}-darwin-arm64

sedge-linux:
name: Build sedge linux
runs-on: ubuntu-latest
env:
VERSION: ${{ github.event.inputs.tag }}
needs: sedge-darwin
steps:
- name: Checkout
uses: actions/checkout@v3

- uses: actions/setup-go@v3
with:
go-version: '1.18.3'

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

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

- run: chmod +x ./scripts/build-go-linux-binaries.sh && ./scripts/build-go-linux-binaries.sh

- uses: actions/upload-artifact@master
name: Uploading sedge linux amd64 package
with:
name: sedge-${{env.VERSION}}-linux-amd64
path: build/sedge-${{env.VERSION}}-linux-amd64
name: sedge-v${{env.VERSION}}-linux-amd64
path: build/sedge-v${{env.VERSION}}-linux-amd64

- uses: actions/upload-artifact@master
name: Uploading sedge linux arm64 package
with:
name: sedge-${{env.VERSION}}-linux-arm64
path: build/sedge-${{env.VERSION}}-linux-arm64
name: sedge-v${{env.VERSION}}-linux-arm64
path: build/sedge-v${{env.VERSION}}-linux-arm64

update-homebrew:
name: Update Homebrew package
runs-on: ubuntu-latest
env:
VERSION: v${{ github.event.inputs.tag }}
needs: build-sedge
env:
VERSION: ${{ github.event.inputs.tag }}
needs: sedge-linux
steps:
- name: Download packages
uses: actions/download-artifact@v3
with:
with:
path: /tmp/binaries

- name: Checkout repository
uses: actions/checkout@master
with:
with:
repository: NethermindEth/homebrew-sedge
path: homebrew-sedge

- name: Update Homebrew file with new version and hash
run: |
chmod +x /home/runner/work/sedge/sedge/homebrew-sedge/scripts/update-homebrew.sh
bash /home/runner/work/sedge/sedge/homebrew-sedge/scripts/update-homebrew.sh
- name: Create Pull Request
uses: peter-evans/create-pull-request@v4
with:
token: ${{ secrets.REPOSITORY_DISPATCH_TOKEN }}
commit-message: Update Homebrew to latest release
title: '[Release] Update Homebrew'
reviewers: falcoxyz, AntiD2ta, cbermudez97, stdevMac
reviewers: falcoxyz, AntiD2ta, cbermudez97
draft: false
path: homebrew-sedge
add-paths: |
Expand All @@ -84,21 +113,23 @@ jobs:
publish-github:
name: "Release and upload binaries to github"
runs-on: ubuntu-latest
env:
VERSION: v${{ github.event.inputs.tag }}
env:
VERSION: ${{ github.event.inputs.tag }}
needs: update-homebrew
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Download packages
uses: actions/download-artifact@v3
with:
with:
path: /tmp/binaries

- name: Upload release to Github Releases
uses: ncipollo/release-action@v1
with:
artifacts: "/tmp/binaries/sedge-v*/*"
bodyFile: "CHANGELOG.md"
draft: true
tag: v${{ github.event.inputs.tag }}
name: v${{ github.event.inputs.tag }}
tag: ${{ github.event.inputs.tag }}
name: ${{ github.event.inputs.tag }}
18 changes: 18 additions & 0 deletions scripts/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM --platform=$BUILDPLATFORM golang:1.18.3 AS build
WORKDIR /src
ARG TARGETOS
ARG TARGETARCH
ARG LDFLAGS
ARG OUTPUT_NAME
ARG PACKAGE
COPY . ./
RUN go mod download
RUN if [ "$TARGETARCH" = "arm64" ] ; \
then apt update && apt install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu -y && \
CC=aarch64-linux-gnu-gcc CGO_ENABLED=1 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -ldflags "${LDFLAGS}" -o /src/sedge $PACKAGE ; \
else \
CGO_ENABLED=1 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -ldflags "${LDFLAGS}" -o /src/sedge $PACKAGE; \
fi

FROM golang:1.18.3
COPY --from=build /src/sedge /sedge
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@
package=cmd/sedge/main.go
package_name=sedge

platforms=("linux/amd64" "linux/arm64" "darwin/amd64" "darwin/arm64")
platforms=("darwin/amd64" "darwin/arm64")

for platform in "${platforms[@]}"
do
platform_split=(${platform//\// })
GOOS=${platform_split[0]}
GOARCH=${platform_split[1]}
SEDGE_VERSION=$(git tag | sort | tail -n 1)
output_name=$package_name'-'$SEDGE_VERSION'-'$GOOS'-'$GOARCH
output_name=$package_name'-v'$VERSION'-'$GOOS'-'$GOARCH

LDFLAGS="-X github.com/NethermindEth/sedge/internal/utils.Version=${SEDGE_VERSION}"
LDFLAGS="-X github.com/NethermindEth/sedge/internal/utils.Version=v${VERSION}"

env GOOS=$GOOS GOARCH=$GOARCH go build -ldflags "${LDFLAGS}" -o build/"$output_name" $package
env CGO_ENABLED=1 GOOS=$GOOS GOARCH=$GOARCH go build -ldflags "${LDFLAGS}" -o build/"$output_name" $package
if [ $? -ne 0 ]; then
echo 'An error has occurred! Aborting the script execution...'
exit 1
Expand Down
29 changes: 29 additions & 0 deletions scripts/build-go-linux-binaries.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash
set -x
package=cmd/sedge/main.go
package_name=sedge

mkdir -p build

platforms=("linux/amd64" "linux/arm64")

for platform in "${platforms[@]}"
do
platform_split=(${platform//\// })
GOOS=${platform_split[0]}
GOARCH=${platform_split[1]}
output_name=$package_name'-v'$VERSION'-'$GOOS'-'$GOARCH

LDFLAGS="-X github.com/NethermindEth/sedge/internal/utils.Version=v${VERSION}"

docker buildx build --platform="$GOOS"/"$GOARCH" -t nethermindeth/sedge:"$VERSION"-"$GOOS"-"$GOARCH" --build-arg TARGETOS="$GOOS" --build-arg TARGETARCH="$GOARCH" --build-arg LDFLAGS="$LDFLAGS" --build-arg OUTPUT_NAME="$output_name" --build-arg PACKAGE="$package" --load . -f scripts/Dockerfile
docker create --name sedge nethermindeth/sedge:"$VERSION"-"$GOOS"-"$GOARCH"
docker cp sedge:/sedge ./build/"$output_name"
docker rm -f sedge

if [ $? -ne 0 ]; then
echo 'An error has occurred! Aborting the script execution...'
exit 1
fi
echo "Generated ${output_name} file"
done

0 comments on commit 22df40a

Please sign in to comment.