Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically generates release note and binaries on release #126

Merged
merged 9 commits into from
Jan 5, 2023
102 changes: 102 additions & 0 deletions .github/workflows/release-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
name: "Release Build"

on:
push:
tags: # Push events to matching v*, i.e. v20.15.10, v0.1.2-rc34
- "v[0-9]+.[0-9]+.[0-9]+"
- "v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+"

jobs:
build:
name: "Create Release"
runs-on: ubuntu-latest
steps:
- name: "Checkout code"
uses: actions/[email protected]
- 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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know why it failed in this case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So far I’ve confirmed that linux/arm64 produces the following assembler-level error, but I haven’t yet investigated the reason for it.

Building for linux/arm64
CGO_CFLAGS= CGO_LDFLAGS= CGO_ENABLED=1 go build -mod=readonly -tags "netgo ledger...
# runtime/cgo
gcc_arm64.S: Assembler messages:
gcc_arm64.S:28: Error: no such instruction: `stp x29,x30,[sp,'
gcc_arm64.S:32: Error: too many memory references for `mov'
gcc_arm64.S:34: Error: no such instruction: `stp x19,x20,[sp,'
gcc_arm64.S:37: Error: no such instruction: `stp x21,x22,[sp,'
...

# 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
96 changes: 96 additions & 0 deletions .release-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#!/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}" <<EOF
App: ${APP}
Version: ${VERSION}
Commit: ${COMMIT}
EOF
echo "Files:" >> "${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"
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
## [Unreleased]

### Features
* (build) [\#126](https://github.com/line/lbm/pull/126) Automatically generates release note and binaries

### Improvements

Expand Down
26 changes: 16 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#!/usr/bin/make -f

BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
COMMIT := $(shell git log -1 --format='%H')
COMMIT ?= $(shell git log -1 --format='%H')

# ascribe tag only if on a release/ branch, otherwise pick branch name and concatenate commit hash
VERSION := $(shell echo $(shell git describe --tags) | sed 's/^v//')
ifeq (, $(findstring release/,$(BRANCH)))
VERSION = $(BRANCH)-$(COMMIT)
ifeq (, $(VERSION))
BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
VERSION := $(shell echo $(shell git describe --tags) | sed 's/^v//')
ifeq (, $(findstring release/,$(BRANCH)))
VERSION = $(subst /,_,$(BRANCH))-$(COMMIT)
endif
endif

PACKAGES_SIMTEST=$(shell go list ./... | grep '/simulation')
Expand Down Expand Up @@ -196,15 +198,19 @@ dbbackend:
endif

build-reproducible: go.sum
$(DOCKER) rm latest-build || true
$(DOCKER) run --volume=$(CURDIR):/sources:ro \
--env TARGET_PLATFORMS='linux/amd64 darwin/amd64 linux/arm64 windows/amd64' \
$(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 latest-build cosmossdk/rbuilder:latest
$(DOCKER) cp -a latest-build:/home/builder/artifacts/ $(CURDIR)/
--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 .
Expand Down
3 changes: 3 additions & 0 deletions RELEASE_NOTE.md
Original file line number Diff line number Diff line change
@@ -0,0 +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.
zemyblue marked this conversation as resolved.
Show resolved Hide resolved
21 changes: 21 additions & 0 deletions builders/build-artifacts/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
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" ]
7 changes: 7 additions & 0 deletions builders/build-artifacts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# 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`.