Skip to content

Commit 28b0de9

Browse files
authored
ci(extension): package with --target (#692)
* ci(extension): package with --target * chore: rm -rf -> rimraf * chore: also use rimraf in release workflow * chore: rm the universal target * ci: disable darwin-arm64 darwin-arm64 runners must be self hosted github/roadmap#528 rust-lang/rust#73908 * ci: share timestamp across matrix runs ci: ignore scripts on composite chore: only build vscode itself to avoid building twice when ran from root build * fix: use esbuild-wasm instead of esbuild for mac arm64 * revert: composite without scripts * ci: add overrides esbuild step on release workflow * fix: vscode engines allow any version
1 parent 8991b1e commit 28b0de9

File tree

7 files changed

+208
-30
lines changed

7 files changed

+208
-30
lines changed

.github/workflows/extension.yml

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,52 @@ on:
1111
- main
1212

1313
jobs:
14+
create_timestamp:
15+
runs-on: ubuntu-latest
16+
17+
outputs:
18+
timestamp: ${{ steps.set_timestamp.outputs.timestamp }}
19+
20+
steps:
21+
- name: Set Timestamp
22+
id: set_timestamp
23+
run: |
24+
echo "::set-output name=timestamp::$(date +'%s' | cut -c1-8)"
1425
release:
1526
name: VSCode Marketplace
16-
runs-on: ubuntu-latest
27+
needs: create_timestamp
28+
runs-on: ${{ matrix.os }}
29+
strategy:
30+
fail-fast: false
31+
matrix:
32+
include:
33+
- os: windows-latest
34+
target: win32-x64
35+
npm_config_arch: x64
36+
- os: windows-latest
37+
target: win32-ia32
38+
npm_config_arch: ia32
39+
- os: windows-latest
40+
target: win32-arm64
41+
npm_config_arch: arm
42+
- os: ubuntu-latest
43+
target: linux-x64
44+
npm_config_arch: x64
45+
- os: ubuntu-latest
46+
target: linux-arm64
47+
npm_config_arch: arm64
48+
- os: ubuntu-latest
49+
target: linux-armhf
50+
npm_config_arch: arm
51+
- os: ubuntu-latest
52+
target: alpine-x64
53+
npm_config_arch: x64
54+
- os: macos-latest
55+
target: darwin-x64
56+
npm_config_arch: x64
57+
- os: macos-latest
58+
target: darwin-arm64
59+
npm_config_arch: arm64
1760
steps:
1861
- name: Checkout
1962
uses: actions/checkout@v3
@@ -26,13 +69,31 @@ jobs:
2669
- name: Build packages
2770
run: pnpm build
2871

72+
- name: Set Environment Variable
73+
run: echo "VSCE_RELEASE_VERSION=$(date +'%s' | cut -c1-8)" >> $GITHUB_ENV
74+
75+
- name: Prepare npm install
76+
working-directory: ./extension/vscode
77+
run: pnpm rewrite-deps && pnpm clean
78+
79+
- name: Overrides esbuild
80+
working-directory: ./extension/vscode
81+
if: contains(matrix.target, 'darwin-arm64')
82+
run: pnpm override-esbuild
83+
84+
- name: Install with npm
85+
working-directory: ./extension/vscode
86+
run: |
87+
npm i --ignore-scripts
88+
env:
89+
npm_config_arch: ${{ matrix.npm_config_arch }}
90+
2991
- name: Publish RC
3092
working-directory: ./extension/vscode
3193
run: |
32-
pnpm rewrite-deps
33-
rm -rf node_modules
34-
npm i
3594
pnpm release
3695
env:
3796
VSCE_TOKEN: ${{secrets.VSCE_TOKEN}}
97+
VSCE_RELEASE_VERSION: ${{ needs.create_timestamp.outputs.timestamp }}
3898
VSCE_RELEASE_TYPE: rc
99+
VSCE_TARGET: ${{ matrix.target }}

.github/workflows/release.yml

Lines changed: 94 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ name: Publish
33
on:
44
push:
55
paths:
6-
- '.changeset/**'
7-
- 'packages/**'
8-
- 'extension/**'
6+
- ".changeset/**"
7+
- "packages/**"
8+
- "extension/**"
99
branches:
1010
- main
1111

@@ -37,18 +37,6 @@ jobs:
3737
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
3838
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
3939

40-
# - name: Publish extension
41-
# if: steps.changesets.outputs.published == 'true'
42-
# working-directory: ./extension/vscode
43-
# run: |
44-
# pnpm rewrite-deps
45-
# rm -rf node_modules
46-
# npm i
47-
# pnpm release
48-
# env:
49-
# VSCE_TOKEN: ${{secrets.VSCE_TOKEN}}
50-
# VSCE_RELEASE_TYPE: stable
51-
5240
- name: Release to dev tag
5341
if: steps.changesets.outputs.published != 'true'
5442
run: |
@@ -58,3 +46,94 @@ jobs:
5846
env:
5947
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
6048
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
49+
50+
create_timestamp:
51+
runs-on: ubuntu-latest
52+
53+
outputs:
54+
timestamp: ${{ steps.set_timestamp.outputs.timestamp }}
55+
56+
steps:
57+
- name: Set Timestamp
58+
id: set_timestamp
59+
run: |
60+
echo "::set-output name=timestamp::$(date +'%s' | cut -c1-8)"
61+
62+
release-extension:
63+
name: VSCode Marketplace
64+
needs: create_timestamp
65+
runs-on: ${{ matrix.os }}
66+
strategy:
67+
fail-fast: false
68+
matrix:
69+
include:
70+
- os: windows-latest
71+
target: win32-x64
72+
npm_config_arch: x64
73+
- os: windows-latest
74+
target: win32-ia32
75+
npm_config_arch: ia32
76+
- os: windows-latest
77+
target: win32-arm64
78+
npm_config_arch: arm
79+
- os: ubuntu-latest
80+
target: linux-x64
81+
npm_config_arch: x64
82+
- os: ubuntu-latest
83+
target: linux-arm64
84+
npm_config_arch: arm64
85+
- os: ubuntu-latest
86+
target: linux-armhf
87+
npm_config_arch: arm
88+
- os: ubuntu-latest
89+
target: alpine-x64
90+
npm_config_arch: x64
91+
- os: macos-latest
92+
target: darwin-x64
93+
npm_config_arch: x64
94+
- os: macos-latest
95+
target: darwin-arm64
96+
npm_config_arch: arm64
97+
steps:
98+
- name: Checkout
99+
uses: actions/checkout@v3
100+
with:
101+
fetch-depth: 0
102+
103+
- name: Install
104+
uses: ./.github/composite-actions/install
105+
106+
- name: Build packages
107+
run: pnpm build
108+
109+
- name: Set Environment Variable
110+
run: echo "VSCE_RELEASE_VERSION=$(date +'%s' | cut -c1-8)" >> $GITHUB_ENV
111+
112+
- name: Prepare npm install
113+
working-directory: ./extension/vscode
114+
run: pnpm rewrite-deps && pnpm clean
115+
116+
- name: Overrides esbuild
117+
working-directory: ./extension/vscode
118+
if: contains(matrix.target, 'darwin-arm64')
119+
run: pnpm override-esbuild
120+
121+
- name: Install with npm
122+
working-directory: ./extension/vscode
123+
run: |
124+
npm i --ignore-scripts
125+
env:
126+
npm_config_arch: ${{ matrix.npm_config_arch }}
127+
128+
- name: Publish extension
129+
if: steps.changesets.outputs.published == 'true'
130+
working-directory: ./extension/vscode
131+
run: |
132+
pnpm rewrite-deps
133+
pnpm clean
134+
npm i
135+
pnpm release
136+
env:
137+
VSCE_TOKEN: ${{secrets.VSCE_TOKEN}}
138+
VSCE_RELEASE_VERSION: ${{ needs.create_timestamp.outputs.timestamp }}
139+
VSCE_RELEASE_TYPE: stable

extension/vscode/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"version": "0.2.3",
77
"private": true,
88
"engines": {
9-
"vscode": "^1.78.2"
9+
"vscode": "*"
1010
},
1111
"categories": [
1212
"Programming Languages",
@@ -199,14 +199,14 @@
199199
"build:shared": "pnpm --filter=../shared build",
200200
"build:ts-plugin": "pnpm --filter=../ts-plugin build",
201201
"build:all": "pnpm build:shared && pnpm build:lsp && pnpm build:ts-plugin",
202-
"build": "pnpm build:all && tsup",
202+
"build": "tsup",
203203
"dev": "tsup --watch src/index.ts --watch ../language-server/dist/index.js --watch ../shared/dist/index.js",
204-
"clean": "rimraf dist",
204+
"clean": "rimraf dist node_modules",
205205
"typecheck": "tsc --noEmit",
206206
"rewrite-deps": "tsx ./scripts/rewrite-workspace-dependencies.ts",
207+
"override-esbuild": "tsx ./scripts/override-esbuild-with-wasm.ts",
207208
"release": "pnpm build --silent && tsx ./scripts/publish.ts",
208-
"vsce:package": "pnpm --silent build && pnpm vsix-builder package",
209-
"vsce:prerelease": "pnpm --silent build && pnpm vsix-builder package patch --pre-release -o panda.vsix"
209+
"vsce:package": "pnpm --silent build && pnpm vsix-builder package"
210210
},
211211
"dependencies": {
212212
"@pandacss/dev": "workspace:*",
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import type { PackageManifest } from '@pnpm/types'
2+
import fs from 'fs'
3+
import path, { dirname } from 'path'
4+
import { fileURLToPath } from 'url'
5+
6+
const _dirname = dirname(fileURLToPath(import.meta.url))
7+
8+
const main = async () => {
9+
const pkgJsonPath = path.join(_dirname, '../package.json')
10+
const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf-8')) as PackageManifest
11+
12+
// Github runners dont support arm64 on macos
13+
// https://github.com/actions/runner-images/issues/2187
14+
15+
// unless self-hosted but
16+
// https://github.com/medic/cht-core/issues/8277#issuecomment-1568021046
17+
// > GitHub recommends only utilizing self-hosted runners with private repositories.
18+
// > Allowing self-hosted runners on public repositories and allowing workflows on public forks
19+
// > introduces a significant security risk.
20+
21+
// so we need to use esbuild-wasm instead of esbuild
22+
// if we want to be able to publish the extension for M1 macs from the CI
23+
// (or we could also just publish the extension from our own M1 machines)
24+
25+
// @ts-expect-error
26+
pkgJson.overrides = {
27+
esbuild: 'npm:esbuild-wasm@latest',
28+
}
29+
30+
fs.writeFileSync(pkgJsonPath, JSON.stringify(pkgJson, null, 2))
31+
}
32+
main()

extension/vscode/scripts/publish.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ config()
99
const { version } = require('../package.json')
1010

1111
const releaseType = process.env.VSCE_RELEASE_TYPE
12+
const target = process.env.VSCE_TARGET
1213

1314
const tokens = {
1415
vscode: releaseType === 'dry-run' ? 'dry-run' : process.env.VSCE_TOKEN,
@@ -20,7 +21,7 @@ if (!hasTokens) {
2021
throw new Error('Cannot publish extension without tokens.')
2122
}
2223

23-
const today = new Date().getTime().toString().slice(0, 8)
24+
const today = process.env.VSCE_RELEASE_VERSION ?? new Date().getTime().toString().slice(0, 8)
2425
const currentVersion = semver.valid(version)
2526

2627
if (!currentVersion) {
@@ -33,16 +34,16 @@ if (!rcVersion) {
3334
}
3435

3536
const commands = {
36-
vscode_package: 'pnpm run vsce:package',
37+
vscode_package: `pnpm vsix-builder package ${rcVersion} --target ${target} -o panda.vsix`,
3738
vscode_publish: `pnpm vsce publish --packagePath panda.vsix --pat ${process.env.VSCE_TOKEN}`,
3839
// rc release: publish to VS Code Marketplace with today's date as patch number
39-
vscode_package_rc: `pnpm vsix-builder package ${rcVersion} --pre-release -o panda.vsix`,
40+
vscode_package_rc: `pnpm vsix-builder package ${rcVersion} --pre-release --target ${target} -o panda.vsix`,
4041
vscode_rc: `pnpm vsce publish --pre-release --packagePath panda.vsix --pat ${process.env.VSCE_TOKEN}`,
4142
// To publish to the open-vsx registry
4243
openvsx_publish: `npx ovsx publish panda.vsix --pat ${process.env.OVSX_TOKEN}`,
4344
}
4445

45-
console.log('[vsce:package]', commands.vscode_package_rc)
46+
console.log('[vsce:package]', commands.vscode_package_rc, target)
4647
switch (releaseType) {
4748
case 'rc':
4849
execaSync(commands.vscode_package_rc, { stdio: 'inherit' })
@@ -54,7 +55,7 @@ switch (releaseType) {
5455
console.log('[vsce:package]', "Skipping 'vsce package' step.")
5556
}
5657

57-
console.log('[vsce:publish] publishing', rcVersion)
58+
console.log('[vsce:publish] publishing', rcVersion, target)
5859
switch (releaseType) {
5960
case 'rc':
6061
if (!rcVersion || !semver.valid(rcVersion) || semver.valid(rcVersion) === currentVersion) {

extension/vscode/scripts/rewrite-workspace-dependencies.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ const main = async () => {
2929
Object.entries(pkgJson.dependencies ?? {}).forEach(rewritePackageVersion(pkgJson.dependencies ?? {}))
3030
Object.entries(pkgJson.devDependencies ?? {}).forEach(rewritePackageVersion(pkgJson.devDependencies ?? {}))
3131

32+
// @ts-expect-error
33+
pkgJson.overrides = {
34+
esbuild: 'npm:esbuild-wasm@latest',
35+
}
36+
3237
fs.writeFileSync(pkgJsonPath, JSON.stringify(pkgJson, null, 2))
3338
}
3439
main()

extension/vsix-builder/src/vsce/version-bump.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export async function versionBump(manifest: Manifest, options: IVersionBumpOptio
3636
throw new Error('Cannot get the current version number from package.json')
3737
}
3838

39-
const rcVersion = semver.inc(currentVersion, 'minor')?.replace(/\.\d+$/, `.${today}`)
39+
const rcVersion = options.version ?? semver.inc(currentVersion, 'minor')?.replace(/\.\d+$/, `.${today}`)
4040
if (!rcVersion) {
4141
throw new Error("Could not populate the current version number for rc's build.")
4242
}

0 commit comments

Comments
 (0)