-
Notifications
You must be signed in to change notification settings - Fork 1
268 lines (252 loc) · 8.08 KB
/
release.yml
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
name: Release
on:
release:
types: [published]
jobs:
unit-testing:
name: Unit testing
strategy:
matrix:
include:
# Linux targets
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
# Windows targets
- os: windows-latest
target: x86_64-pc-windows-msvc
- os: windows-latest
target: i686-pc-windows-msvc
# macOS targets
- os: macos-14
target: aarch64-apple-darwin
- os: macos-13
target: x86_64-apple-darwin
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
override: true
target: ${{ matrix.target }}
- name: Run tests
run: |
cargo test --workspace --exclude e2e -- --nocapture
env:
RUST_BACKTRACE: full
build:
needs: unit-testing
strategy:
matrix:
include:
# Linux targets
- os: ubuntu-latest
target: x86_64-unknown-linux-musl
# target: x86_64-unknown-linux-gnu
# - os: ubuntu-latest
# target: i686-unknown-linux-gnu
# - os: ubuntu-latest
# target: aarch64-unknown-linux-gnu
# Windows targets
- os: windows-latest
target: x86_64-pc-windows-msvc
- os: windows-latest
target: i686-pc-windows-msvc
# macOS targets
- os: macos-14
target: aarch64-apple-darwin
- os: macos-13
target: x86_64-apple-darwin
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
- name: Checkout Code
uses: actions/checkout@v3
- name: Install Dependencies
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install -y openssl pkg-config libssl-dev musl-tools
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
profile: minimal
override: true
target: ${{ matrix.target }}
- name: Build Binary
uses: actions-rs/cargo@v1
with:
command: build
args: --verbose --release --target ${{ matrix.target }}
- name: Strip Binary (Linux and macOS only)
if: matrix.os != 'windows-latest'
run: |
for file in snm node npm npx pnpm pnpx yarn; do
strip "target/${{ matrix.target }}/release/$file"
done
- name: Create Archive
shell: bash
run: |
mkdir archive
cp LICENSE README.md target/${{ matrix.target }}/release/{node,npm,npx,pnpm,pnpx,snm,yarn} archive/
tar -czf ${{ matrix.target }}.tar.gz -C archive LICENSE README.md node npm npx pnpm pnpx snm yarn
ls -l
- name: Calculate SHA256 Checksum
run: |
echo "Calculating SHA256 for ${{ matrix.target }}.tar.gz..."
if [ "${{ matrix.os }}" == "windows-latest" ]; then
certutil -hashfile "${{ matrix.target }}.tar.gz" SHA256 > "${{ matrix.target }}.sha256"
else
shasum -a 256 ${{ matrix.target }}.tar.gz | tee ${{ matrix.target }}.sha256
fi
cat ${{ matrix.target }}.sha256
shell: bash
- name: Upload Artifacts tar.gz
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.target }}
path: ${{ matrix.target }}.tar.gz
- name: Upload Artifacts sha256
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.target }}.sha256
path: ${{ matrix.target }}.sha256
e2e-testing:
name: E2E testing
needs: build
strategy:
matrix:
include:
# Linux targets
- os: ubuntu-latest
target: x86_64-unknown-linux-musl
# Windows targets
# - os: windows-latest
# target: x86_64-pc-windows-msvc
# - os: windows-latest
# target: i686-pc-windows-msvc
# macOS targets
- os: macos-14
target: aarch64-apple-darwin
- os: macos-13
target: x86_64-apple-darwin
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
override: true
target: ${{ matrix.target }}
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: ${{ matrix.target }}
path: .
- name: Tar downloaded files
shell: bash
run: |
tar -xvf ${{ matrix.target }}.tar.gz -C e2e/tests
cd e2e/tests
ls -R
- name: e2e tests
run: |
cargo test --package e2e -- --nocapture
publish:
name: Publish To Github Release
runs-on: ubuntu-latest
needs: e2e-testing
steps:
- uses: actions/download-artifact@v4
- name: Display structure of downloaded files
run: ls -R
- name: Upload Release Asset
id: upload-release-asset
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
with:
name: ${{ github.ref_name }}
files: |
**/*.tar.gz
**/*.sha256
generate-homebrew-formula:
permissions:
contents: write
name: Generate And Upload Homebrew snm.rb File
runs-on: ubuntu-latest
needs: publish
steps:
- uses: actions/download-artifact@v4
with:
path: .
- name: Display structure of downloaded files
run: |
ls -R
cd x86_64-apple-darwin.sha256
cat x86_64-apple-darwin.sha256
- name: Generate Homebrew Formula
run: |
VERSION=${{ github.ref_name }}
SHA256_INTEL=$(cat x86_64-apple-darwin.sha256/x86_64-apple-darwin.sha256 | awk '{print $1}')
SHA256_ARM=$(cat aarch64-apple-darwin.sha256/aarch64-apple-darwin.sha256 | awk '{print $1}')
cat <<EOF > snm.rb
class Snm < Formula
desc "snm = corepack + fnm + ni ."
homepage "https://github.com/sheinsight/snm"
version "$VERSION"
if Hardware::CPU.intel?
url "https://github.com/sheinsight/snm/releases/download/$VERSION/x86_64-apple-darwin.tar.gz"
sha256 "$SHA256_INTEL"
elsif Hardware::CPU.arm?
url "https://github.com/sheinsight/snm/releases/download/$VERSION/aarch64-apple-darwin.tar.gz"
sha256 "$SHA256_ARM"
end
license "MIT"
def install
bin.install "snm", "pnpx", "pnpm", "npx", "npm", "yarn", "node"
end
test do
system "#{bin}/snm", "--version"
end
end
EOF
- name: Upload artifacts snm.rb
uses: actions/upload-artifact@v4
with:
name: snm.rb
path: snm.rb
create-pull-request:
name: Create Homebrew Pull Request
runs-on: ubuntu-latest
needs: generate-homebrew-formula
steps:
- name: Checkout repository B
uses: actions/checkout@v3
with:
repository: sheinsight/homebrew-shined
token: ${{ secrets.HOMEBREW_GITHUB_TOKEN }}
path: .
- uses: actions/download-artifact@v4
with:
name: snm.rb
path: .
- name: Display structure of downloaded files
run: ls -R
- name: Create Pull Request
uses: peter-evans/create-pull-request@v4
with:
token: ${{ secrets.HOMEBREW_GITHUB_TOKEN }}
commit-message: Auto-generated PR from repository A
title: 'update snm to version ${{ github.ref_name }}'
body: |
This pull request is auto-generated by GitHub Actions from repository A.
add-paths: snm.rb
branch: update-snm-rb-${{ github.ref_name }}
base: main