forked from jspsych/jsPsych
-
Notifications
You must be signed in to change notification settings - Fork 1
110 lines (96 loc) · 3.44 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
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@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 18
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-18-turbo-${{ hashFiles('node_modules/.cache/turbo') }}
restore-keys: |
${{ runner.os }}-node-18-turbo-
- name: Check types
run: npm run tsc
- 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
if: steps.changesets.outputs.published == 'true'
run: npm run build:archive
- name: Upload Release Assets
uses: actions/github-script@v4
if: steps.changesets.outputs.published == 'true'
with:
script: |
const fs = require("fs");
const publishedPackages = ${{ steps.changesets.outputs.publishedPackages }};
const { owner, repo } = context.repo;
const distFile = "dist.zip";
let errorMessage;
for (const { name, version } of publishedPackages) {
const tag = `${name}@${version}`;
// Only upload the dist archive for the core package, plugins, and extensions
if (name === "jspsych" || name.includes("/plugin-") || name.includes("/extension-")) {
console.log(`Uploading dist archive release asset for ${tag}`);
try {
// https://docs.github.com/en/rest/reference/repos#get-a-release-by-tag-name
const releaseId = (
await github.request("GET /repos/{owner}/{repo}/releases/tags/{tag}", {
owner,
repo,
tag,
})
).data.id;
// https://octokit.github.io/rest.js/v18#repos-upload-release-asset
await github.repos.uploadReleaseAsset({
owner,
repo,
release_id: releaseId,
name: `jspsych.zip`,
label: "Dist archive (zip)",
headers: {
"content-type": "application/zip",
"content-length": fs.statSync(distFile).size,
},
data: fs.readFileSync(distFile),
});
} catch (error) {
console.log(error);
errorMessage = error.message;
}
}
}
if (errorMessage) {
core.setFailed(errorMessage);
} else {
console.log(`Release assets successfully uploaded`);
}