-
Notifications
You must be signed in to change notification settings - Fork 1
197 lines (167 loc) · 6.3 KB
/
ci.yml
File metadata and controls
197 lines (167 loc) · 6.3 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
196
197
name: CI/CD Pipeline
on:
push:
branches: [main, develop]
tags: ["v*"]
pull_request:
branches: [main]
env:
CARGO_TERM_COLOR: always
jobs:
lint-and-test:
name: Lint + Unit Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust stable
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: stable
components: rustfmt, clippy
- name: Cache cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-
- name: Check formatting
run: cargo fmt -- --check
- name: Run clippy
run: cargo clippy -- -D warnings
- name: Run unit tests
run: cargo test --lib --bins
e2e-test:
name: E2E Test
runs-on: ubuntu-latest
needs: lint-and-test
steps:
- uses: actions/checkout@v4
- name: Install Rust stable
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: stable
- name: Cache cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-
- name: Run E2E tests
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
env:
SERPAPI_KEY: ${{ secrets.SERPAPI_KEY }}
run: cargo test -- --ignored
- name: Skip E2E tests (fork PR)
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository
run: echo "Skipping E2E tests - SERPAPI_KEY unavailable in fork PRs"
release:
name: Cross-Compile Release
runs-on: ${{ matrix.os }}
needs: [lint-and-test, e2e-test]
if: startsWith(github.ref, 'refs/tags/v')
strategy:
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
use_cross: false
- os: ubuntu-latest
target: aarch64-unknown-linux-gnu
use_cross: true
- os: macos-latest
target: x86_64-apple-darwin
use_cross: false
- os: macos-latest
target: aarch64-apple-darwin
use_cross: false
- os: windows-latest
target: x86_64-pc-windows-msvc
use_cross: false
steps:
- uses: actions/checkout@v4
- name: Install Rust stable
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: stable
target: ${{ matrix.target }}
- name: Install cross
if: matrix.use_cross
run: cargo install cross --git https://github.com/cross-rs/cross
- name: Build release binary (cross)
if: matrix.use_cross
run: cross build --release --target ${{ matrix.target }}
- name: Build release binary (native)
if: "!matrix.use_cross"
run: cargo build --release --target ${{ matrix.target }}
- name: Prepare artifacts (Unix)
if: runner.os != 'Windows'
run: |
cd target/${{ matrix.target }}/release
BINARY_NAME="serpapi-${{ matrix.target }}"
cp serpapi "$BINARY_NAME"
shasum -a 256 "$BINARY_NAME" > "$BINARY_NAME.sha256"
tar czf "$BINARY_NAME.tar.gz" "$BINARY_NAME"
shasum -a 256 "$BINARY_NAME.tar.gz" > "$BINARY_NAME.tar.gz.sha256"
- name: Prepare artifacts (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
cd target/${{ matrix.target }}/release
$BINARY_NAME = "serpapi-${{ matrix.target }}.exe"
Copy-Item serpapi.exe $BINARY_NAME
(Get-FileHash -Algorithm SHA256 $BINARY_NAME).Hash.ToLower() + " $BINARY_NAME" | Out-File -FilePath "$BINARY_NAME.sha256" -Encoding ASCII
Compress-Archive -Path $BINARY_NAME -DestinationPath "$BINARY_NAME.zip"
(Get-FileHash -Algorithm SHA256 "$BINARY_NAME.zip").Hash.ToLower() + " $BINARY_NAME.zip" | Out-File -FilePath "$BINARY_NAME.zip.sha256" -Encoding ASCII
- name: Upload artifacts (Unix)
if: runner.os != 'Windows'
uses: actions/upload-artifact@v4
with:
name: serpapi-${{ matrix.target }}
path: |
target/${{ matrix.target }}/release/serpapi-${{ matrix.target }}
target/${{ matrix.target }}/release/serpapi-${{ matrix.target }}.sha256
target/${{ matrix.target }}/release/serpapi-${{ matrix.target }}.tar.gz
target/${{ matrix.target }}/release/serpapi-${{ matrix.target }}.tar.gz.sha256
- name: Upload artifacts (Windows)
if: runner.os == 'Windows'
uses: actions/upload-artifact@v4
with:
name: serpapi-${{ matrix.target }}
path: |
target/${{ matrix.target }}/release/serpapi-${{ matrix.target }}.exe
target/${{ matrix.target }}/release/serpapi-${{ matrix.target }}.exe.sha256
target/${{ matrix.target }}/release/serpapi-${{ matrix.target }}.exe.zip
target/${{ matrix.target }}/release/serpapi-${{ matrix.target }}.exe.zip.sha256
create-release:
name: Create GitHub Release
runs-on: ubuntu-latest
needs: release
if: startsWith(github.ref, 'refs/tags/v')
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Create release
uses: softprops/action-gh-release@v1
with:
draft: false
prerelease: false
generate_release_notes: true
files: |
artifacts/serpapi-x86_64-unknown-linux-gnu/*
artifacts/serpapi-aarch64-unknown-linux-gnu/*
artifacts/serpapi-x86_64-apple-darwin/*
artifacts/serpapi-aarch64-apple-darwin/*
artifacts/serpapi-x86_64-pc-windows-msvc/*