Skip to content

Commit

Permalink
build: fix github release workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
dekobon committed Dec 27, 2022
1 parent 5838b7c commit a75c46c
Show file tree
Hide file tree
Showing 14 changed files with 159 additions and 102 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
name: Test (Linux)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
profile: minimal
Expand All @@ -25,7 +25,7 @@ jobs:
name: Test (MacOS)
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
profile: minimal
Expand All @@ -40,7 +40,7 @@ jobs:
name: Rustfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
profile: minimal
Expand All @@ -56,7 +56,7 @@ jobs:
name: Clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
profile: minimal
Expand All @@ -73,7 +73,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
Expand Down
42 changes: 0 additions & 42 deletions .github/workflows/publish_binaries_to_gh.yaml

This file was deleted.

44 changes: 38 additions & 6 deletions .github/workflows/make.yaml → .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: setup docker buildx
uses: docker/setup-buildx-action@v2
- name: create build container
run: make container-debian-build-image
env:
DOCKER_BUILD_FLAGS: --load --cache-from=type=gha --cache-to=type=gha,mode=max
- name: run tests
run: make container-test
- name: container-all-packages
run: make container-all-packages
- name: upload linux packages
Expand All @@ -22,7 +30,7 @@ jobs:
runs-on: macos-latest
steps:
- name: checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: install latest rust toolchain
uses: actions-rs/toolchain@v1
with:
Expand All @@ -33,6 +41,8 @@ jobs:
run: rustup target install x86_64-apple-darwin aarch64-apple-darwin
- name: install latest gnu make version
run: brew install make
- name: run tests
run: gmake test
- name: macos-packages
run: gmake gz-packages
- name: upload MacOS packages
Expand All @@ -42,13 +52,14 @@ jobs:
retention-days: 1
path: target/dist/
build-supplemental-files-and-release:
environment: release
needs:
- build-linux-packages
- build-macos-packages
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: download linux packages
uses: actions/download-artifact@v3
with:
Expand All @@ -64,14 +75,35 @@ jobs:
- name: output checksums
run: cat target/dist/SHA256SUMS
- name: release-notes
run: make release-notes
run: |
git fetch --tags
git fetch --unshallow || true
make release-notes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: append to changelog
run: make changelog >> CHANGELOG.md
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: homebrew-package
run: make homebrew-packages
- name: assign git user
- name: assign git user and commit release changes
run: |
git config user.name 'Github Action'
git config user.email '[email protected]'
- name: do release
git commit CHANGELOG.md pkg/brew/*.rb -m "ci: release changes for ${GITHUB_REF_NAME}"
git push origin ${GITHUB_REF_NAME}
- name: do github release
run: make gh-make-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: do cargo release
# Do not fail build on crates.io problems
run: make cargo-release || true
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
- name: create pull request integrating release branch changes
run: |
gh pr create --title "ci: integrate release changes for ${GITHUB_REF_NAME}" --body "This pull request was automatically created by the Github Action workflow **${GITHUB_WORKFLOW}**." --head ${GITHUB_REF_NAME} --base master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Changelog

All notable changes to this project will be documented in this file.
2 changes: 2 additions & 0 deletions Containerfile.debian
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ RUN set -eux \
apt-get -qq update; \
apt-get -qq upgrade --yes; \
apt-get -qq install --yes --no-install-recommends --no-install-suggests \
bsdmainutils \
ca-certificates \
git \
gzip \
grep \
gawk \
Expand Down
35 changes: 18 additions & 17 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,23 @@ ifneq ($(shell test $(MAKE_MAJOR_VER) -gt 3; echo $$?),0)
$(error Make version $(MAKE_VERSION) is not supported, please install GNU Make 4.x)
endif

GREP ?= $(shell command -v ggrep 2> /dev/null || command -v grep 2> /dev/null)
SED ?= $(shell command -v gsed 2> /dev/null || command -v sed 2> /dev/null)
AWK ?= $(shell command -v gawk 2> /dev/null || command -v awk 2> /dev/null)
RUSTUP ?= $(shell command -v rustup 2> /dev/null)
RPM_ARCH := $(shell uname -m)
VERSION ?= $(shell $(GREP) -Po '^version\s+=\s+"\K.*?(?=")' $(CURDIR)/Cargo.toml)
SRC_REPO := https://github.com/dekobon/bunyan-view
DEFAULT_TARGET ?= $(shell $(RUSTUP) toolchain list | $(GREP) '(default)' | cut -d' ' -f1 | cut -d- -f2-)
SHELL := /bin/bash
OUTPUT_BINARY ?= bunyan
PACKAGE_NAME ?= bunyan-view
CARGO ?= cargo
DOCKER ?= docker
CHECKSUM ?= sha256sum
COMMITSAR_DOCKER := $(DOCKER) run --tty --rm --workdir /src -v "$(CURDIR):/src" aevea/commitsar
COMMITSAR ?= $(shell command -v commitsar 2> /dev/null)
GREP ?= $(shell command -v ggrep 2> /dev/null || command -v grep 2> /dev/null)
SED ?= $(shell command -v gsed 2> /dev/null || command -v sed 2> /dev/null)
AWK ?= $(shell command -v gawk 2> /dev/null || command -v awk 2> /dev/null)
RUSTUP ?= $(shell command -v rustup 2> /dev/null)
RPM_ARCH := $(shell uname -m)
VERSION ?= $(shell $(GREP) -Po '^version\s+=\s+"\K.*?(?=")' $(CURDIR)/Cargo.toml)
SRC_REPO := https://github.com/dekobon/bunyan-view
DEFAULT_TARGET ?= $(shell $(RUSTUP) toolchain list | $(GREP) '(default)' | cut -d' ' -f1 | cut -d- -f2-)
SHELL := /bin/bash
OUTPUT_BINARY ?= bunyan
PACKAGE_NAME ?= bunyan-view
CARGO ?= cargo
DOCKER ?= docker
DOCKER_BUILD_FLAGS ?= --load
CHECKSUM ?= sha256sum
COMMITSAR_DOCKER := $(DOCKER) run --tty --rm --workdir /src -v "$(CURDIR):/src" aevea/commitsar
COMMITSAR ?= $(shell command -v commitsar 2> /dev/null)

# Define platform targets based off of the current host OS
# If we are running MacOS, then we can build for MacOS platform targets that have been installed in rustup
Expand All @@ -45,7 +46,7 @@ endif

.PHONY: help
help:
@grep --no-filename -E '^[ a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
@$(GREP) --no-filename -E '^[ a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
$(AWK) 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-28s\033[0m %s\n", $$1, $$2}' | sort

.PHONY: clean
Expand Down
27 changes: 27 additions & 0 deletions RELEASING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Release Process

This document describes the process for releasing a new version of the
project.

## Prerequisites

- You must be a maintainer of the project.
- You must have installed GNU Make 4+.
- You must have committer rights.

## Release Process

1. Create a new branch for the release, e.g. `release-v1.2.3`:
`git checkout -b release-v1.2.3`
2. Update the Cargo.toml version to the new version:
`make version-release`
3. Check in version changes: `git commit Cargo.toml -m "ci: updating version to 1.2.3"`
4. Wait for CI to build, tag and perform the release.
5. Pull the latest changes from origin because the CI will have pushed changes to the branch.
6. Once the release is complete, rebase the release branch into master: `
git rebase --onto origin/master release-v1.2.3 master
git push origin master`
7. Increment the version to the next development version: `make version-update` and
use a version number like 1.2.4-beta.
8. Check in version changes: `git commit Cargo.toml -m "ci: updating version to 1.2.4-beta"`
9. Delete release branch from origin.
42 changes: 42 additions & 0 deletions build/changelog.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env bash

# This script generates a changelog for the current version of the project.

set -o errexit # abort on nonzero exit status
set -o nounset # abort on unbound variable
set -o pipefail # don't hide errors within pipes

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"

pushd . > /dev/null
cd "${SCRIPT_DIR}/.."

if command -v ggrep > /dev/null; then
GREP=ggrep
else
GREP=grep
fi
if command -v gsed > /dev/null; then
SED=gsed
else
SED=sed
fi

# if gh is installed, use it to pull the last version number
if command -v gh > /dev/null; then
LAST_RELEASE="$(gh release list | ${GREP} -E 'v[0-9]+\.[0-9]+\.[0-9]+' | cut -f1 | ${GREP} -v "${VERSION}" | head -n1)"
else
LAST_RELEASE="$(git tag -l | ${GREP} -E '^v[0-9]+\.[0-9]+\.[0-9]+$$' | sort --version-sort --field-separator=. --reverse | ${GREP} -v "${VERSION}" | head -n1)"
fi

LAST_RELEASE_HASH="$(git show --format=%H "${LAST_RELEASE}" | head -n1)"

echo "## Changes between ${LAST_RELEASE} [$LAST_RELEASE_HASH] and ${VERSION}:"
git log --format="%s (%h)" "${LAST_RELEASE_HASH}..HEAD" | \
${GREP} -E -v '^(ci|chore): .*' | \
${SED} 's/: /:\t/g1' | \
column -s " " -t | \
${SED} -e 's/^/ * /'

echo ""
popd > /dev/null
8 changes: 4 additions & 4 deletions build/container.mk
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
.PHONY: container-debian-build-image
.ONESHELL: container-debian-build-image
container-debian-build-image:
container-debian-build-image: ## Builds a container image for building on Debian Linux
$Q if [ "$$($(DOCKER) images --quiet --filter=reference=debian_builder)" = "" ]; then \
echo "$(M) building debian linux docker build image: $(@)"; \
$(DOCKER) build -t debian_builder -f Containerfile.debian .; \
fi
$Q echo "$(M) building debian linux docker build image: $(@)"
$(DOCKER) buildx build $(DOCKER_BUILD_FLAGS) -t debian_builder -f Containerfile.debian $(CURDIR);

.PHONY: container-deb-packages
container-deb-packages: container-debian-build-image ## Builds deb packages using a container image
Expand Down
5 changes: 2 additions & 3 deletions build/github.mk
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
.PHONY: gh-make-release
.ONESHELL: gh-make-release
gh-make-release: GIT_BRANCH = $(shell git rev-parse --abbrev-ref HEAD)
gh-make-release:
ifndef CI
$(error must be running in CI)
endif
ifneq ($(GIT_BRANCH),release-v$(VERSION))
ifneq ($(shell git rev-parse --abbrev-ref HEAD),release-v$(VERSION))
$(error must be running on release-v$(VERSION) branch)
endif
$(info $(M) updating files with release version) @
$(info $(M) updating files with release version [$(GIT_BRANCH)]) @
git commit -m "ci: update files to version $(VERSION)" Cargo.toml pkg/brew/bunyan-bin.rb
git push origin "release-v$(VERSION)"
git tag -a "v$(VERSION)" -m "ci: tagging v$(VERSION)"
Expand Down
6 changes: 3 additions & 3 deletions build/package.mk
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ DEBIAN_PACKAGE_TARGETS := $(foreach t, $(TARGETS), target/$(t)/debian/$(PACKAGE_
$(DEBIAN_PACKAGE_TARGETS): $(TARGETS) target/man/$(OUTPUT_BINARY).1.gz target/dist
$Q TARGET="$(word 2, $(subst /, , $(dir $@)))"
# Skip building debs for musl targets
if echo "$(@)" | grep -q 'musl\|apple'; then \
if echo "$(@)" | $(GREP) -q 'musl\|apple'; then \
exit 0
fi
if [ ! -f "$(CURDIR)/$(@)" ]; then
Expand All @@ -61,7 +61,7 @@ $(RPM_PACKAGE_TARGETS): $(TARGETS) target/man/$(OUTPUT_BINARY).1.gz target/dist
$Q TARGET="$(word 2, $(subst /, , $(dir $@)))"
ARCH="$(firstword $(subst -, , $(word 2, $(subst /, , $(dir $@)))))"
# Skip building rpms for musl targets
if echo "$(@)" | grep -q 'musl\|apple'; then \
if echo "$(@)" | $(GREP) -q 'musl\|apple'; then \
exit 0
fi
if [ ! -f "$(CURDIR)/$(@)" ]; then
Expand Down Expand Up @@ -98,7 +98,7 @@ endif
X86_64_UNKNOWN_LINUX_GNU_SHA256="$$($(GREP) $(PACKAGE_NAME)_v$(VERSION)_x86_64-unknown-linux-gnu.tar.gz $(CURDIR)/target/dist/SHA256SUMS | cut -d ' ' -f 1)" \
X86_64_APPLE_DARWIN_SHA256="$$($(GREP) $(PACKAGE_NAME)_v$(VERSION)_x86_64-apple-darwin.tar.gz $(CURDIR)/target/dist/SHA256SUMS | cut -d ' ' -f 1)" \
AARCH64_APPLE_DARWIN_SHA256="$$($(GREP) $(PACKAGE_NAME)_v$(VERSION)_aarch64-apple-darwin.tar.gz $(CURDIR)/target/dist/SHA256SUMS | cut -d ' ' -f 1)" \
envsubst < pkg/brew/bunyan-bin.rb.template > $(CURDIR)/pkg/brew/bunyan-bin.rb
envsubst < $(CURDIR)/pkg/brew/$(PACKAGE_NAME).rb.template > $(CURDIR)/pkg/brew/$(PACKAGE_NAME).rb


######################################################################################################################
Expand Down
Loading

0 comments on commit a75c46c

Please sign in to comment.