release #59
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: release | |
on: | |
push: | |
tags: | |
- '*' | |
permissions: | |
contents: write | |
jobs: | |
archive-src: | |
name: archive-src | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
persist-credentials: false | |
- name: Install dependencies | |
run: | | |
sudo apt-get update | |
sudo apt-get install --yes --no-install-recommends \ | |
lzip | |
- name: Archive source code | |
shell: bash | |
run: | | |
v="${GITHUB_REF#refs/tags/}" | |
release_name="commitmsgfmt-$v" | |
asset_name="${release_name}.tar.lz" | |
git archive --prefix="${release_name}/" --format=tar "$v" | | |
lzip -6 >"$asset_name" | |
printf 'ASSET=%s\n' "$asset_name" >> $GITHUB_ENV | |
printf 'RELEASE_VERSION=%s\n' "$v" >> $GITHUB_ENV | |
- name: Upload source code archive | |
uses: softprops/action-gh-release@v1 | |
with: | |
draft: true | |
tag_name: ${{ env.RELEASE_VERSION }} | |
files: ${{ env.ASSET }} | |
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 }} |