diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a07c91a..71a3786 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -14,10 +14,16 @@ jobs: - uses: actions/setup-node@v4 with: node-version: 20 - + + - name: Enable Corepack + run: corepack enable + - name: Install dependencies - run: yarn - + run: yarn install --immutable + + - name: Lint and test + run: xvfb-run -a yarn test + - name: Build run: yarn package @@ -25,4 +31,4 @@ jobs: uses: actions/upload-artifact@v4 with: path: "*.vsix" - retention-days: 10 + retention-days: 10 \ No newline at end of file diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 2fd6dd5..a596b19 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -12,15 +12,25 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: - node-version: 18 + node-version: 20 + - name: Enable Corepack + run: corepack enable - name: Install dependencies - run: yarn + run: yarn install --immutable + - name: Package extension + id: package + run: | + echo "version=$(node -p "require('./package.json').version")" >> "$GITHUB_OUTPUT" + yarn package - name: Publish to Open VSX Registry - uses: HaaLeo/publish-vscode-extension@v1 + id: publishToOpenVSX + uses: HaaLeo/publish-vscode-extension@v2 with: pat: ${{ secrets.OPEN_VSX_TOKEN }} + extensionFile: koishi-dev-${{ steps.package.outputs.version }}.vsix - name: Publish to Visual Studio Marketplace - uses: HaaLeo/publish-vscode-extension@v1 + uses: HaaLeo/publish-vscode-extension@v2 with: pat: ${{ secrets.VS_MARKETPLACE_TOKEN }} registryUrl: https://marketplace.visualstudio.com + extensionFile: ${{ steps.publishToOpenVSX.outputs.vsixPath }} diff --git a/.github/workflows/tagger.yml b/.github/workflows/tagger.yml index fdbd53a..69df715 100644 --- a/.github/workflows/tagger.yml +++ b/.github/workflows/tagger.yml @@ -14,38 +14,33 @@ jobs: steps: - uses: actions/checkout@v4 + with: + fetch-depth: 0 - uses: actions/setup-node@v4 with: - node-version: 16 + node-version: 20 - name: Check current version id: check_version - run: echo ::set-output name=VERSION::$(node -p "require('./package.json').version") - - - name: Check remote tags - id: check_tags - run: | - git fetch --tags - echo ::set-output name=TAGS::$(git tag -l) + run: echo "version=$(node -p "require('./package.json').version")" >> "$GITHUB_OUTPUT" - name: Check if tag exists id: check_tag run: | - if [[ "${{ steps.check_tags.outputs.TAGS }}" == *"${{ steps.check_version.outputs.VERSION }}"* ]]; then - echo ::set-output name=TAG_EXISTS::true + if git tag -l "v${VERSION}" | grep -q .; then + echo "exists=true" >> "$GITHUB_OUTPUT" else - echo ::set-output name=TAG_EXISTS::false + echo "exists=false" >> "$GITHUB_OUTPUT" fi + env: + VERSION: ${{ steps.check_version.outputs.version }} - - name: Create tag - id: create_tag - if: ${{ github.ref == 'refs/heads/master' && steps.check_tag.outputs.TAG_EXISTS == 'false' }} - run: echo ::set-output name=TAG::v${{ steps.check_version.outputs.VERSION }} - - - name: Push tag - if: ${{ github.ref == 'refs/heads/master' && steps.check_tag.outputs.TAG_EXISTS == 'false' }} + - name: Create and push tag + if: ${{ steps.check_tag.outputs.exists == 'false' }} run: | git config --local user.email "github-actions[bot]@users.noreply.github.com" git config --local user.name "github-actions[bot]" - git tag ${{ steps.create_tag.outputs.TAG }} - git push origin ${{ steps.create_tag.outputs.TAG }} + git tag "v${VERSION}" + git push origin "v${VERSION}" + env: + VERSION: ${{ steps.check_version.outputs.version }} \ No newline at end of file diff --git a/.gitignore b/.gitignore index e593460..9dce3af 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ dist/ out # VSCode +.vscode-test/ # Plugin schemata/*.json diff --git a/.vscodeignore b/.vscodeignore index b88fa16..b74cafa 100644 --- a/.vscodeignore +++ b/.vscodeignore @@ -4,6 +4,7 @@ src/** .gitignore .yarnrc .yarnrc.yml +.yarn/** **/tsconfig.json **/.eslintrc.json **/eslint.config.mjs diff --git a/.yarnrc.yml b/.yarnrc.yml index 8b757b2..dc61281 100644 --- a/.yarnrc.yml +++ b/.yarnrc.yml @@ -1 +1,6 @@ -nodeLinker: node-modules \ No newline at end of file +approvedGitRepositories: + - "**" + +enableScripts: true + +nodeLinker: node-modules diff --git a/package.json b/package.json index 6c9dec3..f60a4c8 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "description": "VSCode extension for Koishi developers", "version": "0.0.4", "license": "AGPL-3.0", + "packageManager": "yarn@4.14.1", "engines": { "vscode": "^1.140.0" }, @@ -13,11 +14,9 @@ "compile": "tsc -p ./", "convert": "tsx ./scripts/convert.ts", "watch": "tsc -watch -p ./", - "pretest": "yarn run compile && yarn run lint", "lint": "eslint src", - "test": "node ./out/test/runTest.js", - - "package": "vsce package" + "test": "yarn run compile && yarn run lint && node ./out/test/runTest.js", + "package": "vsce package --no-yarn" }, "repository": { "type": "git+https", diff --git a/src/test/suite/index.ts b/src/test/suite/index.ts index 86fe467..2655c79 100644 --- a/src/test/suite/index.ts +++ b/src/test/suite/index.ts @@ -1,8 +1,8 @@ import * as path from 'path' import * as Mocha from 'mocha' -import * as glob from 'glob' +import { globSync } from 'glob' -export function run(): Promise { +export async function run(): Promise { // Create the mocha test const mocha = new Mocha({ ui: 'tdd', @@ -11,28 +11,22 @@ export function run(): Promise { const testsRoot = path.resolve(__dirname, '..') - return new Promise((c, e) => { - glob('**/**.test.js', { cwd: testsRoot }, (err, files) => { - if (err) { - return e(err) - } + // Add files to the test suite + globSync('**/**.test.js', { cwd: testsRoot }).forEach((f) => + mocha.addFile(path.resolve(testsRoot, f)), + ) - // Add files to the test suite - files.forEach((f) => mocha.addFile(path.resolve(testsRoot, f))) - - try { - // Run the mocha test - mocha.run((failures) => { - if (failures > 0) { - e(new Error(`${failures} tests failed.`)) - } else { - c() - } - }) - } catch (err) { - console.error(err) - e(err) - } - }) + // Run the mocha test + const failures = await new Promise((c, e) => { + try { + mocha.run(c) + } catch (err) { + console.error(err) + e(err) + } }) + + if (failures > 0) { + throw new Error(`${failures} tests failed.`) + } } diff --git a/tsconfig.json b/tsconfig.json index bcf9429..516ee69 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -15,5 +15,5 @@ "declarationMap": true }, "include": ["src/**/*.ts"], - "exclude": ["src/test/**/*", "out/**/*", "scripts/**/*"] + "exclude": ["out/**/*", "scripts/**/*"] } diff --git a/yarn.lock b/yarn.lock index 20aefd1..2d344eb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,7 +2,7 @@ # Manual changes might be lost - proceed with caution! __metadata: - version: 8 + version: 9 cacheKey: 10c0 "@azure/abort-controller@npm:^2.0.0, @azure/abort-controller@npm:^2.1.2":