diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 0ce732f..848bfd1 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -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 @@ -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 @@ -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 @@ -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 @@ -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: diff --git a/.github/workflows/publish_binaries_to_gh.yaml b/.github/workflows/publish_binaries_to_gh.yaml deleted file mode 100644 index c934b46..0000000 --- a/.github/workflows/publish_binaries_to_gh.yaml +++ /dev/null @@ -1,42 +0,0 @@ -name: Publish Binaries -on: - push: - tags: - - v[0-9]+.[0-9]+.[0-9]+ - -jobs: - create-release: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: taiki-e/create-gh-release-action@v1 - with: - branch: master - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - upload-assets: - strategy: - matrix: - include: - - target: x86_64-unknown-linux-gnu - os: ubuntu-latest - - target: x86_64-apple-darwin - os: macos-latest - - target: aarch64-unknown-linux-gnu - os: ubuntu-latest - - target: aarch64-apple-darwin - os: macos-latest - runs-on: ${{ matrix.os }} - steps: - - uses: actions/checkout@v2 - - uses: taiki-e/upload-rust-binary-action@v1 - with: - bin: bunyan - target: ${{ matrix.target }} - archive: $bin-$tag-$target - tar: unix - zip: windows - include: LICENSE.txt,README.md,man/bunyan.1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/make.yaml b/.github/workflows/release.yaml similarity index 56% rename from .github/workflows/make.yaml rename to .github/workflows/release.yaml index 4b20480..4ad5679 100644 --- a/.github/workflows/make.yaml +++ b/.github/workflows/release.yaml @@ -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 @@ -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: @@ -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 @@ -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: @@ -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 'dekobon@users.noreply.github.com' - - 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 }} \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..6361e43 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,3 @@ +# Changelog + +All notable changes to this project will be documented in this file. diff --git a/Containerfile.debian b/Containerfile.debian index 4cc62ed..a90777e 100644 --- a/Containerfile.debian +++ b/Containerfile.debian @@ -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 \ diff --git a/GNUmakefile b/GNUmakefile index 129c073..1b73030 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -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 @@ -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 diff --git a/RELEASING.md b/RELEASING.md new file mode 100644 index 0000000..000de31 --- /dev/null +++ b/RELEASING.md @@ -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. \ No newline at end of file diff --git a/build/changelog.sh b/build/changelog.sh new file mode 100755 index 0000000..79e434b --- /dev/null +++ b/build/changelog.sh @@ -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 \ No newline at end of file diff --git a/build/container.mk b/build/container.mk index 6e3c2f6..2f2cb71 100644 --- a/build/container.mk +++ b/build/container.mk @@ -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 diff --git a/build/github.mk b/build/github.mk index b15d1bc..4576619 100644 --- a/build/github.mk +++ b/build/github.mk @@ -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)" diff --git a/build/package.mk b/build/package.mk index 475f2b5..ae6f685 100644 --- a/build/package.mk +++ b/build/package.mk @@ -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 @@ -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 @@ -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 ###################################################################################################################### diff --git a/build/release.mk b/build/release.mk index afa6895..108b758 100644 --- a/build/release.mk +++ b/build/release.mk @@ -1,29 +1,17 @@ -LAST_VERSION := $(shell git tag -l | $(GREP) -E '^v[0-9]+\.[0-9]+\.[0-9]+$$' | sort --version-sort --field-separator=. --reverse | head -n1 | $(SED) -e 's/^v//') -LAST_VERSION_HASH := $(shell git show --format=%H v$(LAST_VERSION) | head -n1) -CHANGES := $(shell git log --format="%s (%h)" "$(LAST_VERSION_HASH)..HEAD" | \ - $(GREP) -v '^(ci|chore): .*' | \ - $(SED) 's/: /:\t/g1' | \ - column -s " " -t | \ - $(SED) -e 's/^/ * /' | \ - tr '\n' '\1') - .PHONY: changelog .ONESHELL: changelog changelog: ## Outputs the changes since the last version committed - $Q echo 'Changes in $(VERSION) since $(LAST_VERSION):' - echo "$(CHANGES)" | tr '\1' '\n' + $Q VERSION="$(VERSION)" $(CURDIR)/build/changelog.sh .ONESHELL: target/dist/release_notes.md target/dist/release_notes.md: target/dist target/dist/SHA256SUMS $(info $(M) building release notes) @ - $Q echo 'Changes since last release:' > target/dist/release_notes.md - $Q echo '```' >> target/dist/release_notes.md - $Q echo "$(CHANGES)" | tr '\1' '\n' >> target/dist/release_notes.md - $Q echo '```' >> target/dist/release_notes.md - $Q echo 'SHA256 Checksums:' >> target/dist/release_notes.md - $Q echo '```' >> target/dist/release_notes.md - $Q cat target/dist/SHA256SUMS >> target/dist/release_notes.md - $Q echo '```' >> target/dist/release_notes.md + $Q echo "# Release Notes" > target/dist/release_notes.md + VERSION="$(VERSION)" $(CURDIR)/build/changelog.sh >> target/dist/release_notes.md + echo '## SHA256 Checksums' >> target/dist/release_notes.md + echo '```' >> target/dist/release_notes.md + cat target/dist/SHA256SUMS >> target/dist/release_notes.md + echo '```' >> target/dist/release_notes.md .PHONY: release-notes release-notes: target/dist/release_notes.md ## Build release notes @@ -39,7 +27,7 @@ version-update: ## Prompts for a new version $Q echo " last committed version: $(LAST_VERSION)" $Q echo " Cargo.toml file version : $(VERSION)" read -p " Enter new version in the format (MAJOR.MINOR.PATCH): " version - $Q echo "$$version" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+-?.*$$' || \ + $Q echo "$$version" | $(GREP) -qE '^[0-9]+\.[0-9]+\.[0-9]+-?.*$$' || \ (echo "invalid version identifier: $$version" && exit 1) && \ $(SED) -i "s/^version\s*=.*$$/version = \"$$version\"/" $(CURDIR)/Cargo.toml @ VERSION=$(shell $(GREP) -Po '^version\s+=\s+"\K.*?(?=")' $(CURDIR)/Cargo.toml) @@ -47,8 +35,13 @@ version-update: ## Prompts for a new version .PHONY: version-release .ONESHELL: version-release version-release: ## Change from a pre-release to full release version - $Q echo "$(VERSION)" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+-beta$$' || \ + $Q echo "$(VERSION)" | $(GREP) -qE '^[0-9]+\.[0-9]+\.[0-9]+-beta$$' || \ (echo "invalid version identifier - must contain suffix -beta: $(VERSION)" && exit 1) export NEW_VERSION="$(shell echo $(VERSION) | $(SED) -e 's/-beta$$//')" $(SED) -i "s/^version\s*=.*$$/version = \"$$NEW_VERSION\"/" $(CURDIR)/Cargo.toml - @ VERSION=$(shell $(GREP) -Po '^version\s+=\s+"\K.*?(?=")' $(CURDIR)/Cargo.toml) \ No newline at end of file + @ VERSION=$(shell $(GREP) -Po '^version\s+=\s+"\K.*?(?=")' $(CURDIR)/Cargo.toml) + +.PHONY: cargo-release +cargo-release: ## Releases a new version to crates.io + $(info $(M) releasing version $(VERSION) to crates.io) @ + $Q $(CARGO) publish \ No newline at end of file diff --git a/pkg/brew/bunyan-bin.rb b/pkg/brew/bunyan-view.rb similarity index 100% rename from pkg/brew/bunyan-bin.rb rename to pkg/brew/bunyan-view.rb diff --git a/pkg/brew/bunyan-bin.rb.template b/pkg/brew/bunyan-view.rb.template similarity index 100% rename from pkg/brew/bunyan-bin.rb.template rename to pkg/brew/bunyan-view.rb.template