-
Notifications
You must be signed in to change notification settings - Fork 2
215 lines (198 loc) · 7.52 KB
/
ci.yaml
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
name: CI/CD Workflow
on:
push:
branches:
- main
pull_request:
branches:
- "*"
jobs:
test:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
arch: [aarch64, x86_64]
runs-on: "${{ matrix.os }}"
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Cache dependencies
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: "${{ matrix.os }}-${{ matrix.arch }}-cargo-${{ hashFiles('**/Cargo.lock') }}"
- name: Cache LLVM
id: cache-llvm
if: matrix.os == 'windows-latest'
uses: actions/cache@v3
with:
path: |
C:\Program Files\LLVM
key: ${{ matrix.os }}-${{ matrix.arch }}-llvm-17.0.4 # Adjust version as needed
restore-keys: |
${{ matrix.os }}-${{ matrix.arch }}-llvm-17.0.4
- name: Download and Install LLVM
if: steps.cache-llvm.outputs.cache-hit != 'true' && matrix.os == 'windows-latest'
run: |
$arch = if ($env:ARCH -eq 'x86_64') { "win64" } else { "woa64" }
$url = "https://github.com/llvm/llvm-project/releases/download/llvmorg-17.0.4/LLVM-17.0.4-$arch.exe"
echo "Downloading LLVM from $url" # Debugging line
$output = "llvm-installer.exe"
Invoke-WebRequest -Uri $url -OutFile $output
$process = Start-Process $output -ArgumentList "/S" -NoNewWindow -PassThru
$process.WaitForExit()
shell: powershell
env:
ARCH: ${{ matrix.arch }}
- name: Set LIBCLANG_PATH
if: matrix.os == 'windows-latest'
run: |
echo "LIBCLANG_PATH=C:\Program Files\LLVM\bin" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8
# Debug: Print the LIBCLANG_PATH environment variable
echo "LIBCLANG_PATH: $env:LIBCLANG_PATH"
# Debug: Check if libclang.dll is present
Test-Path "C:\Program Files\LLVM\bin\libclang.dll"
shell: powershell
- name: Run pre-build scripts and test
shell: bash
run: |
if [[ "${{ runner.os }}" == "Linux" ]]; then
# Execute Linux pre-build script
bash ./pre-build-linux.sh && cargo test
elif [[ "${{ runner.os }}" == "Windows" ]]; then
# Execute Windows pre-build script
powershell -File ./pre-build-win.ps1 --ci && cargo test
else
cargo test
fi
env:
# Build environment variables
GITHUB_ENV: ${{ github.workspace }}/.env
build:
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
needs: test
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
arch: [aarch64, x86_64]
runs-on: "${{ matrix.os }}"
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Cache dependencies
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: "${{ matrix.os }}-${{ matrix.arch }}-cargo-${{ hashFiles('**/Cargo.lock') }}"
- name: Cache LLVM
id: cache-llvm
if: matrix.os == 'windows-latest'
uses: actions/cache@v3
with:
path: |
C:\Program Files\LLVM
key: ${{ matrix.os }}-${{ matrix.arch }}-llvm-17.0.4 # Adjust version as needed
restore-keys: |
${{ matrix.os }}-${{ matrix.arch }}-llvm-17.0.4
- name: Download and Install LLVM
if: steps.cache-llvm.outputs.cache-hit != 'true' && matrix.os == 'windows-latest'
run: |
$arch = if ($env:ARCH -eq 'x86_64') { "win64" } else { "woa64" }
$url = "https://github.com/llvm/llvm-project/releases/download/llvmorg-17.0.4/LLVM-17.0.4-$arch.exe"
$output = "llvm-installer.exe"
Invoke-WebRequest -Uri $url -OutFile $output
$process = Start-Process $output -ArgumentList "/S" -NoNewWindow -PassThru
$process.WaitForExit()
shell: powershell
env:
ARCH: ${{ matrix.arch }}
- name: Set LIBCLANG_PATH
if: matrix.os == 'windows-latest'
run: |
echo "LIBCLANG_PATH=C:\Program Files\LLVM\bin" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8
shell: powershell
- name: Run pre-build scripts and build release
shell: bash
run: |
if [[ "${{ runner.os }}" == "Linux" ]]; then
# Execute Linux pre-build script
bash ./pre-build-linux.sh && cargo build --release
elif [[ "${{ runner.os }}" == "Windows" ]]; then
# Execute Windows pre-build script
powershell -File ./pre-build-win.ps1 --ci && cargo build --release
else
cargo build --release
fi
env:
# Build environment variables
GITHUB_ENV: ${{ github.workspace }}/.env
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: "${{ matrix.os }}-${{ matrix.arch }}-binary"
path: target/release/smrec
release:
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
needs: build
runs-on: ubuntu-latest
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
arch: [aarch64, x86_64]
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: "${{ matrix.os }}-${{ matrix.arch }}-binary"
- name: Get version from Cargo.toml
id: get_version
run: echo "::set-output name=version::$(grep '^version =' Cargo.toml | awk -F\" '{print $2}')"
- name: Prepare asset
run: |
mkdir -p ./release
mv ./${{ matrix.os }}-${{ matrix.arch }}-binary ./release/smrec
cd release
zip -r ../smrec_${{ steps.get_version.outputs.version }}_${{ matrix.os }}_${{ matrix.arch }}.zip .
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ steps.get_version.outputs.version }}
release_name: smrec v${{ steps.get_version.outputs.version }} - ${{ matrix.os }} ${{ matrix.arch }}
body: "Automatic changelog generation will be applied in the future. This is an auto generated release note."
draft: false
prerelease: false
- name: Upload Release Asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./smrec_${{ steps.get_version.outputs.version }}_${{ matrix.os }}_${{ matrix.arch }}.zip
asset_name: smrec_${{ steps.get_version.outputs.version }}_${{ matrix.os }}_${{ matrix.arch }}.zip
asset_content_type: application/zip
- name: Error Handling
if: failure()
run: echo "An error has occurred during the release process"
publish:
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
needs: release
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Publish to Crates.io
uses: actions-rs/cargo@v1
with:
command: publish
args: "--token ${{ secrets.CRATES_IO_TOKEN }}"