Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/eager-jars-lead.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"posthog-vscode": minor
---

Added robust testing
18 changes: 17 additions & 1 deletion .github/workflows/publish-ovsx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ on:
version:
required: true
type: string
skip_tests:
description: "Skip the test gate (only set true when called from release.yml after it already ran tests)"
required: false
type: boolean
default: false
secrets:
OPEN_VSX_TOKEN:
required: true
Expand All @@ -17,15 +22,26 @@ on:
type: string

jobs:
test:
name: Tests (publish gate)
# Run tests unless explicitly skipped (workflow_call from release.yml).
# Manual workflow_dispatch always runs tests.
if: github.event_name == 'workflow_dispatch' || inputs.skip_tests != true
uses: ./.github/workflows/test.yml

publish:
name: Publish to Open VSX
needs: test
# Run publish if tests passed OR were skipped (release.yml gated).
# `always()` is required so that a `skipped` test job doesn't block this job.
if: always() && (needs.test.result == 'success' || needs.test.result == 'skipped')
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup pnpm
uses: pnpm/action-setup@v4
uses: pnpm/action-setup@41ff72655975bd51cab0327fa583b6e92b6d3061 # v4

- name: Setup Node.js
uses: actions/setup-node@v4
Expand Down
18 changes: 17 additions & 1 deletion .github/workflows/publish-vscode.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
version:
required: true
type: string
skip_tests:
description: "Skip the test gate (only set true when called from release.yml after it already ran tests)"
required: false
type: boolean
default: false
secrets:
VSCE_PAT:
required: true
Expand All @@ -17,15 +22,26 @@
type: string

jobs:
test:
name: Tests (publish gate)
# Run tests unless explicitly skipped (workflow_call from release.yml).
# Manual workflow_dispatch always runs tests.
if: github.event_name == 'workflow_dispatch' || inputs.skip_tests != true
uses: ./.github/workflows/test.yml

publish:

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {}
name: Publish to VS Code Marketplace
needs: test
# Run publish if tests passed OR were skipped (release.yml gated).
# `always()` is required so that a `skipped` test job doesn't block this job.
if: always() && (needs.test.result == 'success' || needs.test.result == 'skipped')
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup pnpm
uses: pnpm/action-setup@v4
uses: pnpm/action-setup@41ff72655975bd51cab0327fa583b6e92b6d3061 # v4

- name: Setup Node.js
uses: actions/setup-node@v4
Expand Down
22 changes: 17 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,15 @@
echo "has-changesets=true" >> "$GITHUB_OUTPUT"
fi

test:
name: Tests (release gate)
needs: check-changesets
if: needs.check-changesets.outputs.has-changesets == 'true'
uses: ./.github/workflows/test.yml

version-and-release:

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {}
name: Version bump and release
needs: check-changesets
needs: [check-changesets, test]
if: needs.check-changesets.outputs.has-changesets == 'true'
runs-on: ubuntu-latest
permissions:
Expand All @@ -57,7 +63,7 @@
token: ${{ steps.releaser.outputs.token }}

- name: Setup pnpm
uses: pnpm/action-setup@v4
uses: pnpm/action-setup@41ff72655975bd51cab0327fa583b6e92b6d3061 # v4

- name: Setup Node.js
uses: actions/setup-node@v4
Expand Down Expand Up @@ -94,9 +100,11 @@

- name: Commit version bump
if: steps.version.outputs.was-released == 'true'
env:
VERSION: ${{ steps.version.outputs.new-version }}
run: |
git add -A
git commit -m "chore: release v${{ steps.version.outputs.new-version }}"
git commit -m "chore: release v$VERSION"
git push

- name: Create Git tag
Expand Down Expand Up @@ -129,7 +137,7 @@
ref: v${{ needs.version-and-release.outputs.new-version }}

- name: Setup pnpm
uses: pnpm/action-setup@v4
uses: pnpm/action-setup@41ff72655975bd51cab0327fa583b6e92b6d3061 # v4

- name: Setup Node.js
uses: actions/setup-node@v4
Expand All @@ -138,7 +146,7 @@
cache: pnpm

- name: Setup Emscripten
uses: mymindstorm/setup-emsdk@v14
uses: mymindstorm/setup-emsdk@6ab9eb1bda2574c4ddb79809fc9247783eaf9021 # v14

- name: Install dependencies
run: pnpm install --frozen-lockfile
Expand All @@ -159,6 +167,8 @@
uses: ./.github/workflows/publish-vscode.yml
with:
version: ${{ needs.version-and-release.outputs.new-version }}
# Tests already ran in the `test` job above; skip duplicate run.
skip_tests: true
secrets:
VSCE_PAT: ${{ secrets.VSCE_PAT }}

Expand All @@ -169,5 +179,7 @@
uses: ./.github/workflows/publish-ovsx.yml
with:
version: ${{ needs.version-and-release.outputs.new-version }}
# Tests already ran in the `test` job above; skip duplicate run.
skip_tests: true
secrets:
OPEN_VSX_TOKEN: ${{ secrets.OPEN_VSX_TOKEN }}
39 changes: 37 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ on:
branches: [main]
push:
branches: [main, "feat/**"]
# Allow other workflows (release.yml, publish-*.yml) to call this workflow
# as a reusable test gate before publishing.
workflow_call:

permissions:
contents: read
Expand All @@ -30,5 +33,37 @@ jobs:
- name: Compile tests
run: pnpm compile-tests

- name: Run tests
run: xvfb-run -a pnpm test
- name: Run tests with coverage
run: xvfb-run -a pnpm test:coverage

- name: Upload coverage report
if: always()
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
with:
name: coverage-report
path: coverage/
if-no-files-found: warn
retention-days: 14

- name: Enforce coverage thresholds
if: success()
env:
MIN_LINES: "30"
MIN_FUNCTIONS: "30"
run: |
node -e '
const fs = require("fs");
const summary = JSON.parse(fs.readFileSync("coverage/coverage-summary.json", "utf8"));
const total = summary.total || {};
const lines = total.lines ? total.lines.pct : 0;
const functions = total.functions ? total.functions.pct : 0;
const minLines = Number(process.env.MIN_LINES);
const minFunctions = Number(process.env.MIN_FUNCTIONS);
console.log(`Coverage: lines=${lines}% functions=${functions}%`);
console.log(`Thresholds: lines>=${minLines}% functions>=${minFunctions}%`);
if (lines < minLines || functions < minFunctions) {
console.error("Coverage below threshold.");
process.exit(1);
}
console.log("Coverage thresholds met.");
'
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ out
dist
node_modules
.vscode-test/
coverage/
*.vsix
token.txt
wasm/
Expand Down
22 changes: 21 additions & 1 deletion .vscode-test.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
import { defineConfig } from '@vscode/test-cli';

export default defineConfig({
files: 'out/test/**/*.test.js',
tests: [
{
files: 'out/test/**/*.test.js',
srcDir: 'out',
},
],
coverage: {
includeAll: true,
include: [
'**/out/services/**',
'**/out/providers/**',
'**/out/utils/**',
],
exclude: [
'**/out/test/**',
'**/out/views/**',
'**/*.map',
],
reporter: ['text', 'html', 'lcov', 'json-summary'],
output: './coverage',
},
});
Loading
Loading