name: Release
on:
push:
tags:
- "v*"
permissions:
contents: write
env:
CARGO_TERM_COLOR: always
jobs:
build:
name: Build ${{ matrix.target }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
archive: tar.gz
- target: aarch64-unknown-linux-gnu
os: ubuntu-latest
archive: tar.gz
cross: true
- target: x86_64-apple-darwin
os: macos-latest
archive: tar.gz
- target: aarch64-apple-darwin
os: macos-latest
archive: tar.gz
- target: x86_64-pc-windows-msvc
os: windows-latest
archive: zip
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Install cross-compilation tools
if: matrix.cross
uses: taiki-e/setup-cross-toolchain-action@v1
with:
target: ${{ matrix.target }}
- name: Install OpenSSL (Windows)
if: runner.os == 'Windows'
run: |
echo "OPENSSL_NO_VENDOR=1" >> $env:GITHUB_ENV
- name: Build release binary
run: cargo build --release --locked --target ${{ matrix.target }}
- name: Ad-hoc sign macOS binary
if: runner.os == 'macOS'
run: |
codesign --force --sign - target/${{ matrix.target }}/release/src2md
codesign --verify --verbose target/${{ matrix.target }}/release/src2md
- name: Prepare archive (Unix)
if: matrix.os != 'windows-latest'
run: |
cd target/${{ matrix.target }}/release
tar czvf ../../../src2md-${{ matrix.target }}.${{ matrix.archive }} src2md
cd -
- name: Prepare archive (Windows)
if: matrix.os == 'windows-latest'
run: |
cd target/${{ matrix.target }}/release
7z a ../../../src2md-${{ matrix.target }}.${{ matrix.archive }} src2md.exe
cd -
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: src2md-${{ matrix.target }}
path: src2md-${{ matrix.target }}.${{ matrix.archive }}
if-no-files-found: error
release:
name: Create Release
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Flatten artifacts
run: |
mkdir -p release
find artifacts -type f \( -name "*.tar.gz" -o -name "*.zip" \) -exec mv {} release/ \;
- name: Generate checksums
run: |
cd release
sha256sum * > checksums-sha256.txt
cat checksums-sha256.txt
- name: Extract version from tag
id: version
run: echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
name: ${{ steps.version.outputs.version }}
draft: false
prerelease: ${{ contains(github.ref, 'alpha') || contains(github.ref, 'beta') || contains(github.ref, 'rc') }}
generate_release_notes: true
body: |
## Installation
### macOS
After downloading, you may need to allow the app:
```bash
xattr -d com.apple.quarantine src2md
```
### Via Cargo
```bash
cargo install src2md
```
files: |
release/*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
publish:
name: Publish to crates.io
needs: release
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Rust
uses: dtolnay/rust-toolchain@stable
- name: Publish to crates.io
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
run: cargo publish --locked