Skip to content

Commit f79cc85

Browse files
committed
Test a new workflow
1 parent c25dd65 commit f79cc85

File tree

16 files changed

+371
-77
lines changed

16 files changed

+371
-77
lines changed

.github/actions/info/action.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: Package Info
2+
description: Gets which packages are currently present in the repository
3+
4+
inputs:
5+
type:
6+
description: Which type of packages to find
7+
required: true
8+
9+
outputs:
10+
packages:
11+
description: The list of packages present
12+
13+
runs:
14+
using: node22
15+
main: ./dist.js

.github/actions/info/build.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import getBuildCommand from '@sourceacademy/modules-repotools/builder';
2+
3+
const buildCommand = getBuildCommand({
4+
bundle: true,
5+
entryPoints: ['./index.ts'],
6+
format: 'esm',
7+
outfile: './dist.js',
8+
packages: 'external'
9+
});
10+
11+
await buildCommand.parseAsync();

.github/actions/info/dist.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// index.ts
2+
import fs from "fs/promises";
3+
import pathlib from "path";
4+
import * as core from "@actions/core";
5+
import { getExecOutput } from "@actions/exec";
6+
async function findPackages(directory, maxDepth) {
7+
async function* recurser(currentDir, currentDepth) {
8+
if (maxDepth !== void 0 && currentDepth >= maxDepth) return;
9+
const items = await fs.readdir(currentDir, { withFileTypes: true });
10+
for (const item of items) {
11+
const fullPath = pathlib.join(currentDir, item.name);
12+
if (item.isFile()) {
13+
if (item.name === "package.json") {
14+
yield fullPath;
15+
}
16+
continue;
17+
}
18+
if (item.isDirectory() && item.name !== "node__modules") {
19+
yield* recurser(fullPath, currentDepth + 1);
20+
}
21+
}
22+
}
23+
return Array.fromAsync(recurser(directory, 0));
24+
}
25+
async function main() {
26+
const { stdout } = await getExecOutput("git", ["rev-parse", "--show-toplevel"]);
27+
const gitRoot = stdout.trim();
28+
const packageType = core.getInput("type", { required: true });
29+
let dirPath;
30+
switch (packageType) {
31+
case "lib": {
32+
dirPath = pathlib.join(gitRoot, "lib");
33+
break;
34+
}
35+
case "bundles": {
36+
dirPath = pathlib.join(gitRoot, "src", "bundles");
37+
break;
38+
}
39+
case "tabs": {
40+
dirPath = pathlib.join(gitRoot, "src", "tabs");
41+
break;
42+
}
43+
default: {
44+
core.error(`Invalid package type: ${packageType}. Must be lib, bundles or tabs`);
45+
return;
46+
}
47+
}
48+
const packages = await findPackages(dirPath);
49+
core.setOutput("packages", packages);
50+
}
51+
await main();

.github/actions/info/index.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import fs from 'fs/promises';
2+
import pathlib from 'path';
3+
import * as core from '@actions/core';
4+
import { getExecOutput } from '@actions/exec';
5+
6+
/**
7+
* Recursively locates the packages present in a directory, up to an optional max depth
8+
*/
9+
async function findPackages(directory: string, maxDepth?: number) {
10+
async function* recurser(currentDir: string, currentDepth: number): AsyncGenerator<string> {
11+
if (maxDepth !== undefined && currentDepth >= maxDepth) return;
12+
13+
const items = await fs.readdir(currentDir, { withFileTypes: true });
14+
for (const item of items) {
15+
const fullPath = pathlib.join(currentDir, item.name);
16+
if (item.isFile()) {
17+
if (item.name === 'package.json') {
18+
yield fullPath;
19+
}
20+
continue;
21+
}
22+
23+
if (item.isDirectory() && item.name !== 'node_modules') {
24+
yield* recurser(fullPath, currentDepth + 1);
25+
}
26+
}
27+
}
28+
29+
return Array.fromAsync(recurser(directory, 0));
30+
}
31+
32+
async function main() {
33+
const { stdout } = await getExecOutput('git', ['rev-parse', '--show-toplevel']);
34+
const gitRoot = stdout.trim();
35+
36+
const packageType = core.getInput('type', { required: true });
37+
38+
let dirPath: string;
39+
switch (packageType) {
40+
case 'lib': {
41+
dirPath = pathlib.join(gitRoot, 'lib');
42+
break;
43+
}
44+
case 'bundles': {
45+
dirPath = pathlib.join(gitRoot, 'src', 'bundles');
46+
break;
47+
}
48+
case 'tabs': {
49+
dirPath = pathlib.join(gitRoot, 'src', 'tabs');
50+
break;
51+
}
52+
default: {
53+
core.error(`Invalid package type: ${packageType}. Must be lib, bundles or tabs`);
54+
return;
55+
}
56+
}
57+
58+
const packages = await findPackages(dirPath);
59+
core.setOutput('packages', packages);
60+
}
61+
62+
try {
63+
await main();
64+
} catch (error: any) {
65+
core.setFailed(error.message);
66+
}

