-
Notifications
You must be signed in to change notification settings - Fork 0
104 lines (92 loc) · 2.97 KB
/
cli.yml
File metadata and controls
104 lines (92 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
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 }}"