Skip to content

Commit 1cf20f6

Browse files
authored
feat: build license file for vscode-webdriverio (#74)
1 parent f3d922f commit 1cf20f6

9 files changed

Lines changed: 1982 additions & 1003 deletions

File tree

.github/workflows/ci-license.yml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: Check license updates
2+
3+
on:
4+
workflow_call:
5+
# Make this a reusable workflow, no value needed
6+
# https://docs.github.com/en/actions/using-workflows/reusing-workflows
7+
8+
env:
9+
TURBO_TELEMETRY_DISABLED: 1
10+
11+
jobs:
12+
license-check:
13+
name: License Check
14+
runs-on: 'ubuntu-latest'
15+
permissions:
16+
pull-requests: write
17+
steps:
18+
- name: 👷 Checkout
19+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
20+
21+
- name: 🛠️ Setup workspace
22+
uses: ./.github/actions/setup-workspace
23+
with:
24+
node-version: '20'
25+
26+
- name: ⬇️ Download Build Archive
27+
uses: ./.github/actions/download-archive
28+
with:
29+
name: vscode-webdriverio
30+
path: .
31+
filename: vscode-webdriverio-build.zip
32+
33+
- name: 📃 Generate License file
34+
run: pnpm --filter @vscode-wdio/compiler build -p vscode-webdriverio -l
35+
shell: bash
36+
37+
- name: ✅ Check status
38+
id: check
39+
run: |
40+
if [[ $(git status --short | grep -c -v vscode-webdriverio-build.zip) -ne 0 ]]; then
41+
STATUS=$(git status --verbose); printf "%s" "$STATUS"; git diff | cat
42+
echo "result=1" >> $GITHUB_OUTPUT
43+
else
44+
echo "result=0" >> $GITHUB_OUTPUT
45+
fi
46+
shell: bash
47+
48+
- uses: marocchino/sticky-pull-request-comment@52423e01640425a022ef5fd42c6fb5f633a02728 # v2.9.1
49+
if: ${{ steps.check.outputs.result > 0 }}
50+
with:
51+
header: license-error
52+
message: >
53+
Thank you for creating PR!🙏
54+
55+
It is likely that the license file needs to be updated due to changes in dependencies.
56+
57+
Please run following commands at project root directory.
58+
```
59+
$ pnpm run build
60+
61+
$ git add packages/vscode-webdriverio/LICENSE.md
62+
63+
$ git commit
64+
```
65+
66+
If you have any questions please reach out to us on our [Discord](https://discord.webdriver.io/)
67+
channel. We are happy to help you out there.
68+
69+
- name: 💥 Exit with error
70+
if: ${{ steps.check.outputs.result > 0 }}
71+
run: exit 1
72+
73+
- uses: marocchino/sticky-pull-request-comment@52423e01640425a022ef5fd42c6fb5f633a02728 # v2.9.1
74+
if: ${{ steps.check.outputs.result == 0 }}
75+
with:
76+
header: license-error
77+
delete: true

.github/workflows/ci.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ concurrency:
1313
group: ci-${{ github.workflow }}-${{ github.ref }}
1414
cancel-in-progress: true
1515

16+
permissions:
17+
pull-requests: write
18+
1619
jobs:
1720
build:
1821
name: Build
@@ -29,6 +32,11 @@ jobs:
2932
needs: [lint, build]
3033
uses: ./.github/workflows/ci-typecheck.yml
3134

35+
license-check:
36+
name: License Check
37+
needs: [lint, build]
38+
uses: ./.github/workflows/ci-license.yml
39+
3240
unit:
3341
name: Unit
3442
needs: [lint, build]
@@ -48,21 +56,21 @@ jobs:
4856

4957
smoke-config:
5058
name: Smoke - Update Config
51-
needs: [lint, build, e2e]
59+
needs: [lint, build, unit, license-check, typecheck, e2e]
5260
uses: ./.github/workflows/ci-smoke.yml
5361
with:
5462
scenario: 'config'
5563

5664
smoke-timeout:
5765
name: Smoke - Worker idle timeout
58-
needs: [lint, build, e2e]
66+
needs: [lint, build, unit, license-check, typecheck, e2e]
5967
uses: ./.github/workflows/ci-smoke.yml
6068
with:
6169
scenario: 'timeout'
6270

6371
smoke-env:
6472
name: Smoke - Load .env files
65-
needs: [lint, build, e2e]
73+
needs: [lint, build, unit, license-check, typecheck, e2e]
6674
uses: ./.github/workflows/ci-smoke.yml
6775
with:
6876
scenario: 'env'

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,8 @@
1919
},
2020
"[typescript]": {
2121
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
22+
},
23+
"[markdown]": {
24+
"files.trimTrailingWhitespace": false
2225
}
2326
}

infra/compiler/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
"build": "tsx ./src/index.ts"
77
},
88
"dependencies": {
9+
"chalk": "^5.4.1",
910
"esbuild": "^0.25.0",
11+
"fdir": "^6.4.6",
1012
"type-fest": "^4.24.0"
1113
}
1214
}

infra/compiler/src/index.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { parseArgs } from 'node:util'
55

66
import { context } from 'esbuild'
77

8+
import { generateLicense } from './license.js'
89
import { esbuildProblemMatcherPlugin } from './plugins.js'
910

1011
import type { PackageJson } from 'type-fest'
@@ -24,6 +25,11 @@ const optionsDef = {
2425
production: {
2526
type: 'boolean',
2627
},
28+
onlyLicense: {
29+
type: 'boolean',
30+
short: 'l',
31+
default: false,
32+
},
2733
} as const
2834

2935
const { values: options } = parseArgs({ args, options: optionsDef })
@@ -41,6 +47,18 @@ if (!fss.existsSync(pkgPath)) {
4147
const pkg = (await import(url.pathToFileURL(pkgPath).href, { with: { type: 'json' } })).default
4248

4349
const absWorkingDir = path.dirname(pkgPath)
50+
const outdir = path.resolve(absWorkingDir, 'dist')
51+
52+
if (options.onlyLicense) {
53+
const metafile = path.join(outdir, 'meta.json')
54+
if (!fss.existsSync(metafile)) {
55+
throw new Error(`Meta file was not found: ${metafile}\nPlease execute \`pnpm run build\` at root directory.`)
56+
}
57+
const meta = JSON.parse(fss.readFileSync(metafile, { encoding: 'utf-8' }))
58+
generateLicense(rootDir, pkgPath, meta)
59+
console.log('The license file was generated successfully.')
60+
process.exit(0)
61+
}
4462

4563
const exports = (pkg.exports || {}) as PackageJson.ExportConditions
4664

@@ -60,8 +78,6 @@ if (entryPoints.length < 1) {
6078
throw new Error(`No export module found to build at: ${absWorkingDir}`)
6179
}
6280

63-
const outdir = path.resolve(absWorkingDir, 'dist')
64-
6581
const ctx = await context({
6682
sourceRoot: absWorkingDir,
6783
entryPoints,
@@ -89,5 +105,7 @@ if (options.watch) {
89105

90106
if (!options.production) {
91107
fss.writeFileSync(path.join(outdir, 'meta.json'), JSON.stringify(result.metafile))
108+
109+
generateLicense(rootDir, pkgPath, result.metafile)
92110
}
93111
}

0 commit comments

Comments
 (0)