Skip to content

Commit 99132b7

Browse files
Small cleanup
1 parent e9d1931 commit 99132b7

4 files changed

Lines changed: 29 additions & 16 deletions

File tree

.github/workflows/deploy.yaml

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@ on:
66
types: [completed]
77
branches: [main]
88

9+
permissions:
10+
contents: write
11+
912
jobs:
1013
publish-extension:
1114
name: Publish to marketplace
1215
runs-on: ubuntu-latest
13-
environment: production
16+
environment: Production
1417
if: ${{ github.event.workflow_run.conclusion == 'success' }}
1518

1619
steps:
@@ -23,6 +26,7 @@ jobs:
2326
uses: actions/setup-node@v6
2427
with:
2528
node-version-file: .nvmrc
29+
cache: npm
2630

2731
- name: Install dependencies
2832
run: npm --color ci
@@ -32,20 +36,27 @@ jobs:
3236
VERSION=$(node -p "require('./package.json').version")
3337
echo "version=$VERSION" >> $GITHUB_ENV
3438
35-
- name: Create Git tag
39+
- name: Check whether this version is already published
3640
run: |
37-
git tag ${{ env.version }}
38-
git push origin ${{ env.version }}
41+
if git ls-remote --exit-code --tags origin "refs/tags/${{ env.version }}" > /dev/null; then
42+
echo "Version ${{ env.version }} is already tagged."
43+
exit 1
44+
fi
3945
4046
- name: Publish to Open VSX Registry
4147
id: publishToOpenVSX
4248
uses: HaaLeo/publish-vscode-extension@v2
4349
with:
44-
pat: ${{ secrets.OPEN_VSX_TOKEN }}
50+
pat: ${{ secrets.OPENVSX_PAT }}
4551

4652
- name: Publish to Visual Studio Marketplace
4753
uses: HaaLeo/publish-vscode-extension@v2
4854
with:
49-
pat: ${{ secrets.VS_MARKETPLACE_TOKEN }}
55+
pat: ${{ secrets.VSCE_PAT }}
5056
registryUrl: https://marketplace.visualstudio.com
5157
extensionFile: ${{ steps.publishToOpenVSX.outputs.vsixPath }}
58+
59+
- name: Create Git tag
60+
run: |
61+
git tag "${{ env.version }}"
62+
git push origin "${{ env.version }}"

.github/workflows/test.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ on:
66
pull_request:
77
types: [opened, synchronize, reopened]
88

9+
permissions:
10+
contents: read
11+
912
jobs:
1013
run-tests:
1114
name: Run tests
@@ -19,6 +22,7 @@ jobs:
1922
uses: actions/setup-node@v6
2023
with:
2124
node-version-file: .nvmrc
25+
cache: npm
2226

2327
- name: Install dependencies
2428
run: npm --color ci

src/commandRunner.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@ import * as vscode from "vscode";
33
import { globsToRegex } from "./regex";
44

55
export class CommandRunner {
6-
private allowRegex!: RegExp;
7-
private denyRegex!: RegExp | null;
6+
private allowRegex: RegExp | undefined;
7+
private denyRegex: RegExp | undefined;
88
private backgroundWindowProtection!: boolean;
99

1010
public constructor() {
11-
this.reloadConfiguration = this.reloadConfiguration.bind(this);
1211
this.runCommand = this.runCommand.bind(this);
1312

1413
this.reloadConfiguration();
@@ -20,13 +19,12 @@ export class CommandRunner {
2019
.getConfiguration("command-server")
2120
.get<string[]>("allowList", []);
2221

23-
this.allowRegex = globsToRegex(allowList);
24-
2522
const denyList = vscode.workspace
2623
.getConfiguration("command-server")
2724
.get<string[]>("denyList", []);
2825

29-
this.denyRegex = denyList.length === 0 ? null : globsToRegex(denyList);
26+
this.allowRegex = globsToRegex(allowList);
27+
this.denyRegex = globsToRegex(denyList);
3028

3129
this.backgroundWindowProtection = vscode.workspace
3230
.getConfiguration("command-server")
@@ -46,11 +44,11 @@ export class CommandRunner {
4644
}
4745
}
4846

49-
if (!this.allowRegex.test(commandId)) {
47+
if (this.allowRegex != null && !this.allowRegex.test(commandId)) {
5048
throw new Error("Command not in allowList");
5149
}
5250

53-
if (this.denyRegex != null && commandId.match(this.denyRegex)) {
51+
if (this.denyRegex?.test(commandId)) {
5452
throw new Error("Command in denyList");
5553
}
5654

src/regex.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { Minimatch } from "minimatch";
22

3-
export function globsToRegex(globs: string[]): RegExp {
3+
export function globsToRegex(globs: string[]): RegExp | undefined {
44
const regexes = globs
55
.map((glob) => new Minimatch(glob).makeRe())
66
.filter((regex): regex is RegExp => regex !== false);
7-
return any(regexes);
7+
return regexes.length > 0 ? any(regexes) : undefined;
88
}
99

1010
/**

0 commit comments

Comments
 (0)