-
Notifications
You must be signed in to change notification settings - Fork 7
252 lines (201 loc) Β· 7.25 KB
/
releases.yml
File metadata and controls
252 lines (201 loc) Β· 7.25 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
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
name: Releases
on:
push:
branches: [main]
env:
CARGO_TERM_COLOR: always
jobs:
check:
name: Checking if a release exists
runs-on: ubuntu-latest
outputs:
needs-release: ${{steps.check.outputs.needs-release}}
version: ${{steps.version.outputs.version}}
steps:
- name: Checkout the repo
uses: actions/checkout@v4
- name: Compute version
id: version
run: |
version=$(cargo pkgid -p zpm-switch | cut -d "#" -f2)
echo "version=$version" >> $GITHUB_OUTPUT
- name: Check if release exists
id: check
run: |
if gh release view "v${{steps.version.outputs.version}}" >/dev/null 2>&1; then
echo "needs-release=false" >> $GITHUB_OUTPUT
echo "Release v${{ steps.version.outputs.version }} already exists"
else
echo "needs-release=true" >> $GITHUB_OUTPUT
echo "Release v${{ steps.version.outputs.version }} does not exist"
fi
env:
GH_TOKEN: ${{github.token}}
build:
if: needs.check.outputs.needs-release == 'true'
needs: check
strategy:
matrix:
include:
- target: x86_64-unknown-linux-musl
os: ubuntu-latest
- target: aarch64-unknown-linux-musl
os: ubuntu-latest
- target: i686-unknown-linux-musl
os: ubuntu-latest
- target: aarch64-apple-darwin
os: macos-latest
name: 'Building ${{matrix.target}}'
runs-on: ${{matrix.os}}
steps:
- name: Checkout the repo
uses: actions/checkout@v4
- uses: ./.github/actions/build
id: build
with:
target: ${{matrix.target}}
profile: release-lto-nodebug
version: ${{needs.check.outputs.version}}
- name: Generate the archive files
run: |
zip -jX yarn-${{matrix.target}}.zip target/${{matrix.target}}/release-lto-nodebug/{yarn-bin,yarn,LICENSE.md}
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: yarn-${{matrix.target}}
path: |
yarn-${{matrix.target}}.zip
release:
needs: [check, build]
name: 'Creating a release'
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout the repo
uses: actions/checkout@v4
- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
merge-multiple: true
- name: Create GitHub Release
run: |
PRERELEASE_OPTIONS=
if [[ '${{needs.check.outputs.version}}' =~ - ]]; then
PRERELEASE_OPTIONS=--prerelease
fi
gh release create "v${{needs.check.outputs.version}}" \
--title "v${{needs.check.outputs.version}}" \
--notes "Release of v${{needs.check.outputs.version}}" \
--target ${{github.ref}} \
$PRERELEASE_OPTIONS \
artifacts/*
env:
GH_TOKEN: ${{github.token}}
npm:
needs: [check, build]
name: 'Publishing to npm'
runs-on: ubuntu-latest
environment: releases
permissions:
contents: read
id-token: write
steps:
- name: Checkout the repo
uses: actions/checkout@v4
- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
merge-multiple: true
- name: Unpack the build of Yarn we just created
uses: actions/github-script@v8
env:
VERSION: ${{needs.check.outputs.version}}
with:
script: |
const cp = require(`child_process`);
const fs = require(`fs`);
const path = require(`path`);
const artifacts = fs.readdirSync(`artifacts`, {
withFileTypes: true,
});
function includes(str, search) {
return str.split(/-/).includes(search);
}
function findFirst(str, map) {
return Object.entries(map).find(([, value]) => includes(str, value))[0];
}
for (const artifact of artifacts) {
if (!artifact.isFile() || !artifact.name.startsWith('yarn-'))
continue;
const targetName = artifact.name.replace(`.zip`, ``);
const destinationPath = path.join(artifact.parentPath, targetName);
const sourcePath = path.join(artifact.parentPath, artifact.name);
cp.execFileSync(`unzip`, [`-d`, destinationPath, sourcePath]);
const ext = includes(targetName, `windows`) ? `.exe` : ``;
// We don't need to distribute Yarn Switch itself
fs.unlinkSync(path.join(destinationPath, `yarn`));
// Rename the binary to `yarn`
fs.renameSync(path.join(destinationPath, `yarn-bin${ext}`), path.join(destinationPath, `yarn${ext}`));
// Make it executable
fs.chmodSync(path.join(destinationPath, `yarn${ext}`), 0o755);
const cpu = findFirst(targetName, {
x64: `x86_64`,
arm64: `aarch64`,
ia32: `i686`,
});
const os = findFirst(targetName, {
linux: `linux`,
darwin: `darwin`,
});
fs.writeFileSync(path.join(destinationPath, `package.json`), `${JSON.stringify({
name: `@yarnpkg/${targetName}`,
version: process.env.VERSION,
license: `GPL-3.0`,
cpu: [cpu],
os: [os],
bin: {
yarn: `yarn${ext}`,
},
repository: {
type: `git`,
url: `git+https://github.com/yarnpkg/zpm.git`,
},
}, null, 2)}\n`);
fs.writeFileSync(path.join(destinationPath, `yarn.lock`), ``);
}
- name: Add the bin directory to the PATH
run: |
echo "$PWD/artifacts/yarn-x86_64-unknown-linux-musl" >> $GITHUB_PATH
- name: Generate the packages
uses: actions/github-script@v8
env:
YARN_NPM_AUTH_TOKEN: ${{secrets.TEMPORARY_NPM_PUBLISH_TOKEN}}
with:
script: |
const cp = require(`child_process`);
const fs = require(`fs`);
const path = require(`path`);
const artifacts = fs.readdirSync(`artifacts`, {
withFileTypes: true,
});
for (const artifact of artifacts) {
if (!artifact.isDirectory() || !artifact.name.startsWith('yarn-'))
continue;
const artifactPath = path.join(artifact.parentPath, artifact.name);
console.log(`Publishing ${artifactPath}`);
cp.execFileSync(`yarn`, [`install`], {
stdio: `inherit`,
cwd: artifactPath,
});
cp.execFileSync(`yarn`, [`npm`, `whoami`], {
stdio: `inherit`,
cwd: artifactPath,
});
cp.execFileSync(`yarn`, [`npm`, `publish`, `--access`, `public`], {
stdio: `inherit`,
cwd: artifactPath,
});
}