name: Release
permissions:
contents: write
on:
push:
branches: [main, dev]
tags:
- 'v[0-9]+.*'
pull_request:
jobs:
check:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
features: ["", "tui"]
steps:
- uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@stable
with:
components: clippy, rustfmt
- uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: check-${{ matrix.features }}-${{ hashFiles('Cargo.lock') }}
restore-keys: check-${{ matrix.features }}-
- name: Clippy (-D warnings)
run: |
FEAT=""
if [ -n "${{ matrix.features }}" ]; then FEAT="--features ${{ matrix.features }}"; fi
cargo clippy --locked --all-targets $FEAT -- -D warnings
- name: Test (incl. USAGE.md schema)
run: |
FEAT=""
if [ -n "${{ matrix.features }}" ]; then FEAT="--features ${{ matrix.features }}"; fi
cargo test --locked $FEAT
- name: Format check
run: cargo fmt --check
create-release:
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: taiki-e/create-gh-release-action@v1
with:
changelog: docs/CHANGELOG.md
token: ${{ secrets.GITHUB_TOKEN }}
upload-assets:
if: startsWith(github.ref, 'refs/tags/v')
needs: create-release
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- target: aarch64-apple-darwin
os: macos-latest
features: ""
- target: aarch64-apple-darwin
os: macos-latest
features: "tui"
- target: x86_64-apple-darwin
os: macos-latest
features: ""
- target: x86_64-apple-darwin
os: macos-latest
features: "tui"
- target: x86_64-pc-windows-msvc
os: windows-latest
features: ""
- target: x86_64-pc-windows-msvc
os: windows-latest
features: "tui"
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
features: ""
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
features: "tui"
- target: x86_64-unknown-linux-musl
os: ubuntu-latest
features: ""
- target: x86_64-unknown-linux-musl
os: ubuntu-latest
features: "tui"
- target: aarch64-unknown-linux-musl
os: ubuntu-latest
features: ""
- target: aarch64-unknown-linux-musl
os: ubuntu-latest
features: "tui"
steps:
- uses: actions/checkout@v6
- name: Setup cross toolchain (musl / aarch64 linux)
if: matrix.os == 'ubuntu-latest' && contains(matrix.target, 'musl')
uses: taiki-e/setup-cross-toolchain-action@v1
with:
target: ${{ matrix.target }}
- name: Install Rust target
if: matrix.os != 'ubuntu-latest' || !contains(matrix.target, 'musl')
run: rustup target add ${{ matrix.target }}
- uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: release-${{ matrix.os }}-${{ matrix.target }}-${{ matrix.features }}-${{ hashFiles('Cargo.lock') }}
restore-keys: release-${{ matrix.os }}-${{ matrix.target }}-
- name: Build (locked, release)
shell: bash
run: |
FEAT=""
if [ -n "${{ matrix.features }}" ]; then FEAT="--features ${{ matrix.features }}"; fi
cargo build --locked --release --target ${{ matrix.target }} $FEAT
- name: Package + checksum (contract A)
shell: bash
env:
VERSION: ${{ github.ref_name }}
TARGET: ${{ matrix.target }}
FEATURES: ${{ matrix.features }}
run: |
set -euo pipefail
VERSION="${VERSION#v}"
SUFFIX=""
if [ -n "${FEATURES}" ]; then SUFFIX="-tui"; fi
if [ "$RUNNER_OS" = "Windows" ]; then
EXT="zip"
BIN="mdbook-plotly.exe"
else
EXT="tar.gz"
BIN="mdbook-plotly"
fi
DIR="target/${TARGET}/release"
NAME="mdbook-plotly-${VERSION}-${TARGET}${SUFFIX}.${EXT}"
if [ "$RUNNER_OS" = "Windows" ]; then
powershell -NoProfile -Command "Compress-Archive -Force -Path '${DIR}/${BIN}' -DestinationPath '${NAME}'"
else
tar -C "${DIR}" -czf "${NAME}" "${BIN}"
fi
python3 - "$NAME" <<'PY'
import hashlib, sys
name = sys.argv[1]
digest = hashlib.sha256(open(name, "rb").read()).hexdigest()
with open(name + ".sha256", "w", encoding="ascii") as f:
f.write(f"{digest} {name}\n")
PY
ls -1 mdbook-plotly-*
- name: Upload assets
uses: softprops/action-gh-release@v2
with:
files: |
mdbook-plotly-*.tar.gz
mdbook-plotly-*.zip
mdbook-plotly-*.sha256
token: ${{ secrets.GITHUB_TOKEN }}