Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 104 additions & 0 deletions .github/workflows/cli.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
name: CLI

on:
push:
branches: [main]
pull_request:
types: [opened, synchronize, reopened]
release:
types: [published]

jobs:
build:
name: Build Rust (${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
include:
- os: ubuntu-latest
bin_src: rust/target/release/contentmd
bin_dst: dist/contentmd-linux
artifact: contentmd-linux
- os: macos-latest
bin_src: rust/target/release/contentmd
bin_dst: dist/contentmd-macos
artifact: contentmd-macos
- os: windows-latest
bin_src: rust/target/release/contentmd.exe
bin_dst: dist/contentmd-windows.exe
artifact: contentmd-windows

steps:
- name: Checkout
uses: actions/checkout@v6

- name: Setup Rust
uses: dtolnay/rust-toolchain@stable

- name: Cache Rust dependencies
uses: actions/cache@v5
with:
path: |
~/.cargo/registry
~/.cargo/git
rust/target
key: ${{ runner.os }}-cargo-${{ hashFiles('rust/Cargo.lock') }}
restore-keys: ${{ runner.os }}-cargo-

- name: Set Cargo.toml version from release tag
if: github.event_name == 'release'
shell: bash
run: |
TAG="${{ github.event.release.tag_name }}"
VERSION="${TAG#v}"
VERSION="${VERSION%%-*}"
if ! [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Release tag '$TAG' does not yield a valid major.minor.patch version (got '$VERSION')" >&2
exit 1
fi
echo "Setting Cargo.toml version to $VERSION"
sed -i.bak -E "s/^version = \".*\"/version = \"$VERSION\"/" rust/Cargo.toml
rm rust/Cargo.toml.bak
grep '^version' rust/Cargo.toml

- name: Run Tests
working-directory: rust
run: cargo test

- name: Build Binary
working-directory: rust
run: cargo build --release

- name: Stage binary for upload
shell: bash
run: |
mkdir -p dist
cp ${{ matrix.bin_src }} ${{ matrix.bin_dst }}

- name: Upload binary artifact
uses: actions/upload-artifact@v7
with:
name: ${{ matrix.artifact }}
path: ${{ matrix.bin_dst }}
retention-days: 2

release:
name: Attach binaries to release
needs: build
if: github.event_name == 'release'
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Download all artifacts
uses: actions/download-artifact@v8
with:
path: dist
merge-multiple: true

- name: Upload binaries to release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh release upload "${{ github.event.release.tag_name }}" dist/* --clobber --repo "${{ github.repository }}"
1 change: 1 addition & 0 deletions rust/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
Loading
Loading