Skip to content

Commit

Permalink
feat: support universal as VSCE_TARGET (#376)
Browse files Browse the repository at this point in the history
  • Loading branch information
felipecrs authored Dec 6, 2022
1 parent 7a2ccd1 commit 6c4cae9
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 39 deletions.
61 changes: 33 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ Which `.vsix` file (or files) to publish. This controls what value will be used

### Environment variables

| Variable | Description |
| ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `VSCE_PAT` | **Required** (unless `publish` is set to `false`). The personal access token to publish the extension to Visual Studio Marketplace |
| `VSCE_TARGET` | _Optional_. The target to use when packaging or publishing the extension (used as `vsce package --target ${VSCE_TARGET}`). See [the platform-specific example](#platform-specific-on-github-actions) ) |
| `OVSX_PAT` | _Optional_. The personal access token to push to OpenVSX |
| Variable | Description |
| ------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `VSCE_PAT` | **Required** (unless `publish` is set to `false`). The personal access token to publish the extension to Visual Studio Marketplace |
| `VSCE_TARGET` | _Optional_. The target to use when packaging or publishing the extension (used as `vsce package --target ${VSCE_TARGET}`). When set to `universal`, behave as if `VSCE_TARGET` was not set (i.e. build the universal/generic `vsix`). See [the platform-specific example](#platform-specific-on-github-actions) |
| `OVSX_PAT` | _Optional_. The personal access token to push to OpenVSX |

### Publishing to OpenVSX

Expand Down Expand Up @@ -209,75 +209,80 @@ jobs:
matrix:
include:
- os: windows-latest
platform: win32
arch: x64
target: win32-x64
npm_config_arch: x64
- os: windows-latest
platform: win32
arch: ia32
target: win32-ia32
npm_config_arch: ia32
- os: windows-latest
platform: win32
arch: arm64
target: win32-arm64
npm_config_arch: arm
- os: ubuntu-latest
platform: linux
arch: x64
taget: linux-x64
npm_config_arch: x64
- os: ubuntu-latest
platform: linux
arch: arm64
target: linux-arm64
npm_config_arch: arm64
- os: ubuntu-latest
platform: linux
arch: armhf
target: linux-armhf
npm_config_arch: arm
- os: ubuntu-latest
platform: alpine
arch: x64
target: alpine-x64
npm_config_arch: x64
- os: macos-latest
platform: darwin
arch: x64
target: darwin-x64
npm_config_arch: x64
- os: macos-latest
platform: darwin
arch: arm64
target: darwin-arm64
npm_config_arch: arm64
- os: ubuntu-latest
target: universal
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
- run: npm ci
- if: matrix.target != 'universal'
name: Install dependencies (with binaries)
run: npm ci
env:
npm_config_arch: ${{ matrix.npm_config_arch }}
- name: Set VSCE_TARGET
shell: pwsh
run: echo "VSCE_TARGET=${{ matrix.platform }}-${{ matrix.arch }}" >> $env:GITHUB_ENV
- if: matrix.target == 'universal'
name: Install dependencies (without binaries)
run: npm ci
- run: npx semantic-release --extends ./package.release.config.js
env:
VSCE_TARGET: ${{ matrix.target }}
# All tokens are required since semantic-release needs to validate them
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VSCE_PAT: ${{ secrets.VSCE_PAT }}
# In case you want to publish to OpenVSX
OVSX_PAT: ${{ secrets.OVSX_PAT }}
- uses: actions/upload-artifact@v3
with:
name: ${{ env.VSCE_TARGET }}
name: ${{ matrix.target }}
path: '*.vsix'
release:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
- run: npm ci
- uses: actions/download-artifact@v3
- run: npx semantic-release --extends ./publish.release.config.js
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion lib/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ module.exports = async (version, packageVsix, logger, cwd) => {
'--out',
packagePath,
];
if (process.env.VSCE_TARGET) {
if (isTargetEnabled()) {
options.push('--target', process.env.VSCE_TARGET);
}

Expand Down
4 changes: 3 additions & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ const isOvsxEnabled = () => {
};

const isTargetEnabled = () => {
return 'VSCE_TARGET' in process.env;
return (
'VSCE_TARGET' in process.env && process.env.VSCE_TARGET !== 'universal'
);
};

module.exports = {
Expand Down
20 changes: 11 additions & 9 deletions lib/verify-target.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@ module.exports = async () => {
);
}

const targets = require('@vscode/vsce/out/package').Targets;
if (process.env.VSCE_TARGET !== 'universal') {
const targets = require('@vscode/vsce/out/package').Targets;

// Throw if the target is not supported
if (!targets.has(process.env.VSCE_TARGET)) {
throw new SemanticReleaseError(
`Unsupported vsce target: ${
process.env.VSCE_TARGET
}. Available targets: ${Object.values(targets).join(', ')}`,
'EUNSUPPORTEDVSCETARGET'
);
// Throw if the target is not supported
if (!targets.has(process.env.VSCE_TARGET)) {
throw new SemanticReleaseError(
`Unsupported vsce target: ${
process.env.VSCE_TARGET
}. Available targets: ${Object.values(targets).join(', ')}`,
'EUNSUPPORTEDVSCETARGET'
);
}
}
};
30 changes: 30 additions & 0 deletions test/prepare.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,33 @@ test('packageVsix when target is set', async (t) => {
{ stdio: 'inherit', preferLocal: true, cwd },
]);
});

test('packageVsix when target is set to universal', async (t) => {
const { execaStub } = t.context.stubs;
const name = 'test';

const prepare = proxyquire('../lib/prepare', {
execa: execaStub,
'fs-extra': {
readJson: sinon.stub().returns({
name,
}),
},
});

const version = '1.0.0';
const packagePath = `${name}-${version}.vsix`;

sinon.stub(process, 'env').value({
VSCE_TARGET: 'universal',
});

const result = await prepare(version, true, logger, cwd);

t.deepEqual(result, packagePath);
t.deepEqual(execaStub.getCall(0).args, [
'vsce',
['package', version, '--no-git-tag-version', '--out', packagePath],
{ stdio: 'inherit', preferLocal: true, cwd },
]);
});
10 changes: 10 additions & 0 deletions test/verify-target.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,13 @@ test('VSCE_TARGET is unsupported', async (t) => {
code: 'EUNSUPPORTEDVSCETARGET',
});
});

test('VSCE_TARGET is universal', async (t) => {
sinon.stub(process, 'env').value({
VSCE_TARGET: 'universal',
});

const verifyTarget = require('../lib/verify-target');

await t.notThrowsAsync(() => verifyTarget());
});

0 comments on commit 6c4cae9

Please sign in to comment.