name: Release
on:
push:
tags:
- '*.*.*'
permissions:
contents: write
env:
CARGO_TERM_COLOR: always
jobs:
validate:
name: Validate release metadata
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- id: version
name: Require tag and Cargo version equality
shell: bash
run: |
version=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].version')
if [[ "${GITHUB_REF_NAME}" != "${version}" ]]; then
echo "tag ${GITHUB_REF_NAME} does not match Cargo version ${version}" >&2
exit 1
fi
echo "version=${version}" >> "$GITHUB_OUTPUT"
- name: Verify package contents
shell: bash
run: |
package_files="$RUNNER_TEMP/textcon-package-files.txt"
cargo package --list --locked > "$package_files"
grep -qx 'docs/man/textcon.1' "$package_files"
grep -qx 'docs/man/textcon.1.scd' "$package_files"
if grep -q '^skills/' "$package_files"; then
echo 'source-only skill leaked into Cargo package' >&2
exit 1
fi
- name: Publish dry run
run: cargo publish --dry-run --locked
build:
name: Build ${{ matrix.target }}
needs: validate
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
binary: textcon
asset: textcon-linux-x86_64
cross: false
- os: ubuntu-latest
target: x86_64-unknown-linux-musl
binary: textcon
asset: textcon-linux-x86_64-musl
cross: true
- os: ubuntu-latest
target: aarch64-unknown-linux-gnu
binary: textcon
asset: textcon-linux-aarch64
cross: true
- os: macos-latest
target: x86_64-apple-darwin
binary: textcon
asset: textcon-macos-x86_64
cross: false
- os: macos-latest
target: aarch64-apple-darwin
binary: textcon
asset: textcon-macos-aarch64
cross: false
- os: windows-latest
target: x86_64-pc-windows-msvc
binary: textcon.exe
asset: textcon-windows-x86_64
cross: false
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Install cross
if: matrix.cross
run: cargo install cross --locked
- name: Install reproducible archive tooling
if: runner.os == 'macOS'
run: brew install gnu-tar
- name: Build release binary
shell: bash
run: |
if [[ "${{ matrix.cross }}" == "true" ]]; then
cross build --release --locked --target "${{ matrix.target }}"
else
cargo build --release --locked --target "${{ matrix.target }}"
fi
- name: Stage release tree
shell: bash
run: |
root="textcon-${{ needs.validate.outputs.version }}-${{ matrix.target }}"
archive="${{ matrix.asset }}-${{ needs.validate.outputs.version }}"
mkdir -p "${root}/bin" "${root}/share/man/man1"
cp "target/${{ matrix.target }}/release/${{ matrix.binary }}" "${root}/bin/"
cp docs/man/textcon.1 "${root}/share/man/man1/"
cp README.md LICENSE "${root}/"
if [[ "${{ runner.os }}" == "Windows" ]]; then
7z a "${archive}.zip" "${root}"
sha256sum "${archive}.zip" > "${archive}.zip.sha256"
else
tar_command=tar
if [[ "${{ runner.os }}" == "macOS" ]]; then tar_command=gtar; fi
"$tar_command" --sort=name --owner=0 --group=0 --numeric-owner \
--mtime="@$(git log -1 --format=%ct)" -cf - "${root}" \
| gzip -n > "${archive}.tar.gz"
shasum -a 256 "${archive}.tar.gz" > "${archive}.tar.gz.sha256"
fi
- uses: actions/upload-artifact@v4
with:
name: ${{ matrix.asset }}-${{ needs.validate.outputs.version }}
path: |
${{ matrix.asset }}-${{ needs.validate.outputs.version }}.tar.gz
${{ matrix.asset }}-${{ needs.validate.outputs.version }}.tar.gz.sha256
${{ matrix.asset }}-${{ needs.validate.outputs.version }}.zip
${{ matrix.asset }}-${{ needs.validate.outputs.version }}.zip.sha256
if-no-files-found: ignore
publish-crate:
name: Publish crate
needs: [validate, build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- run: cargo publish --locked --token "${{ secrets.CRATES_IO_TOKEN }}"
release:
name: Create draft release
needs: [validate, build, publish-crate]
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with:
path: artifacts
merge-multiple: true
- uses: softprops/action-gh-release@v2
with:
draft: true
generate_release_notes: true
files: artifacts/*