.github/actions/info/package.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "@sourceacademy/modules-info-action",
3+
"private": true,
4+
"type": "module",
5+
"devDependencies": {
6+
"@sourceacademy/modules-repotools": "workspace:^",
7+
"@types/node": "^22.15.30",
8+
"typescript": "^5.8.2"
9+
},
10+
"dependencies": {
11+
"@actions/core": "^1.11.1",
12+
"@actions/exec": "^1.1.1"
13+
},
14+
"scripts": {
15+
"build": "node ./build.js"
16+
}
17+
}

.github/actions/info/tsconfig.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"include": ["./index.ts"],
3+
"compilerOptions": {
4+
"forceConsistentCasingInFileNames": true,
5+
"lib": ["esnext"],
6+
"module": "esnext",
7+
"moduleResolution": "bundler",
8+
"noEmit": true,
9+
"strict": true,
10+
"target": "esnext",
11+
"verbatimModuleSyntax": true
12+
}
13+
}

.github/workflows/new-workflow.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: new-workflow
2+
3+
permissions:
4+
contents: read
5+
6+
on:
7+
pull_request:
8+
branches:
9+
- master
10+
11+
jobs:
12+
load-packages:
13+
name: Determine the packages present in the repo for the given type
14+
runs-on: ubuntu-latest
15+
strategy:
16+
matrix:
17+
type: ['lib', 'bundles', 'tabs']
18+
19+
steps:
20+
- name: Check out source code
21+
uses: actions/checkout@v4
22+
23+
- name: Use Node.js 💻
24+
uses: actions/setup-node@v4
25+
with:
26+
node-version-file: .node-version
27+
cache: yarn
28+
29+
- name: Find Packages
30+
id: find
31+
uses: ./.github/actions/info
32+
with:
33+
type: ${{ matrix.type }}
34+
35+
- name: Print
36+
run: echo ${{ steps.find.outputs }}

.github/workflows/pull-request.yml

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
name: on-pull-request
2+
3+
permissions:
4+
contents: read
5+
26
on:
37
pull_request:
48
branches:
@@ -41,6 +45,31 @@ jobs:
4145
docs: ${{ steps.filter.outputs.docs || steps.filter.outputs.workflows }}
4246
playwright: ${{ steps.filter.outputs.devserver || steps.filter.outputs.libraries || steps.filter.outputs.tabs }}
4347

48+
job-creator:
49+
name: Determine what jobs to run
50+
runs-on: ubuntu-latest
51+
steps:
52+
# Determine which paths and thus which bu
53+
- name: Filter paths
54+
uses: dorny/paths-filter@v3
55+
id: filter
56+
with:
57+
filters: |
58+
workflows:
59+
- .github/workflows/**
60+
devserver:
61+
- 'devserver/**'
62+
libraries:
63+
- 'lib/**'
64+
tabs:
65+
- src/tabs/**
66+
bundles:
67+
- src/bundles/**
68+
docs:
69+
- docs/**
70+
71+
72+
4473
test:
4574
name: Verify that all tests, linting, type-checking and building succeeds.
4675
runs-on: ubuntu-latest
@@ -59,11 +88,13 @@ jobs:
5988
- name: Use Node.js 💻
6089
uses: actions/setup-node@v4
6190
with:
62-
node-version: 22
91+
node-version-file: .node-version
6392
cache: yarn
6493

65-
# - name: Setup Repotools
66-
# run: yarn workspaces focus @sourceacademy/modules-repotools && yarn workspaces foreach -A --include "@sourceacademy/modules-repotools" run build
94+
# For whatever reason, repotools refuses to install correctly, so we have to install it separately and
95+
# build it in its entirety before proceeding with installing everything else
96+
- name: Setup Repotools
97+
run: yarn workspaces focus @sourceacademy/modules-repotools && yarn workspaces foreach -A --include "@sourceacademy/modules-repotools" run build
6798

6899
- name: Install dependencies
69100
run: yarn install --immutable

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"files.insertFinalNewline": true,
33
"json.schemas": [
44
{
5-
"fileMatch": ["src/bundles/**/manifest.json"],
5+
"fileMatch": ["src/bundles/*/manifest.json"],
66
"url": "./lib/repotools/src/manifest.schema.json"
77
},
88
{

eslint.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ export default tseslint.config(
2525
'**/*.snap',
2626
'**/*.d.ts',
2727
'**/dist/**',
28+
'**/dist.*js',
2829
'.yarn',
2930
'build/**',
3031
'docs/.vitepress/cache',
3132
'devserver/vite.config.ts', // Don't lint this because there's no tsconfig properly configured for it
3233
'lib/buildtools/bin',
3334
'lib/buildtools/src/build/__test_mocks__',
34-
'lib/*/dist.*js',
3535
'src/**/samples/**',
3636
'src/bundles/scrabble/src/words.json', // Don't lint this because its way too big
3737
'src/java/**',
@@ -337,6 +337,7 @@ export default tseslint.config(
337337
files: [
338338
'lib/buildtools/**/*.ts',
339339
'lib/repotools/**/*.ts',
340+
'.github.actions/**/*.ts',
340341
'**/vitest.config.js'
341342
],
342343
rules: {

0 commit comments

Comments
 (0)