name: Release
on:
push:
tags: [ 'v*' ]
permissions:
contents: read
env:
CARGO_TERM_COLOR: always
jobs:
build:
name: Build (${{ matrix.target }})
runs-on: ${{ matrix.os }}
permissions:
contents: read
id-token: write attestations: write strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
ext: ""
pack: tar.gz
- os: macos-latest
target: aarch64-apple-darwin
ext: ""
pack: tar.gz
- os: windows-latest
target: x86_64-pc-windows-msvc
ext: .exe
pack: zip
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 with:
persist-credentials: false
- uses: dtolnay/rust-toolchain@b725eda525362e7cf34af9a7243cac1e3f01a7ec with:
toolchain: stable
targets: ${{ matrix.target }}
- name: Verify tag == Cargo.toml
shell: bash
run: |
TAG="${GITHUB_REF_NAME}"
VERSION=$(grep '^version *= *"' Cargo.toml | sed 's/.*"\(.*\)".*/\1/')
if [ "v$VERSION" != "$TAG" ]; then
echo "::error::Tag($TAG) != Cargo.toml(v$VERSION)"
exit 1
fi
echo "OK: $TAG matches Cargo.toml"
- name: Build
run: cargo build --release --locked --target ${{ matrix.target }}
- name: Prepare package
shell: bash
run: |
BIN="tree2md${{ matrix.ext }}"
OUT="tree2md-${{ matrix.target }}"
mkdir -p dist/$OUT
cp target/${{ matrix.target }}/release/$BIN dist/$OUT/
cp README.md dist/$OUT/ 2>/dev/null || true
cp LICENSE dist/$OUT/ 2>/dev/null || true
cd dist
if [ "${{ matrix.pack }}" = "zip" ]; then
7z a -tzip "$OUT.zip" "$OUT"
# Use certutil on Windows for SHA256
certutil -hashfile "$OUT.zip" SHA256 | head -2 | tail -1 | tr -d ' ' > "$OUT.sha256"
echo " $OUT.zip" >> "$OUT.sha256"
else
tar czf "$OUT.tar.gz" "$OUT"
shasum -a 256 "$OUT.tar.gz" > "$OUT.sha256"
fi
- name: Attest build provenance
uses: actions/attest-build-provenance@977bb373ede98d70efdf65b84cb5f73e068dcc2a with:
subject-path: dist/tree2md-${{ matrix.target }}.${{ matrix.pack }}
- name: Upload artifact
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 with:
name: tree2md-${{ matrix.target }}
path: dist/tree2md-${{ matrix.target }}.*
release:
name: Create GitHub Release
needs: build
runs-on: ubuntu-latest
permissions:
contents: write steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 with:
fetch-depth: 0
persist-credentials: false
- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 with:
path: artifacts
- name: Extract release notes from CHANGELOG.md
id: notes
run: |
TAG="${GITHUB_REF_NAME}" # e.g. v0.5.0
VER="${TAG#v}" # e.g. 0.5.0
# Extract the section for this version from CHANGELOG.md
awk -v ver="$VER" '
$0 ~ "^## \\[" ver "\\]" {p=1; next}
p && $0 ~ "^## \\[" {exit}
p && $0 ~ "^\\[Unreleased\\]:" {exit}
p
' CHANGELOG.md > RELEASE_NOTES.md
# Add header with version and date
echo "## tree2md ${TAG}" > RELEASE_NOTES_FINAL.md
echo "" >> RELEASE_NOTES_FINAL.md
cat RELEASE_NOTES.md >> RELEASE_NOTES_FINAL.md
echo "---- RELEASE NOTES ----"
cat RELEASE_NOTES_FINAL.md
- name: Create release
uses: softprops/action-gh-release@3bb12739c298aeb8a4eeaf626c5b8d85266b0e65 with:
name: "tree2md ${{ github.ref_name }}"
files: artifacts/**/tree2md-*
body_path: RELEASE_NOTES_FINAL.md
generate_release_notes: true
append_body: true
draft: false
prerelease: false
publish:
name: Publish to crates.io
needs: build
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 with:
fetch-depth: 0
persist-credentials: false
- uses: dtolnay/rust-toolchain@b725eda525362e7cf34af9a7243cac1e3f01a7ec with:
toolchain: stable
- name: Ensure tag == Cargo.toml (strict)
run: |
TAG="${GITHUB_REF_NAME}"
VERSION=$(grep '^version *= *"' Cargo.toml | sed 's/.*"\(.*\)".*/\1/')
[ "v$VERSION" = "$TAG" ] || (echo "::error::Tag($TAG) != v$VERSION"; exit 1)
echo "OK: $TAG == v$VERSION"
- name: Check not already published
run: |
VERSION=$(grep '^version *= *"' Cargo.toml | sed 's/.*"\(.*\)".*/\1/')
# Simple check - fails if version already exists, passes if unpublished (404) or not found
cargo search tree2md --limit 1 | grep -q "tree2md = \"$VERSION\"" && \
(echo "::error::Version $VERSION already on crates.io"; exit 1) || true
- name: Publish
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: cargo publish --locked