Skip to content

release

release #54

Workflow file for this run

name: release
on:
push:
tags:
- '*'
permissions:
contents: write
jobs:
build-package:
name: build-package
runs-on: ${{ matrix.os }}
strategy:
matrix:
build:
- linux
include:
- build: linux
os: ubuntu-22.04
target: x86_64-unknown-linux-musl
binary_ext:
env:
# Backtraces for panics.
RUST_BACKTRACE: 1
TARGET_FLAGS:
TARGET_DIR: ./target
steps:
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: false
- 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' "${GITHUB_REF#refs/tags/}" >> $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 cargo-binstall
uses: cargo-bins/[email protected]
env:
GITHUB_TOKEN: ${{ github.token }}
- name: Install Cross
# "install cross" takes 1 minute, "binstall cross" takes 1 second.
run: cargo binstall --no-confirm cross
env:
GITHUB_TOKEN: ${{ github.token }}
- 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 }}