-
-
Notifications
You must be signed in to change notification settings - Fork 680
125 lines (104 loc) · 3.96 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
name: release
on:
push:
paths:
- ".changeset/**"
- ".github/**"
- "packages/**"
- "package.json"
- "package-lock.json"
branches:
- main
jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 20
cache: npm
- name: Install dependencies
run: npm ci
- name: Download Turborepo cache
uses: actions/cache@v3
with:
path: node_modules/.cache/turbo
key: ${{ runner.os }}-node-20-turbo-${{ hashFiles('node_modules/.cache/turbo') }}
restore-keys: |
${{ runner.os }}-node-20-turbo-
- name: Check types
run: npm run tsc
- name: Build packages
run: npm run build
- name: Run tests
run: npm run test -- --ci --maxWorkers=2
- name: Create Release Pull Request or Publish Packages
id: changesets
uses: changesets/action@v1
with:
version: npm run changeset:version
publish: npm run changeset:publish
commit: "chore(release): version packages"
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Pack Dist Archive
run: npm run build:archive
- name: Upload Release Assets
uses: actions/github-script@v7
with:
script: |
const fs = require("fs");
const { owner, repo } = context.repo;
const distFile = "dist.zip";
const assetName = "jspsych.zip";
/**
* Returns all recent releases without a dist archive asset, up to (excluding) the first release
* that has a dist archive asset.
**/
async function fetchReleasesWithoutDistArchive() {
const releasesWithoutDistArchive = [];
for await (const response of github.paginate.iterator(github.rest.repos.listReleases, {
owner,
repo,
})) {
for (const release of response.data) {
if (!release.assets.some((asset) => asset.name === assetName)) {
releasesWithoutDistArchive.push(release);
} else {
return releasesWithoutDistArchive;
}
}
}
return releasesWithoutDistArchive;
}
console.log("Collecting recent releases that do not have a dist archive");
const releasesWithoutDistArchive = await fetchReleasesWithoutDistArchive();
if (releasesWithoutDistArchive.length === 0) {
console.log("The most recent release already has a dist archive. Skipping asset upload.");
return;
}
console.log(`Found ${releasesWithoutDistArchive.length} recent releases without a dist archive.`);
const distFileSize = fs.statSync(distFile).size;
const distFileContents = fs.readFileSync(distFile);
// Upload dist archive for each release without a dist archive, in reverse order so re-running an
// aborted or failed job will pick up where it left off last time
for (const release of releasesWithoutDistArchive.reverse()) {
console.log(`Uploading dist archive release asset for ${release.tag_name}`);
// https://octokit.github.io/rest.js/v20#repos-upload-release-asset
await github.rest.repos.uploadReleaseAsset({
owner,
repo,
release_id: release.id,
name: assetName,
label: "Dist archive (zip)",
headers: {
"content-type": "application/zip",
"content-length": distFileSize,
},
data: distFileContents,
});
}