-
Notifications
You must be signed in to change notification settings - Fork 0
195 lines (163 loc) · 5.98 KB
/
ci.yml
File metadata and controls
195 lines (163 loc) · 5.98 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
186
187
188
189
190
191
192
193
194
195
name: CI
on:
pull_request:
branches:
- main
push:
branches:
- main
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- name: Cache cargo
uses: Swatinem/rust-cache@v2
- name: Install nextest
uses: taiki-e/install-action@nextest
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Pre-install tsx for TypeScript tests
run: npm install -g tsx
- name: Format check
run: cargo fmt --check
- name: Lint
run: cargo clippy -- -D warnings
- name: Run tests
run: cargo nextest run
- name: Build
run: cargo build --release
release:
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
needs: test
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version-check.outputs.current }}
changed: ${{ steps.version-check.outputs.changed }}
tag_exists: ${{ steps.tag-check.outputs.exists }}
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Check if version changed
id: version-check
run: |
# Get current version from Cargo.toml
CURRENT_VERSION=$(grep '^version' Cargo.toml | head -1 | sed 's/.*"\(.*\)".*/\1/')
echo "current=$CURRENT_VERSION" >> $GITHUB_OUTPUT
# Get previous version from parent commit
git show HEAD^:Cargo.toml > /tmp/old-cargo.toml 2>/dev/null || echo 'version = "0.0.0"' > /tmp/old-cargo.toml
PREVIOUS_VERSION=$(grep '^version' /tmp/old-cargo.toml | head -1 | sed 's/.*"\(.*\)".*/\1/')
echo "previous=$PREVIOUS_VERSION" >> $GITHUB_OUTPUT
# Check if version changed
if [ "$CURRENT_VERSION" != "$PREVIOUS_VERSION" ]; then
echo "changed=true" >> $GITHUB_OUTPUT
echo "Version changed: $PREVIOUS_VERSION -> $CURRENT_VERSION"
else
echo "changed=false" >> $GITHUB_OUTPUT
echo "Version unchanged: $CURRENT_VERSION"
fi
- name: Check if tag exists
if: steps.version-check.outputs.changed == 'true'
id: tag-check
run: |
if git ls-remote --tags origin | grep -q "refs/tags/v${{ steps.version-check.outputs.current }}$"; then
echo "exists=true" >> $GITHUB_OUTPUT
echo "Tag v${{ steps.version-check.outputs.current }} already exists"
else
echo "exists=false" >> $GITHUB_OUTPUT
fi
- name: Create tag
if: steps.version-check.outputs.changed == 'true' && steps.tag-check.outputs.exists != 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -a "v${{ steps.version-check.outputs.current }}" -m "Release v${{ steps.version-check.outputs.current }}"
git push origin "v${{ steps.version-check.outputs.current }}"
build-binaries:
if: needs.release.outputs.changed == 'true' && needs.release.outputs.tag_exists != 'true'
needs: release
strategy:
matrix:
include:
- target: x86_64-unknown-linux-musl
os: ubuntu-latest
- target: aarch64-unknown-linux-musl
os: ubuntu-latest
- target: x86_64-apple-darwin
os: macos-latest
- target: aarch64-apple-darwin
os: macos-latest
- target: x86_64-pc-windows-msvc
os: windows-latest
runs-on: ${{ matrix.os }}
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Install cross (Linux)
if: runner.os == 'Linux'
uses: taiki-e/install-action@cross
- name: Cache cargo
uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.target }}
- name: Build (Linux)
if: runner.os == 'Linux'
run: cross build --release --target ${{ matrix.target }}
- name: Build (macOS)
if: runner.os == 'macOS'
run: cargo build --release --target ${{ matrix.target }}
- name: Build (Windows)
if: runner.os == 'Windows'
run: cargo build --release --target ${{ matrix.target }}
- name: Prepare binary (Unix)
if: runner.os != 'Windows'
run: |
cp target/${{ matrix.target }}/release/migrate migrate-${{ matrix.target }}
- name: Prepare binary (Windows)
if: runner.os == 'Windows'
run: |
cp target/${{ matrix.target }}/release/migrate.exe migrate-${{ matrix.target }}.exe
- name: Test binary compatibility (Linux)
if: runner.os == 'Linux' && matrix.target == 'x86_64-unknown-linux-musl'
run: |
# Verify the binary runs on an older system (Debian Bullseye has GLIBC 2.31)
docker run --rm -v $PWD:/app debian:bullseye /app/migrate-${{ matrix.target }} --version
- name: Upload to release
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ needs.release.outputs.version }}
files: migrate-${{ matrix.target }}*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
publish-crate:
if: needs.release.outputs.changed == 'true' && needs.release.outputs.tag_exists != 'true'
needs: release
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
- name: Cache cargo
uses: Swatinem/rust-cache@v2
- name: Publish to crates.io
run: cargo publish
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}