-
Notifications
You must be signed in to change notification settings - Fork 2
185 lines (158 loc) Β· 6.15 KB
/
Copy pathcd.yml
File metadata and controls
185 lines (158 loc) Β· 6.15 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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
name: "CD Release"
on:
workflow_dispatch:
inputs:
version:
description: "Release version (e.g., v1.0.0)"
required: true
type: string
prerelease:
description: "Mark as pre-release"
required: false
type: boolean
default: false
dry_run:
description: "Dry run (build only, no release)"
required: false
type: boolean
default: false
jobs:
# Verify version matches Cargo.toml
validate-version:
name: Validate Version
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Check version matches Cargo.toml
run: |
echo "π Validating version input..."
# Remove 'v' prefix from input version if present
INPUT_VERSION="${{ inputs.version }}"
INPUT_VERSION="${INPUT_VERSION#v}"
# Extract version from Cargo.toml
CARGO_VERSION=$(grep -m1 '^version = ' Cargo.toml | sed 's/version = "\(.*\)"/\1/')
echo "π Input version: $INPUT_VERSION"
echo "π¦ Cargo.toml version: $CARGO_VERSION"
if [ "$INPUT_VERSION" != "$CARGO_VERSION" ]; then
echo "β Version mismatch!"
echo " Input version: $INPUT_VERSION"
echo " Cargo.toml version: $CARGO_VERSION"
echo ""
echo "Please ensure the version you entered matches the version in Cargo.toml"
echo "Either update Cargo.toml to version $INPUT_VERSION and commit, or use version $CARGO_VERSION"
exit 1
fi
echo "β
Version matches Cargo.toml!"
# Verify CI has passed before proceeding (lightweight check, no polling)
check-ci:
name: Verify CI Passed
needs: validate-version
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Check CI Status via GitHub API
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "π Checking CI status for commit: ${{ github.sha }}"
# Get all check runs for this commit
gh api repos/${{ github.repository }}/commits/${{ github.sha }}/check-runs \
--jq '.check_runs[] | select(.name | test("Build Project|Run Tests|Check Formatting|Run Clippy Lints|Build Documentation")) | "\(.name): \(.conclusion)"'
# Check if all required checks passed
FAILED_CHECKS=$(gh api repos/${{ github.repository }}/commits/${{ github.sha }}/check-runs \
--jq '[.check_runs[] | select(.name | test("Build Project|Run Tests|Check Formatting|Run Clippy Lints|Build Documentation")) | select(.conclusion != "success")] | length')
if [ "$FAILED_CHECKS" -gt 0 ]; then
echo "β CI checks have not all passed. Please ensure all CI checks are green before releasing."
exit 1
fi
echo "β
All CI checks passed!"
# Build release binaries for all platforms
build-release:
name: Build ${{ matrix.platform.name }}
needs: check-ci
runs-on: ${{ matrix.platform.os }}
strategy:
matrix:
platform:
- name: Linux x64
os: ubuntu-latest
target: x86_64-unknown-linux-gnu
artifact: enforce-script-lsp-${{ inputs.version }}-linux-x64
- name: Windows x64
os: windows-latest
target: x86_64-pc-windows-msvc
artifact: enforce-script-lsp-${{ inputs.version }}-windows-x64.exe
steps:
- uses: actions/checkout@v5
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.platform.target }}
- name: Cache Dependencies
uses: actions/cache@v4
with:
path: |
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-
- name: Build Release Binary
run: cargo build --release --target ${{ matrix.platform.target }} --verbose
- name: Prepare Binary (Unix)
if: runner.os != 'Windows'
run: |
cp target/${{ matrix.platform.target }}/release/enforce-script-lsp ${{ matrix.platform.artifact }}
chmod +x ${{ matrix.platform.artifact }}
- name: Prepare Binary (Windows)
if: runner.os == 'Windows'
run: |
Copy-Item target/${{ matrix.platform.target }}/release/enforce-script-lsp.exe ${{ matrix.platform.artifact }}
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.platform.artifact }}
path: ${{ matrix.platform.artifact }}
retention-days: 1
# Publish to crates.io
publish-crates:
name: Publish to crates.io
needs: check-ci
if: ${{ !inputs.dry_run && !inputs.prerelease }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
- name: Publish to crates.io
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: |
echo "π¦ Publishing to crates.io..."
cargo publish --verbose
# Create GitHub Release with all binaries
create-release:
name: Create GitHub Release
needs: build-release
if: ${{ !inputs.dry_run && always() && needs.build-release.result == 'success' }}
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v5
- name: Download all artifacts
uses: actions/download-artifact@v5
with:
path: artifacts/
- name: Create Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ inputs.version }}
name: Release ${{ inputs.version }}
prerelease: ${{ inputs.prerelease }}
draft: false
generate_release_notes: true
files: |
artifacts/enforce-script-lsp-${{ inputs.version }}-linux-x64/enforce-script-lsp-${{ inputs.version }}-linux-x64
artifacts/enforce-script-lsp-${{ inputs.version }}-windows-x64.exe/enforce-script-lsp-${{ inputs.version }}-windows-x64.exe