Skip to content

release

release #41

Workflow file for this run

name: release
on:
push:
tags:
- '*'
jobs:
# First register a new release we can attach files to.
create-release:
name: create-release
runs-on: ubuntu-latest
outputs:
version: ${{ steps.release_version.outputs.version }}
steps:
# Yes, we really need to get the plain tag name like this. There are even
# dedicated actions for it.
# https://stackoverflow.com/a/58178121/482758
- name: Share release version
id: release_version
run: printf 'version=%s\n' "${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
build-package:
name: build-package
needs:
- create-release
runs-on: ${{ matrix.os }}
strategy:
matrix:
build:
- linux
- macos
- win-msvc
include:
- build: linux
os: ubuntu-22.04
target: x86_64-unknown-linux-musl
binary_ext:
- build: macos
os: macos-12
target: x86_64-apple-darwin
binary_ext:
- build: win-msvc
os: windows-2022
target: x86_64-pc-windows-msvc
binary_ext: .exe
env:
# Backtraces for panics.
RUST_BACKTRACE: 1
TARGET_FLAGS:
TARGET_DIR: ./target
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Prepare environment
shell: bash
run: |
printf 'TARGET_FLAGS=--target %s\n' "${{ matrix.target }}" >> $GITHUB_ENV
printf 'TARGET_DIR=./target/${{ matrix.target }}\n' >> $GITHUB_ENV
printf 'RELEASE_VERSION=%s\n' "${{ needs.create-release.outputs.version }}" >> $GITHUB_ENV
printf 'RELEASE_BINARY=%s\n' "target/${{ matrix.target }}/release/commitmsgfmt${{ matrix.binary_ext }}" >> $GITHUB_ENV
# So much cruft just to install Asciidoctor.
# It's possible to do something like
# run: ./ci/install-${{ matrix.os }}
# but I couldn't get Windows to do anything that way.
- name: Install dependencies (Ubuntu)
if: matrix.os == 'ubuntu-22.04'
run: |
sudo apt-get update
sudo apt-get install --yes --no-install-recommends \
asciidoctor
- name: Install dependencies (Windows)
if: matrix.os == 'windows-2022'
run: gem install asciidoctor
- name: Install dependencies (macOS)
if: matrix.os == 'macos-12'
run: brew install asciidoctor
- name: Install Rust
uses: dtolnay/rust-toolchain@master
with:
# Build all releases on nightly for latest optimizations.
toolchain: nightly
targets: ${{ matrix.target }}
- name: Install Cross
run: cargo install cross
- name: Build release
run: cross build --verbose --release ${{ env.TARGET_FLAGS }}
- name: Strip release binary
if: matrix.build == 'linux' || matrix.build == 'macos'
run: strip "${{ env.RELEASE_BINARY }}"
- name: Assemble package
shell: bash
run: |
package="commitmsgfmt-${{ env.RELEASE_VERSION }}-${{ matrix.target }}"
mkdir -p "$package"
asciidoctor --doctype manpage --backend manpage "doc/*.adoc"
cp "doc/commitmsgfmt.1" "$package"
cp LICENSE.txt "$package"
cp README.md "$package"
cp CHANGELOG.md "$package"
cp -r contrib "$package"
cp "${{ env.RELEASE_BINARY }}" "$package"
if [[ "${{ matrix.os }}" = 'windows-2022' ]]
then
7z a "$package.zip" "$package"
printf 'ASSET=%s\n' "$package.zip" >> $GITHUB_ENV
else
tar caf "$package.tar.gz" "$package"
printf 'ASSET=%s\n' "$package.tar.gz" >> $GITHUB_ENV
fi
- name: Upload package
uses: softprops/action-gh-release@v1
with:
draft: true
tag_name: ${{ env.RELEASE_VERSION }}
files: ${{ env.ASSET }}