-
Notifications
You must be signed in to change notification settings - Fork 12
161 lines (133 loc) · 4.28 KB
/
rust-runtime-release.yml
File metadata and controls
161 lines (133 loc) · 4.28 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
name: Rust Runtime Release
on:
workflow_dispatch:
inputs:
publish_crate:
description: "Publish the Rust crate when CARGO_REGISTRY_TOKEN is available"
required: false
default: false
type: boolean
create_github_release:
description: "Create or update a GitHub release with CLI artifacts"
required: false
default: false
type: boolean
push:
tags:
- "sidemantic-rs-v*"
- "rust-runtime-v*"
permissions:
contents: read
env:
CARGO_TERM_COLOR: always
jobs:
package:
name: Check crate package
runs-on: ubuntu-latest
defaults:
run:
working-directory: sidemantic-rs
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Cache cargo
uses: Swatinem/rust-cache@v2
with:
workspaces: sidemantic-rs
- name: Run package metadata tests
run: cargo test --locked --test package_metadata
- name: Check package contents
run: cargo package --locked --no-verify
- name: Check publish dry run
run: cargo publish --locked --dry-run
- name: Publish crate
if: ${{ github.event_name == 'workflow_dispatch' && inputs.publish_crate == true }}
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: |
if [ -z "$CARGO_REGISTRY_TOKEN" ]; then
echo "Skipping cargo publish because CARGO_REGISTRY_TOKEN is not configured."
exit 0
fi
cargo publish --locked
cli-artifacts:
name: Build CLI artifact (${{ matrix.artifact }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
artifact: linux-x86_64
- os: macos-13
artifact: macos-x86_64
- os: macos-14
artifact: macos-arm64
- os: windows-latest
artifact: windows-x86_64
defaults:
run:
working-directory: sidemantic-rs
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Cache cargo
uses: Swatinem/rust-cache@v2
with:
workspaces: sidemantic-rs
- name: Build CLI
run: cargo build --release --locked --bin sidemantic
- name: Package CLI artifact
shell: bash
run: |
mkdir -p dist
if [ "$RUNNER_OS" = "Windows" ]; then
cp target/release/sidemantic.exe "dist/sidemantic-${{ matrix.artifact }}.exe"
else
cp target/release/sidemantic "dist/sidemantic-${{ matrix.artifact }}"
tar -czf "dist/sidemantic-${{ matrix.artifact }}.tar.gz" -C dist "sidemantic-${{ matrix.artifact }}"
fi
- name: Upload CLI artifact
uses: actions/upload-artifact@v4
with:
name: sidemantic-cli-${{ matrix.artifact }}
path: sidemantic-rs/dist/*
if-no-files-found: error
github-release:
name: Attach CLI artifacts to GitHub release
needs:
- package
- cli-artifacts
if: ${{ startsWith(github.ref, 'refs/tags/') || (github.event_name == 'workflow_dispatch' && inputs.create_github_release == true) }}
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: Download CLI artifacts
uses: actions/download-artifact@v4
with:
path: dist
merge-multiple: true
- name: Resolve release tag
id: release
run: |
if [ "${{ github.ref_type }}" = "tag" ]; then
TAG="${{ github.ref_name }}"
else
VERSION=$(grep '^version = ' sidemantic-rs/Cargo.toml | sed 's/version = "\(.*\)"/\1/')
TAG="sidemantic-rs-v${VERSION}"
fi
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
- name: Create or update GitHub release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
TAG="${{ steps.release.outputs.tag }}"
if gh release view "$TAG" >/dev/null 2>&1; then
gh release upload "$TAG" dist/* --clobber
else
gh release create "$TAG" dist/* --title "$TAG" --generate-notes
fi