Skip to content

Commit 838ef37

Browse files
committed
Add a new action that rebuilds the tabs for the devserver if necessary
1 parent 5583e18 commit 838ef37

File tree

12 files changed

+900
-105
lines changed

12 files changed

+900
-105
lines changed

.github/actions/build.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const buildCommand = getBuildCommand({
55
bundle: true,
66
entryPoints: [
77
{ in: './src/info/index.ts', out: 'info' },
8+
{ in: './src/load-artifacts/index.ts', out: 'load' },
89
],
910
format: 'esm',
1011
outdir: 'dist',

.github/actions/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"vitest": "^3.2.3"
1010
},
1111
"dependencies": {
12+
"@actions/artifact": "^2.3.2",
1213
"@actions/core": "^1.11.1",
1314
"@actions/exec": "^1.1.1",
1415
"lodash": "^4.17.21"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
name: Load Artifacts for Dev Server
2+
description: This action is mainly intended for loading all of the compiled tabs for the devserver.
3+
4+
runs:
5+
using: node20
6+
main: ../../dist/load.js
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import pathlib from 'path';
2+
import { DefaultArtifactClient } from '@actions/artifact';
3+
import * as core from '@actions/core';
4+
import { exec } from '@actions/exec';
5+
import { bundlesDir, outDir, tabsDir } from '@sourceacademy/modules-repotools/getGitRoot';
6+
import { resolveAllTabs } from '@sourceacademy/modules-repotools/manifest';
7+
8+
async function main() {
9+
const artifact = new DefaultArtifactClient();
10+
const tabsResult = await resolveAllTabs(bundlesDir, tabsDir);
11+
12+
if (tabsResult.severity === 'error') {
13+
core.startGroup('Tab Resolution errors');
14+
for (const error of tabsResult.errors) {
15+
core.error(error);
16+
}
17+
core.endGroup();
18+
core.setFailed('Tab resolution failed with errors');
19+
return;
20+
}
21+
22+
const tabPromises = Object.keys(tabsResult.tabs).map(async tabName => {
23+
try {
24+
const { artifact: { id } } = await artifact.getArtifact(`${tabName}-tab`);
25+
await artifact.downloadArtifact(id, { path: pathlib.join(outDir, 'tabs', `${tabName}.js`) });
26+
core.info(`Downloaded artifact for ${tabName}`);
27+
} catch {}
28+
29+
core.info(`Error retrieving artifact for ${tabName}, will try building`);
30+
// Artifact could not be found, we probably need to build it
31+
const focusExitCode = await exec('yarn', ['workspaces', 'focus', `@sourceacademy/tab-${tabName}`]);
32+
if (focusExitCode !== 0) {
33+
core.setFailed(`yarn workspace focus failed for ${tabName}`);
34+
return;
35+
}
36+
37+
const buildExitCode = await exec('yarn', ['workspaces', 'foreach', '-A', '--include', `@sourceacademy/tab-${tabName}`, 'run', 'build']);
38+
if (buildExitCode !== 0) {
39+
core.setFailed(`Building ${tabName} failed`);
40+
return;
41+
}
42+
core.info(`Built ${tabName}`);
43+
});
44+
45+
await Promise.all(tabPromises);
46+
}
47+
48+
if (process.env.GITHUB_ACTIONS) {
49+
// Only automatically execute when running in github actions
50+
try {
51+
await main();
52+
} catch (error: any) {
53+
core.setFailed(error.message);
54+
}
55+
}

.github/workflows/pull-request.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,13 @@ jobs:
109109
cd ${{ matrix.tabInfo.directory }}
110110
yarn build
111111
112+
- name: Upload Tab Artifact
113+
if: matrix.tabInfo.changes
114+
uses: actions/upload-artifact@v4
115+
with:
116+
name: ${{ matrix.tabInfo.tabName }}-tab
117+
path: ./build/tabs/${{ matrix.tabInfo.tabName }}.js
118+
112119
- name: Run Tests
113120
# https://github.com/vitest-dev/vitest/issues/5477
114121
# Known Vitest issue for coverage running in browser mode
@@ -183,8 +190,11 @@ jobs:
183190
package-name: '@sourceacademy/modules-devserver'
184191
playwright: true
185192

186-
- name: Build all tabs
187-
run: yarn workspaces foreach -ptW --from "./src/tabs/*" run build
193+
- name: Install dependencies for other actions
194+
run: yarn workspaces focus @sourceacademy/modules-github-actions
195+
196+
- name: Load/Build all tabs
197+
uses: ./.github/actions/src/load-artifacts
188198

189199
- name: Run tests
190200
run: |

.husky/post-checkout

Lines changed: 0 additions & 1 deletion
This file was deleted.

.husky/post-merge

Lines changed: 0 additions & 1 deletion
This file was deleted.

.husky/post-rewrite

Lines changed: 0 additions & 1 deletion
This file was deleted.

.yarn/patches/uniqid-npm-5.4.0-f982bda028.patch

Lines changed: 0 additions & 76 deletions
This file was deleted.

lib/buildtools/src/commands/prebuild.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const getLintCommand = () => new Command('lint')
2424
const resolveResult = await resolveEitherBundleOrTab(fullyResolved);
2525

2626
if (resolveResult.severity === 'error') {
27-
if (resolveResult.errors.length === 0 ) {
27+
if (resolveResult.errors.length === 0) {
2828
logCommandErrorAndExit(`No tab or bundle found at ${fullyResolved}`);
2929
}
3030

@@ -86,7 +86,7 @@ export const getTscCommand = () => new Command('tsc')
8686
const resolveResult = await resolveEitherBundleOrTab(fullyResolved);
8787

8888
if (resolveResult.severity === 'error') {
89-
if (resolveResult.errors.length === 0 ) {
89+
if (resolveResult.errors.length === 0) {
9090
logCommandErrorAndExit(`No tab or bundle found at ${fullyResolved}`);
9191
}
9292

@@ -107,14 +107,14 @@ export const getTscCommand = () => new Command('tsc')
107107
});
108108

109109
export const getPrebuildAllCommand = () => new Command('prebuild')
110-
.argument('[directory]', 'Directory to prebuild tasks in', process.cwd())
110+
.argument('[directory]', 'Directory to run prebuild tasks in', process.cwd())
111111
.option('--ci', process.env.CI)
112112
.action(async (directory, { ci }) => {
113113
const fullyResolved = pathlib.resolve(directory);
114114
const resolveResult = await resolveEitherBundleOrTab(fullyResolved);
115115

116116
if (resolveResult.severity === 'error') {
117-
if (resolveResult.errors.length === 0 ) {
117+
if (resolveResult.errors.length === 0) {
118118
logCommandErrorAndExit(`No tab or bundle found at ${fullyResolved}`);
119119
}
120120

0 commit comments

Comments
 (0)