-
Notifications
You must be signed in to change notification settings - Fork 0
168 lines (143 loc) · 5.17 KB
/
ci.yml
File metadata and controls
168 lines (143 loc) · 5.17 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
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-gnu
os: ubuntu-latest
- target: aarch64-unknown-linux-gnu
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-compilation tools (Linux ARM)
if: matrix.target == 'aarch64-unknown-linux-gnu'
run: |
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu
- name: Cache cargo
uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.target }}
- name: Build
shell: bash
run: |
if [ "${{ matrix.target }}" = "aarch64-unknown-linux-gnu" ]; then
export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc
fi
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: 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 }}