diff --git a/.github/workflows/release-build.yml b/.github/workflows/release-build.yml index 3e2a669d..8832f6d6 100644 --- a/.github/workflows/release-build.yml +++ b/.github/workflows/release-build.yml @@ -7,96 +7,252 @@ on: - "v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+" jobs: - build: + create_tarball: + name: "Create Tarball" + runs-on: self-hosted + steps: + - name: "Set tag as version" + run: echo "VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV # set env.VERSION=v0.0.0 + - name: "Checkout code" + uses: actions/checkout@v3.1.0 + - name: "Create compressed repository source" + run: | + git archive --format=tar --prefix "lbm-${{ env.VERSION }}/" HEAD | gzip -9n > lbm-${{ env.VERSION }}.tgz + md5sum lbm-${{ env.VERSION }}.tgz > lbm-${{ env.VERSION }}.tgz.md5 + sha256sum lbm-${{ env.VERSION }}.tgz > lbm-${{ env.VERSION }}.tgz.sha256 + - name: "Store compressed source" + uses: actions/upload-artifact@v3 + with: + name: release-${{ env.VERSION }} + path: | + lbm-${{ env.VERSION }}.tgz + lbm-${{ env.VERSION }}.tgz.md5 + lbm-${{ env.VERSION }}.tgz.sha256 + + build_for_linux: + name: "Release Build for Linux" + needs: create_tarball + runs-on: ubuntu-latest + strategy: + matrix: + arch: [ amd64, arm64 ] + include: + - arch: amd64 + cc: x86_64-linux-gnu-gcc + cxx: x86_64-linux-gnu-g++ + libwasmvm: libwasmvm.x86_64.so + test: 1 + - arch: arm64 + cc: aarch64-linux-gnu-gcc + cxx: aarch64-linux-gnu-g++ + libwasmvm: libwasmvm.aarch64.so + test: 0 + steps: + - name: "Set tag as version" + run: echo "VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV # set env.VERSION=v0.0.0 + - name: "Update runtime" + run: | + sudo apt update + sudo apt upgrade -y + sudo apt install -y build-essential g++-x86-64-linux-gnu g++-aarch64-linux-gnu wget + - name: "Install go" + uses: actions/setup-go@v3 + with: + go-version: '1.18' + check-latest: true + - name: "Print go environment for debugging" + run: go env + - name: "Download compressed repository source" + uses: actions/download-artifact@v3 + with: + name: release-${{ env.VERSION }} + - name: "Extract compressed repository source" + run: tar zxf lbm-${{ env.VERSION }}.tgz --strip-components=1 + + - name: "Set ID=${{ env.VERSION }}-linux-${{ matrix.arch }}" + run: echo "ID=${{ env.VERSION }}-linux-${{ matrix.arch }}" >> $GITHUB_ENV + - name: "Build artifact: linux-${{ matrix.arch }}" + run: | + make clean build GOARCH=${{ matrix.arch }} CC=${{ matrix.cc }} CXX=${{ matrix.cxx }} + - name: "Archive artifact: linux-${{ matrix.arch }}" + run: | + mkdir -p ./artifacts/lbm-${{ env.ID }} + mv ./build/lbm ./artifacts/lbm-${{ env.ID }}/lbm-${{ env.ID }} + cd ./artifacts + LIBWASMVM=`find ~ -name ${{ matrix.libwasmvm }} -type f` + if [ ! -f "$LIBWASMVM" ]; then echo "ERROR: ${{ matrix.libwasmvm }} not found: $LIBWASMVM"; exit 1; fi + cp "$LIBWASMVM" ./lbm-${{ env.ID }}/${{ matrix.libwasmvm }} + ls -laF ./lbm-${{ env.ID }} + echo "MD5: `md5sum ./lbm-${{ env.ID }}/lbm-${{ env.ID }}`" + if [ ${{ matrix.test }} -eq 1 ]; then echo "Binary launch version: `LD_LIBRARY_PATH=./lbm-${{ env.ID }} ./lbm-${{ env.ID }}/lbm-${{ env.ID }} version`" 2>&1; fi + tar zcvf ./lbm-${{ env.ID }}.tgz lbm-${{ env.ID }}/ + md5sum lbm-${{ env.ID }}.tgz > ./lbm-${{ env.ID }}.md5 + sha256sum lbm-${{ env.ID }}.tgz > ./lbm-${{ env.ID }}.sha256 + - name: "Store artifact: linux-${{ matrix.arch }}" + uses: actions/upload-artifact@v3 + with: + name: release-${{ env.VERSION }} + path: | + ./artifacts/lbm-${{ env.ID }}.tgz + ./artifacts/lbm-${{ env.ID }}.md5 + ./artifacts/lbm-${{ env.ID }}.sha256 + + # build_for_darwin: + # name: "Release Build for macOS" + # needs: create_tarball + # runs-on: macOS-latest + # strategy: + # matrix: + # arch: [ "amd64", "arm64" ] + # include: + # - arch: amd64 + # libwasmvm: libwasmvm.dylib + # test: 1 + # - arch: arm64 + # libwasmvm: libwasmvm.dylib + # test: 0 + # steps: + # - name: "Set tag as version" + # run: echo "VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV # set env.VERSION=v0.0.0 + # - name: "Setup Xcode" + # run: sudo xcode-select --switch /Applications/Xcode.app + # - name: "Install md5sum" + # run: | + # brew update + # brew install md5sha1sum + # - name: "Install go" + # uses: actions/setup-go@v3 + # with: + # go-version: '1.18' + # check-latest: true + # - name: "Print go environment" + # run: go env + # - name: "Download compressed repository source" + # uses: actions/download-artifact@v3 + # with: + # name: release-${{ env.VERSION }} + # - name: "Extract compressed repository source" + # run: tar zxf lbm-${{ env.VERSION }}.tgz --strip-components=1 + # + # - name: "Set ID=${{ env.VERSION }}-darwin-${{ matrix.arch }}" + # run: echo "ID=${{ env.VERSION }}-darwin-${{ matrix.arch }}" >> $GITHUB_ENV + # - name: "Build artifact: darwin-${{ matrix.arch }}" + # run: | + # make clean build GOARCH=${{ matrix.arch }} + # - name: "Archive artifact: darwin-${{ matrix.arch }}" + # run: | + # mkdir -p ./artifacts/lbm-${{ env.ID }} + # mv ./build/lbm ./artifacts/lbm-${{ env.ID }}/lbm-${{ env.ID }} + # cd ./artifacts + # LIBWASMVM=`find ~ -name ${{ matrix.libwasmvm }} -type f` + # if [ ! -f "$LIBWASMVM" ]; then echo "ERROR: ${{ matrix.libwasmvm }} not found: $LIBWASMVM"; exit 1; fi + # cp "$LIBWASMVM" ./lbm-${{ env.ID }}/${{ matrix.libwasmvm }} + # ls -laF ./lbm-${{ env.ID }} + # echo "MD5: `md5sum ./lbm-${{ env.ID }}/lbm-${{ env.ID }}`" + # if [ ${{ matrix.test }} -eq 1 ]; then echo "Binary launch version: `LD_LIBRARY_PATH=./lbm-${{ env.ID }} ./lbm-${{ env.ID }}/lbm-${{ env.ID }} version`" 2>&1; fi + # tar zcvf ./lbm-${{ env.ID }}.tgz lbm-${{ env.ID }}/ + # md5sum lbm-${{ env.ID }}.tgz > ./lbm-${{ env.ID }}.md5 + # shasum -a 256 lbm-${{ env.ID }}.tgz > ./lbm-${{ env.ID }}.sha256 + # - name: "Store artifact: darwin-${{ matrix.arch }}" + # uses: actions/upload-artifact@v3 + # with: + # name: release-${{ env.VERSION }} + # path: | + # ./artifacts/lbm-${{ env.ID }}.tgz + # ./artifacts/lbm-${{ env.ID }}.md5 + # ./artifacts/lbm-${{ env.ID }}.sha256 + + create_release: name: "Create Release" + needs: [ build_for_linux ] + # needs: [ build_for_linux, build_for_darwin ] runs-on: ubuntu-latest steps: - - name: "Checkout code" - uses: actions/checkout@v3.1.0 - - name: set tag env - run: echo "VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV - - name: install go - uses: actions/setup-go@v3 - with: - go-version: '1.18' - check-latest: true - - name: "Build lbm/build-artifacts Docker image" - run: cd builders/build-artifacts && docker build -t lbm/build-artifacts . - - name: "Build artifacts" - run: make distclean build-reproducible - - name: "Generate release note" - run: cat ./RELEASE_NOTE.md <(echo) <(echo '```') ./artifacts/build_report <(echo '```') > ./releasenote - - name: "Create release" - id: create_release - uses: actions/create-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - tag_name: ${{ github.ref }} - release_name: Release ${{ github.ref }} - body_path: ./releasenote - draft: true - prerelease: false - - name: "Upload build_report" - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ github.token }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./artifacts/build_report - asset_name: build_report - asset_content_type: application/file -# - name: "Upload darwin-amd64 artifact" -# uses: actions/upload-release-asset@v1 -# env: -# GITHUB_TOKEN: ${{ github.token }} -# with: -# upload_url: ${{ steps.create_release.outputs.upload_url }} -# asset_path: ./artifacts/lbm-${{ env.VERSION }}-darwin-amd64 -# asset_name: lbm-${{ env.VERSION }}-darwin-amd64 -# asset_content_type: application/binary -# - name: "Upload darwin-arm64 artifact" -# uses: actions/upload-release-asset@v1 -# env: -# GITHUB_TOKEN: ${{ github.token }} -# with: -# upload_url: ${{ steps.create_release.outputs.upload_url }} -# asset_path: ./artifacts/lbm-${{ env.VERSION }}-darwin-arm64 -# asset_name: lbm-${{ env.VERSION }}-darwin-arm64 -# asset_content_type: application/binary - - name: "Upload linux-amd64 artifact" - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ github.token }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./artifacts/lbm-${{ env.VERSION }}-linux-amd64 - asset_name: lbm-${{ env.VERSION }}-linux-amd64 - asset_content_type: application/binary -# - name: "Upload linux-arm64 artifact" -# uses: actions/upload-release-asset@v1 -# env: -# GITHUB_TOKEN: ${{ github.token }} -# with: -# upload_url: ${{ steps.create_release.outputs.upload_url }} -# asset_path: ./artifacts/lbm-${{ env.VERSION }}-linux-arm64 -# asset_name: lbm-${{ env.VERSION }}-linux-arm64 -# asset_content_type: application/binary -# - name: "Upload windows-amd64 artifact" -# uses: actions/upload-release-asset@v1 -# env: -# GITHUB_TOKEN: ${{ github.token }} -# with: -# upload_url: ${{ steps.create_release.outputs.upload_url }} -# asset_path: ./artifacts/lbm-${{ env.VERSION }}-windows-amd64.exe -# asset_name: lbm-${{ env.VERSION }}-windows-amd64.exe -# asset_content_type: application/binary - - name: "Upload compressed repository" - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ github.token }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./artifacts/lbm-${{ env.VERSION }}.tgz - asset_name: lbm-${{ env.VERSION }}.tgz - asset_content_type: application/gzip + - name: "Set tag as version" + run: echo "VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV # set env.VERSION=v0.0.0 + + - name: "Download artifacts" + uses: actions/download-artifact@v3 + with: + name: release-${{ env.VERSION }} + - name: "Extract compressed repository source" + run: tar zxf lbm-${{ env.VERSION }}.tgz --strip-components=1 lbm-${{ env.VERSION }}/RELEASE_NOTE.md + - name: "List artifact files for debugging" + run: "ls -laF" + - name: "Create build report" + run: | + echo "App: lbm" > build_report.txt + echo "Version: ${{ env.VERSION }}" >> build_report.txt + echo "Commit: ${{ github.sha }}" >> build_report.txt + echo "Checksums MD5:" >> build_report.txt + echo " `cat lbm-${{ env.VERSION }}-linux-amd64.md5`" >> build_report.txt + echo " `cat lbm-${{ env.VERSION }}-linux-arm64.md5`" >> build_report.txt + echo " `cat lbm-${{ env.VERSION }}.tgz.md5`" >> build_report.txt + echo "Checksums SHA256:" >> build_report.txt + echo " `cat lbm-${{ env.VERSION }}-linux-amd64.sha256`" >> build_report.txt + echo " `cat lbm-${{ env.VERSION }}-linux-arm64.sha256`" >> build_report.txt + echo " `cat lbm-${{ env.VERSION }}.tgz.sha256`" >> build_report.txt + - name: "Create release note" + run: | + cat ./RELEASE_NOTE.md > release_note.txt + echo '' >> release_note.txt + echo '```text' >> release_note.txt + cat ./build_report.txt >> release_note.txt + echo '```' >> build_report.txt + - name: "Create release" + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref }} + release_name: Release ${{ github.ref }} + body_path: ./release_note.txt + draft: true + prerelease: false + + - name: "Upload artifact: lbm-${{ env.VERSION }}-linux-amd64" + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ github.token }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: lbm-${{ env.VERSION }}-linux-amd64.tgz + asset_name: lbm-${{ env.VERSION }}-linux-amd64.tgz + asset_content_type: application/octet-stream + - name: "Upload artifact: lbm-${{ env.VERSION }}-linux-arm64" + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ github.token }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: lbm-${{ env.VERSION }}-linux-arm64.tgz + asset_name: lbm-${{ env.VERSION }}-linux-arm64.tgz + asset_content_type: application/octet-stream + # - name: "Upload artifact: lbm-${{ env.VERSION }}-dawrin-amd64" + # uses: actions/upload-release-asset@v1 + # env: + # GITHUB_TOKEN: ${{ github.token }} + # with: + # upload_url: ${{ steps.create_release.outputs.upload_url }} + # asset_path: lbm-${{ env.VERSION }}-darwin-amd64.tgz + # asset_name: lbm-${{ env.VERSION }}-darwin-amd64.tgz + # asset_content_type: application/octet-stream + # - name: "Upload artifact: lbm-${{ env.VERSION }}-dawrin-arm64" + # uses: actions/upload-release-asset@v1 + # env: + # GITHUB_TOKEN: ${{ github.token }} + # with: + # upload_url: ${{ steps.create_release.outputs.upload_url }} + # asset_path: lbm-${{ env.VERSION }}-darwin-arm64.tgz + # asset_name: lbm-${{ env.VERSION }}-darwin-arm64.tgz + # asset_content_type: application/octet-stream + - name: "Upload artifact: compressed repository source" + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ github.token }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: lbm-${{ env.VERSION }}.tgz + asset_name: lbm-${{ env.VERSION }}.tgz + asset_content_type: application/gzip diff --git a/.release-build.sh b/.release-build.sh deleted file mode 100755 index a3517614..00000000 --- a/.release-build.sh +++ /dev/null @@ -1,96 +0,0 @@ -#!/bin/bash - -# NOTE: This script is used by lbm/build-artifact Docker container to build release binaries for the platforms listed -# in TARGET_PLATFORMS. If you want to build locally, please run `make distclean build-reproducible` instead of using -# this directly. - -set -ue - -# Expect the following envvars to be set: -# - APP -# - VERSION -# - COMMIT -# - TARGET_PLATFORMS -# - LEDGER_ENABLED -# - DEBUG - -BASEDIR="$(mktemp -d)" -BASENAME="${APP}-${VERSION}" - -OUTDIR="${HOME}/artifacts" -rm -rfv ${OUTDIR}/ -mkdir -p ${OUTDIR}/ - -FILE_EXT="" -if [ $(go env GOOS) = windows ] -then - FILE_EXT=".exe" -fi - -# Prepare a taball for release. -TARBALL="${BASEDIR}/${BASENAME}.tgz" -git archive --format=tar --prefix "${BASENAME}/" HEAD | gzip -9n > "${TARBALL}" - -# Setup a directory to build from the taball. -BUILDDIR="${BASEDIR}/build" -mkdir -p ${BUILDDIR} -cd ${BUILDDIR} -tar zxf "${TARBALL}" --strip-components=1 -go mod download - -# Add the tarball to artifacts -mv "${TARBALL}" "${OUTDIR}" - -setup_env(){ - local PLATFORM="$1" - _GOOS="$(go env GOOS)" - _GOARCH="$(go env GOARCH)" - # slash-separated identifiers such as linux/amd64 - go env -w GOOS="${PLATFORM%%/*}" - go env -w GOARCH="${PLATFORM##*/}" -} - -restore_env() { - go env -w GOOS="${_GOOS}" - go env -w GOARCH="${_GOARCH}" - unset _GOOS - unset _GOARCH -} - -# Build for each os-architecture pair -for platform in ${TARGET_PLATFORMS} ; do - # This function sets GOOS, GOARCH, and FILE_EXT environment variables - # according to the build target platform. FILE_EXT is empty in all - # cases except when the target platform is 'windows'. - setup_env "${platform}" - - make clean - echo Building for $(go env GOOS)/$(go env GOARCH) >&2 - GOROOT_FINAL="$(go env GOROOT)" \ - make build \ - LDFLAGS=-buildid=${VERSION} \ - VERSION=${VERSION} \ - COMMIT=${COMMIT} \ - LEDGER_ENABLED=${LEDGER_ENABLED} - mv ./build/${APP}${FILE_EXT} ${OUTDIR}/${BASENAME}-$(go env GOOS)-$(go env GOARCH)${FILE_EXT} - - # This function restore the build environment variables to their - # original state. - restore_env -done - -# Generate and display build report. -REPORT_FILE="$(mktemp)" -pushd "${OUTDIR}" -cat > "${REPORT_FILE}" <> "${REPORT_FILE}" -md5sum * | sed 's/^/ /' >> "${REPORT_FILE}" -echo 'Checksums-Sha256:' >> "${REPORT_FILE}" -sha256sum * | sed 's/^/ /' >> "${REPORT_FILE}" -popd -mv "${REPORT_FILE}" "${OUTDIR}/build_report" -cat "${OUTDIR}/build_report" diff --git a/CHANGELOG.md b/CHANGELOG.md index c6619b16..613fb5c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Features * (build) [\#126](https://github.com/line/lbm/pull/126) Automatically generates release note and binaries * (x/wasmd) [\#355](https://github.com/line/lbm/pull/355) chore: apply detached x/wasmd +* (build) [\#130](https://github.com/line/lbm/pull/130) Add a release build for the linux/arm64, darwin/amd64, and darwin/arm64 platform ### Improvements diff --git a/Makefile b/Makefile index 65678eea..6fae2c77 100644 --- a/Makefile +++ b/Makefile @@ -89,7 +89,6 @@ ifeq (libsodium,$(findstring libsodium,$(LBM_BUILD_OPTIONS))) CGO_LDFLAGS += "-L$(LIBSODIUM_OS)/lib -lsodium" endif - # secp256k1 implementation selection ifeq (libsecp256k1,$(findstring libsecp256k1,$(LBM_BUILD_OPTIONS))) CGO_ENABLED=1 @@ -197,21 +196,6 @@ else dbbackend: endif -build-reproducible: go.sum - $(DOCKER) rm lbm-build-artifacts || true > /dev/null 2>&1 - # to be implemented for: 'darwin/amd64 linux/arm64 windows/amd64' - $(DOCKER) run --volume=$(CURDIR):/lbm:ro \ - --env TARGET_PLATFORMS='linux/amd64' \ - --env APP=lbm \ - --env VERSION=$(VERSION) \ - --env COMMIT=$(COMMIT) \ - --env LEDGER_ENABLED=$(LEDGER_ENABLED) \ - --name lbm-build-artifacts \ - lbm/build-artifacts:latest \ - .release-build.sh - $(DOCKER) cp -a lbm-build-artifacts:/home/lbm/artifacts/ $(CURDIR)/ - $(DOCKER) rm lbm-build-artifacts - build-docker: docker build --build-arg LBM_BUILD_OPTIONS="$(LBM_BUILD_OPTIONS)" -t line/lbm . diff --git a/RELEASE_NOTE.md b/RELEASE_NOTE.md index 8a1be446..cb6a4c50 100644 --- a/RELEASE_NOTE.md +++ b/RELEASE_NOTE.md @@ -1,3 +1,3 @@ # LBM Release Note -This is a sample release note. If you see this message in the release note, please ensure that `./RELEASE_NOTE.md` is written correctly. +This is a sample release note. If you see this message in the release note, make sure that `./RELEASE_NOTE.md` is written correctly. diff --git a/builders/build-artifacts/Dockerfile b/builders/build-artifacts/Dockerfile deleted file mode 100644 index 27c8e7fa..00000000 --- a/builders/build-artifacts/Dockerfile +++ /dev/null @@ -1,21 +0,0 @@ -FROM golang:1.18.9-bullseye - -RUN apt update && \ - apt upgrade && \ - apt install -y \ - build-essential - -RUN mkdir /lbm -RUN useradd -ms /bin/bash -U lbm -USER lbm:lbm -WORKDIR /lbm - -ENV APP ${APP:-simd} -ENV DEBUG ${DEBUG} -ENV VERSION unknown -ENV COMMIT unknown -ENV LEDGER_ENABLED true -ENV TARGET_PLATFORMS ${TARGET_PLATFORMS:-linux/amd64} - -VOLUME [ "/lbm" ] -ENTRYPOINT [ "/bin/bash" ] diff --git a/builders/build-artifacts/README.md b/builders/build-artifacts/README.md deleted file mode 100644 index 343749ee..00000000 --- a/builders/build-artifacts/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# Docker images for creating release builds - -This Docker image is used to create release binaries for Github Actions. To build locally, use the following `make` command: - -`make distclean build-reproducible` - -This will build the build release binaries into `. /artifact`.