name: Release to crates.io and GitHub
on:
push:
tags:
- "v*"
permissions:
contents: read
env:
CARGO_TERM_COLOR: always
jobs:
check-version:
name: Check tag matches Cargo.toml
runs-on: ubuntu-latest
timeout-minutes: 5
outputs:
version: ${{ steps.version.outputs.version }}
publish: ${{ steps.version.outputs.publish }}
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 with:
persist-credentials: false
- id: version
env:
TAG: ${{ github.ref_name }}
run: |
crate_version=$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -1)
if [ "v${crate_version}" != "${TAG}" ]; then
echo "::error::Tag ${TAG} does not match Cargo.toml version ${crate_version}"
exit 1
fi
echo "version=${crate_version}" >> "$GITHUB_OUTPUT"
# Publish to crates.io only for stable X.Y.0 releases (no patch or pre-release tags).
if [[ "${crate_version}" =~ ^[0-9]+\.[0-9]+\.0$ ]]; then
echo "publish=true" >> "$GITHUB_OUTPUT"
else
echo "publish=false" >> "$GITHUB_OUTPUT"
fi
lint-test:
name: Lint and test
needs: check-version
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 with:
persist-credentials: false
- uses: dtolnay/rust-toolchain@7e38f4b43b4db5c8dd498af069a4f6196df1d067 with:
toolchain: stable
components: clippy, rustfmt
- uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 - run: sudo apt-get update && sudo apt-get install -y pkg-config libssl-dev
- run: cargo fmt --all -- --check
- run: cargo clippy --all-targets --all-features --locked -- -D warnings
- run: cargo test --locked
build-binaries:
name: Build ${{ matrix.name }}
needs: lint-test
timeout-minutes: 40
strategy:
matrix:
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
name: git-editor-linux-x86_64
- target: aarch64-apple-darwin
os: macos-latest
name: git-editor-macos-aarch64
- target: x86_64-pc-windows-msvc
os: windows-latest
name: git-editor-windows-x86_64.exe
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 with:
persist-credentials: false
- uses: dtolnay/rust-toolchain@7e38f4b43b4db5c8dd498af069a4f6196df1d067 with:
toolchain: stable
targets: ${{ matrix.target }}
- uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 with:
key: ${{ matrix.target }}
- name: Install OpenSSL headers
if: runner.os == 'Linux'
run: sudo apt-get update && sudo apt-get install -y pkg-config libssl-dev
- run: cargo build --release --locked --target ${{ matrix.target }}
- name: Prepare binary (Unix)
if: runner.os != 'Windows'
run: cp target/${{ matrix.target }}/release/git-editor ${{ matrix.name }}
- name: Prepare binary (Windows)
if: runner.os == 'Windows'
run: copy target\${{ matrix.target }}\release\git-editor.exe ${{ matrix.name }}
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 with:
name: ${{ matrix.name }}
path: ${{ matrix.name }}
build-packages:
name: Build Linux packages
needs: lint-test
runs-on: ubuntu-latest
timeout-minutes: 40
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 with:
persist-credentials: false
- uses: dtolnay/rust-toolchain@7e38f4b43b4db5c8dd498af069a4f6196df1d067 with:
toolchain: stable
- uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 - run: sudo apt-get update && sudo apt-get install -y pkg-config libssl-dev rpm
- name: Install packaging tools (pinned)
run: |
cargo install --locked cargo-deb@3.8.0
cargo install --locked cargo-generate-rpm@0.21.0
- run: cargo build --release --locked --target x86_64-unknown-linux-gnu
- name: Build .deb package
run: |
cargo deb --target x86_64-unknown-linux-gnu --no-build
mv target/x86_64-unknown-linux-gnu/debian/*.deb ./git-editor_amd64.deb
- name: Build .rpm package
run: |
cargo generate-rpm --target x86_64-unknown-linux-gnu
mv target/x86_64-unknown-linux-gnu/generate-rpm/*.rpm ./git-editor.x86_64.rpm
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 with:
name: linux-packages
path: |
git-editor_amd64.deb
git-editor.x86_64.rpm
build-windows-installer:
name: Build Windows installer (.msi)
needs: lint-test
runs-on: windows-latest
timeout-minutes: 40
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 with:
persist-credentials: false
- uses: dtolnay/rust-toolchain@7e38f4b43b4db5c8dd498af069a4f6196df1d067 with:
toolchain: stable
targets: x86_64-pc-windows-msvc
- uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 - name: Install WiX Toolset 3.11 (checksum verified)
run: |
Invoke-WebRequest -Uri "https://github.com/wixtoolset/wix3/releases/download/wix3112rtm/wix311-binaries.zip" -OutFile "wix.zip"
$hash = (Get-FileHash wix.zip -Algorithm SHA256).Hash
if ($hash -ne "2C1888D5D1DBA377FC7FA14444CF556963747FF9A0A289A3599CF09DA03B9E2E") { throw "WiX checksum mismatch: $hash" }
Expand-Archive -Path "wix.zip" -DestinationPath "wix"
echo "$env:GITHUB_WORKSPACE\wix" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
- run: cargo install --locked cargo-wix@0.3.9
- run: cargo build --release --locked --target x86_64-pc-windows-msvc
- run: cargo wix init
- name: Build .msi installer
run: |
cargo wix -p git-editor --target x86_64-pc-windows-msvc --no-build
move target\wix\*.msi git-editor-installer.msi
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 with:
name: git-editor-installer.msi
path: git-editor-installer.msi
build-macos-package:
name: Build macOS package
needs: [check-version, lint-test]
runs-on: macos-latest
timeout-minutes: 40
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 with:
persist-credentials: false
- uses: dtolnay/rust-toolchain@7e38f4b43b4db5c8dd498af069a4f6196df1d067 with:
toolchain: stable
targets: aarch64-apple-darwin
- uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 - run: cargo build --release --locked --target aarch64-apple-darwin
- name: Create .pkg installer
env:
VERSION: ${{ needs.check-version.outputs.version }}
run: |
mkdir -p package/usr/local/bin
cp target/aarch64-apple-darwin/release/git-editor package/usr/local/bin/
chmod +x package/usr/local/bin/git-editor
pkgbuild --root package \
--identifier com.rohansen856.git-editor \
--version "$VERSION" \
--install-location / \
git-editor-aarch64-apple-darwin.pkg
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 with:
name: git-editor-aarch64-apple-darwin.pkg
path: git-editor-aarch64-apple-darwin.pkg
build-archives:
name: Build archive ${{ matrix.archive }}
needs: build-binaries
timeout-minutes: 10
strategy:
matrix:
include:
- os: ubuntu-latest
binary: git-editor-linux-x86_64
archive: git-editor-linux-x86_64.tar.gz
- os: macos-latest
binary: git-editor-macos-aarch64
archive: git-editor-macos-aarch64.tar.gz
- os: windows-latest
binary: git-editor-windows-x86_64.exe
archive: git-editor-windows-x86_64.zip
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 with:
persist-credentials: false
- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 with:
name: ${{ matrix.binary }}
- name: Create archive (Unix)
if: runner.os != 'Windows'
run: |
chmod +x ${{ matrix.binary }}
tar -czf ${{ matrix.archive }} ${{ matrix.binary }} README.md LICENSE
- name: Create archive (Windows)
if: runner.os == 'Windows'
run: 7z a ${{ matrix.archive }} ${{ matrix.binary }} README.md LICENSE
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 with:
name: ${{ matrix.archive }}
path: ${{ matrix.archive }}
github-release:
name: Create GitHub release
needs: [build-binaries, build-packages, build-windows-installer, build-macos-package, build-archives]
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: write
steps:
- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 with:
path: artifacts/
- name: Collect release files and checksums
run: |
mkdir -p release/
find artifacts/ -type f -exec cp {} release/ \;
(cd release && sha256sum * > SHA256SUMS)
cat release/SHA256SUMS
- uses: softprops/action-gh-release@3bb12739c298aeb8a4eeaf626c5b8d85266b0e65 with:
files: release/*
body: |
## Release ${{ github.ref_name }}
Pre-built binaries and packages. Verify downloads with `sha256sum -c SHA256SUMS`.
- **Linux (x86_64)**: `git-editor-linux-x86_64`, `.tar.gz`, `git-editor_amd64.deb`, `git-editor.x86_64.rpm`
- **macOS (Apple Silicon)**: `git-editor-macos-aarch64`, `.tar.gz`, `git-editor-aarch64-apple-darwin.pkg`
- **Windows (x86_64)**: `git-editor-windows-x86_64.exe`, `.zip`, `git-editor-installer.msi`
publish-cratesio:
name: Publish to crates.io
needs: [check-version, github-release]
if: needs.check-version.outputs.publish == 'true'
runs-on: ubuntu-latest
timeout-minutes: 20
environment: release
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 with:
persist-credentials: false
- uses: dtolnay/rust-toolchain@7e38f4b43b4db5c8dd498af069a4f6196df1d067 with:
toolchain: stable
- run: sudo apt-get update && sudo apt-get install -y pkg-config libssl-dev
- run: cargo publish --locked
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}