Skip to content

Commit

Permalink
Add Release Workflow and Build Script for Automated Releases (#190)
Browse files Browse the repository at this point in the history
Signed-off-by: Max Lambrecht <[email protected]>
  • Loading branch information
Max Lambrecht authored Jun 5, 2023
1 parent 72f2e5f commit a7b8f85
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 10 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/release_build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Release Build
on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+' # Trigger this workflow when a new vX.Y.Z tag is pushed
env:
GO_VERSION: 1.20.3

jobs:
build:
name: Build Artifacts
runs-on: ubuntu-latest
permissions:
contents: read
actions: read
steps:
- name: Setup go
uses: actions/setup-go@4d34df0c2316fe8122ab82dc22947d607c0c91f9 # v4.0.0
with:
go-version: ${{ env.GO_VERSION }}

- name: Check out code
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2

- name: Get dependencies
run: go mod download

- name: Test
run: go test -v ./...

- name: Build Artifacts
run: ./.github/workflows/scripts/build_artifacts.sh

- name: Upload Artifacts
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
with:
name: release-artifacts
path: |
galadriel-*-linux-*-glibc.tar.gz
galadriel-*-linux-*-glibc.tar.gz.sha256sum.txt
release:
name: Release
needs: build
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Download Artifacts
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
with:
name: release-artifacts

- name: Release
uses: softprops/action-gh-release@26994186c0ac3ef5cae75ac16aa32e8153525f77 # v1
with:
files: |
galadriel-*-linux-*-glibc.tar.gz
galadriel-*-linux-*-glibc.tar.gz.sha256sum.txt
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
34 changes: 34 additions & 0 deletions .github/workflows/scripts/build_artifacts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash
# Builds Galadriel artifacts for Linux for all supported architectures.
# Usage: build_artifacts.sh

set -e

supported_architectures=(amd64 arm64)

export version_tag=
if [[ "$GITHUB_REF" =~ ^refs/tags/v[0-9.]+$ ]]; then
# Strip off the leading "v" from the release tag. Release artifacts are
# named just with the version number (e.g. v0.9.3 tag produces
# galadriel-0.9.3-linux-x64.tar.gz).
version_tag="${GITHUB_REF##refs/tags/v}"
fi

for architecture in "${supported_architectures[@]}"; do
# Build the server and harvester binaries for the current architecture
if GOARCH=$architecture make build; then
echo "Artifacts successfully built for architecture: ${architecture}"
tarball="galadriel-${version_tag}-linux-${architecture}-glibc.tar.gz"

# Create a tarball with the binaries, license, and conf files
tar -czvf "$tarball" -C bin/ . -C ../ LICENSE conf/

# Generate a SHA-256 checksum for the tarball
sha256sum "$tarball" > "$tarball.sha256sum.txt"
else
echo "Error encountered while building artifact for architecture: ${architecture}"
exit 1
fi
done

echo "Build completed successfully for all architectures"
25 changes: 15 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,30 +39,36 @@ else
$(error unsupported ARCH: $(arch1))
endif

# Define the default architecture (can be overridden by GOARCH)
ARCH ?= $(shell go env GOARCH)
ifeq ($(ARCH),)
ARCH := $(arch1)
endif

# Define build directories and URLs
build_dir := $(DIR)/.build/$(os1)-$(arch1)
build_dir := $(DIR)/.build/$(os1)-$(ARCH)
go_dir := $(build_dir)/go/$(GO_VERSION)
server_sqlc_config_file := $(DIR)/pkg/server/db/sqlc.yaml
sqlc_dir := $(build_dir)/sqlc/$(SQLC_VERSION)
sqlc_bin := $(sqlc_dir)/sqlc

exe :=
ifeq ($(os1),windows)
go_bin_dir := $(go_dir)/go/bin
go_url := https://storage.googleapis.com/golang/go$(GO_VERSION).$(os1)-$(arch2).zip
exe := .exe
else
go_bin_dir := $(go_dir)/bin
go_url := https://storage.googleapis.com/golang/go$(GO_VERSION).$(os1)-$(arch2).tar.gz
exe :=
endif

# SQLC download URL
ifeq ($(os1),windows)
sqlc_url := https://github.com/kyleconroy/sqlc/releases/download/v$(SQLC_VERSION)/sqlc_$(SQLC_VERSION)_windows_amd64.zip
sqlc_url := https://github.com/kyleconroy/sqlc/releases/download/v$(SQLC_VERSION)/sqlc_$(SQLC_VERSION)_windows_$(arch2).zip
else ifeq ($(os1),darwin)
sqlc_url := https://github.com/kyleconroy/sqlc/releases/download/v$(SQLC_VERSION)/sqlc_$(SQLC_VERSION)_darwin_$(arch2).zip
sqlc_url := https://github.com/kyleconroy/sqlc/releases/download/v$(SQLC_VERSION)/sqlc_$(SQLC_VERSION)_darwin-$(arch2).zip
else
sqlc_url := https://github.com/kyleconroy/sqlc/releases/download/v$(SQLC_VERSION)/sqlc_$(SQLC_VERSION)_linux_amd64.zip
sqlc_url := https://github.com/kyleconroy/sqlc/releases/download/v$(SQLC_VERSION)/sqlc_$(SQLC_VERSION)_linux-$(arch2).zip
endif

# Define Go path
Expand All @@ -73,7 +79,7 @@ define binary_rule
.PHONY: $1
$1: | go-check bin/
@echo "Building $1..."
$(E)$(go_path) go build -o $1 $2
$(E)GOARCH=$(ARCH) $(go_path) go build -o $1$(exe) $2
endef

# Dynamically generate targets for each binary using the binary_rule template
Expand All @@ -86,9 +92,9 @@ bin/:

# Go check and installation if necessary
go-check:
ifeq (go$(GO_VERSION), $(shell $(go_path) go version 2>/dev/null | cut -f3 -d' '))
else
@echo "Installing go $(GO_VERSION)..."
@echo "Checking Go installation..."
ifneq ($(GO_VERSION),$(shell go version | cut -d' ' -f3 | cut -d'o' -f2))
@echo "Installing go $(GO_VERSION) ($(ARCH))..."
$(E)rm -rf $(dir $(go_dir))
$(E)mkdir -p $(go_dir)
$(E)curl -sSfL $(go_url) | tar xz -C $(go_dir) --strip-components=1
Expand Down Expand Up @@ -129,7 +135,6 @@ clean:
rm -rf out/coverage
.PHONY: clean


# Generate SQL and API code
generate-sql-code: install-sqlc $(server_sqlc_config_file)
@echo "Generating server SQL code..."
Expand Down

0 comments on commit a7b8f85

Please sign in to comment.