Skip to content

Commit 8d978ab

Browse files
amvanbarenamvanbaren
andauthored
Use separate jobs instead of child_process (#881)
Co-authored-by: amvanbaren <[email protected]>
1 parent f7cfb5c commit 8d978ab

10 files changed

+573
-239
lines changed
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
name: Publish extension
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
extension:
6+
description: Extension JSON object
7+
required: true
8+
type: string
9+
publishContext:
10+
description: Publish context JSON object
11+
required: true
12+
type: string
13+
skipPublish:
14+
description: Skip publishing to Open VSX, only build extensions
15+
required: true
16+
type: boolean
17+
force:
18+
description: Force publish to Open VSX, even if version is already published
19+
required: true
20+
type: boolean
21+
jobs:
22+
download_release:
23+
name: Download latest release
24+
runs-on: ubuntu-latest
25+
permissions:
26+
contents: read
27+
env:
28+
DO_DOWNLOAD: ${{ fromJSON(inputs.publishContext).files != null }}
29+
steps:
30+
- uses: actions/checkout@v4
31+
if: ${{ env.DO_DOWNLOAD == 'true' }}
32+
- uses: actions/[email protected]
33+
if: ${{ env.DO_DOWNLOAD == 'true' }}
34+
with:
35+
node-version: "20.x"
36+
- run: npm install
37+
if: ${{ env.DO_DOWNLOAD == 'true' }}
38+
- run: npm i -g @vscode/vsce pnpm
39+
if: ${{ env.DO_DOWNLOAD == 'true' }}
40+
- id: download_extension
41+
uses: actions/github-script@v7
42+
if: ${{ env.DO_DOWNLOAD == 'true' }}
43+
env:
44+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
45+
EXTENSION: ${{ inputs.extension }}
46+
PUBLISH_CONTEXT: ${{ inputs.publishContext }}
47+
with:
48+
script: |
49+
const script = require('./scripts/download-extension.js');
50+
await script();
51+
build_extension:
52+
name: Build Extension
53+
runs-on: ubuntu-latest
54+
needs: download_release
55+
permissions:
56+
actions: none
57+
steps:
58+
- uses: actions/checkout@v4
59+
- uses: actions/[email protected]
60+
with:
61+
node-version: "20.x"
62+
- uses: oven-sh/setup-bun@v2
63+
with:
64+
bun-version: latest
65+
- name: Set up pyenv
66+
uses: "gabrielfalcao/pyenv-action@32ef4d2c861170ce17ded56d10329d83f4c8f797"
67+
with:
68+
command: python --version
69+
- name: Set default global version
70+
run: |
71+
pyenv install 3.8
72+
pyenv global 3.8
73+
- uses: actions/setup-java@v4
74+
with:
75+
distribution: "microsoft"
76+
java-version: "21"
77+
- name: Install dependencies for native modules
78+
run: |
79+
sudo apt-get update
80+
sudo apt-get install libpango1.0-dev libgif-dev
81+
- run: npm install
82+
- run: npm i -g @vscode/vsce pnpm
83+
- uses: actions/download-artifact@v4
84+
with:
85+
path: /tmp
86+
- id: build_extension
87+
name: Build extension
88+
uses: actions/github-script@v7
89+
env:
90+
FORCE: ${{ inputs.force }}
91+
SKIP_PUBLISH: ${{ inputs.skipPublish }}
92+
EXTENSION: ${{ inputs.extension }}
93+
PUBLISH_CONTEXT: ${{inputs.publishContext}}
94+
with:
95+
script: |
96+
const extension = JSON.parse(process.env.EXTENSION);
97+
const publishContext = JSON.parse(process.env.PUBLISH_CONTEXT);
98+
const buildScript = require('./scripts/build-extension.js');
99+
const extensionFiles = await buildScript(extension, publishContext);
100+
const uploadScript = require('./scripts/upload-artifacts.js');
101+
await uploadScript(extensionFiles);
102+
core.setOutput("extensionFiles", JSON.stringify(extensionFiles));
103+
outputs:
104+
extensionFiles: ${{ steps.build_extension.outputs.extensionFiles }}
105+
publish_extension:
106+
name: Publish Extension
107+
runs-on: ubuntu-latest
108+
if: ${{ inputs.skipPublish != 'true' }}
109+
needs: build_extension
110+
permissions:
111+
actions: none
112+
steps:
113+
- uses: actions/checkout@v4
114+
- uses: actions/[email protected]
115+
with:
116+
node-version: "20.x"
117+
- run: npm install
118+
- run: npm i -g @vscode/vsce pnpm
119+
- uses: actions/download-artifact@v4
120+
with:
121+
path: /tmp
122+
- uses: actions/github-script@v7
123+
env:
124+
OVSX_PAT: ${{ secrets.OVSX_PAT }}
125+
EXTENSION_ID: ${{ fromJson(inputs.extension).id }}
126+
EXTENSION_FILES: ${{needs.build_extension.outputs.extensionFiles}}
127+
with:
128+
script: |
129+
const extensionId = process.env.EXTENSION_ID;
130+
const extensionFiles = JSON.parse(process.env.EXTENSION_FILES);
131+
const script = require('./scripts/publish-extension.js');
132+
await script(extensionId, extensionFiles);

.github/workflows/publish-extensions.yml

Lines changed: 55 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -29,67 +29,75 @@ jobs:
2929
FORCE: ${{ github.event.inputs.forcefullyPublish }}
3030
name: Publish Extensions
3131
runs-on: ubuntu-latest
32+
permissions:
33+
actions: write
34+
contents: read
3235
steps:
3336
- uses: actions/checkout@v4
3437
- uses: actions/[email protected]
3538
with:
3639
node-version: "20.x"
37-
- uses: oven-sh/setup-bun@v2
38-
with:
39-
bun-version: latest
40-
- name: Set up pyenv
41-
uses: "gabrielfalcao/pyenv-action@32ef4d2c861170ce17ded56d10329d83f4c8f797"
42-
with:
43-
command: python --version
44-
- name: Set default global version
45-
run: |
46-
pyenv install 3.8
47-
pyenv global 3.8
48-
- uses: actions/setup-java@v4
49-
with:
50-
distribution: "microsoft"
51-
java-version: "21"
52-
- name: Install dependencies for native modules
53-
run: |
54-
sudo apt-get update
55-
sudo apt-get install libpango1.0-dev libgif-dev
5640
- run: npm install
5741
- run: npm i -g @vscode/vsce pnpm
58-
- run: node publish-extensions
42+
- uses: actions/github-script@v7
5943
env:
60-
OVSX_PAT: ${{ secrets.OVSX_PAT }}
6144
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
62-
- name: Report results
63-
run: bun run ./report-extensions.ts
64-
- uses: actions/upload-artifact@v4
65-
if: always()
45+
REPOSITORY: ${{ github.repository }}
6646
with:
67-
name: report
68-
path: |
69-
/tmp/stat.json
70-
/tmp/result.md
71-
- uses: actions/upload-artifact@v4
72-
if: always()
73-
with:
74-
name: artifacts
75-
path: |
76-
/tmp/artifacts/*.vsix
77-
- name: Upload job summary
78-
if: always()
79-
run: cat /tmp/result.md >> $GITHUB_STEP_SUMMARY
80-
- name: Get previous job's status
81-
id: lastrun
82-
uses: filiptronicek/get-last-job-status@main
83-
- name: Slack Notification
84-
if: ${{ !github.event.inputs.extensions && ((success() && steps.lastrun.outputs.status == 'failed') || failure()) }}
85-
uses: rtCamp/action-slack-notify@v2
86-
env:
87-
SLACK_WEBHOOK: ${{ secrets.GITPOD_SLACK_WEBHOOK }}
88-
SLACK_COLOR: ${{ job.status }}
47+
script: |
48+
const script = require('./scripts/publish-extensions.js');
49+
await script(async (extension, context) => {
50+
const [owner, repo] = process.env.REPOSITORY.split("/");
51+
await github.request("POST /repos/{owner}/{repo}/actions/workflows/{workflow_id}/dispatches", {
52+
owner,
53+
repo,
54+
workflow_id: "publish-extension.yml",
55+
ref: "build-extension",
56+
inputs: {
57+
extension: JSON.stringify(extension),
58+
publishContext: JSON.stringify(context),
59+
force: process.env.FORCE,
60+
skipPublish: process.env.SKIP_PUBLISH,
61+
},
62+
headers: {
63+
"X-GitHub-Api-Version": "2022-11-28",
64+
},
65+
});
66+
});
67+
# TODO fix reporting
68+
# - name: Report results
69+
# run: bun run ./report-extensions.ts
70+
# - uses: actions/upload-artifact@v4
71+
# if: always()
72+
# with:
73+
# name: report
74+
# path: |
75+
# /tmp/stat.json
76+
# /tmp/result.md
77+
# - uses: actions/upload-artifact@v4
78+
# if: always()
79+
# with:
80+
# name: artifacts
81+
# path: |
82+
# /tmp/artifacts/*.vsix
83+
# - name: Upload job summary
84+
# if: always()
85+
# run: cat /tmp/result.md >> $GITHUB_STEP_SUMMARY
86+
# - name: Get previous job's status
87+
# id: lastrun
88+
# uses: filiptronicek/get-last-job-status@main
89+
# - name: Slack Notification
90+
# if: ${{ !github.event.inputs.extensions && ((success() && steps.lastrun.outputs.status == 'failed') || failure()) }}
91+
# uses: rtCamp/action-slack-notify@v2
92+
# env:
93+
# SLACK_WEBHOOK: ${{ secrets.GITPOD_SLACK_WEBHOOK }}
94+
# SLACK_COLOR: ${{ job.status }}
8995
check_parity:
9096
name: Check MS parity
9197
runs-on: ubuntu-latest
9298
needs: publish_extensions
99+
permissions:
100+
actions: none
93101
if: ${{ !github.event.inputs.extensions }} # only run on full runs
94102
steps:
95103
- uses: actions/checkout@v4

.github/workflows/validate-pr.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,15 @@ jobs:
3030
run: |
3131
pyenv install 3.8
3232
pyenv global 3.8
33-
- run: EXTENSIONS=$(node diff-extensions) node publish-extensions
33+
- run: echo "EXTENSIONS=$(node diff-extensions)" >> $GITHUB_ENV
34+
- uses: actions/github-script@v7
3435
env:
3536
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
37+
REPOSITORY: ${{ github.repository }}
38+
with:
39+
script: |
40+
const script = require('./scripts/publish-extensions.js');
41+
await script({github});
3642
- name: Report results
3743
run: bun run ./report-extensions.ts
3844
- uses: actions/upload-artifact@v4

local-workflow.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/********************************************************************************
2+
* Copyright (c) 2025 Precies. Software OU and others
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License v. 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0.
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
********************************************************************************/
10+
11+
// @ts-check
12+
const publishExtensionsScript = require("./scripts/publish-extensions");
13+
const buildExtensionScript = require("./scripts/build-extension");
14+
const publishExtensionScript = require("./scripts/publish-extension");
15+
16+
(async () => {
17+
process.env.SKIP_PUBLISH ??= "true";
18+
process.env.FORCE ??= "true";
19+
20+
await publishExtensionsScript(async (extension, publishContext) => {
21+
const extensionFiles = await buildExtensionScript(extension, publishContext);
22+
await publishExtensionScript(extension.id, extensionFiles);
23+
});
24+
})();

package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"format": "prettier --write ."
2929
},
3030
"dependencies": {
31+
"@actions/artifact": "^2.3.2",
3132
"@vscode/vsce": "^3.0.0",
3233
"ajv": "^8.8.1",
3334
"chai": "^5.1.0",
@@ -37,16 +38,22 @@
3738
"find-up": "^5.0.0",
3839
"human-number": "^2.0.0",
3940
"jest-diff": "^29.7.0",
41+
"limiter": "^3.0.0",
4042
"minimist": "^1.2.5",
4143
"octokit": "^3.1.2",
4244
"ovsx": "latest",
4345
"prettier": "^3.2.5",
44-
"semver": "^7.1.3"
46+
"semver": "^7.1.3",
47+
"xml2js": "^0.6.2",
48+
"yauzl-promise": "^4.0.0"
4549
},
4650
"devDependencies": {
51+
"@actions/github-script": "github:actions/github-script",
4752
"@types/human-number": "^1.0.0",
4853
"@types/node": "^22.2.0",
4954
"@types/unzipper": "^0.10.5",
55+
"@types/xml2js": "^0.4.14",
56+
"@types/yauzl-promise": "^4.0.1",
5057
"bun-types": "^1.0.1"
5158
}
5259
}

0 commit comments

Comments
 (0)