From 9762a8fdba27c7891245c5260fb195f397e57f67 Mon Sep 17 00:00:00 2001 From: Alisue Date: Sat, 3 Aug 2024 18:09:26 +0900 Subject: [PATCH 1/2] :coffee: Check supported versions in CI --- .github/workflows/test.yml | 20 ++++- .scripts/apply-supported-versions.ts | 115 +++++++++++++++++++++++++++ README.md | 4 + deno.jsonc | 3 +- 4 files changed, 140 insertions(+), 2 deletions(-) create mode 100644 .scripts/apply-supported-versions.ts diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8bf2000..48ca53a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,11 +11,19 @@ on: - "deno.jsonc" - ".github/workflows/test.yml" workflow_dispatch: + inputs: + denops_branch: + description: 'Denops revision to test' + required: false + default: 'main' defaults: run: shell: bash --noprofile --norc -eo pipefail {0} +env: + DENOPS_BRANCH: ${{ github.event.inputs.denops_branch || 'main' }} + jobs: check: strategy: @@ -44,6 +52,11 @@ jobs: - name: Type check run: deno task check + - name: Supported version inconsistency check + run: | + deno task apply:supported-versions + git diff --exit-code + test: strategy: matrix: @@ -52,7 +65,7 @@ jobs: - macos-latest - ubuntu-latest deno_version: - - "1.45.x" + - "1.45.0" - "1.x" host_version: - vim: "v9.1.0448" @@ -75,6 +88,11 @@ jobs: git clone https://github.com/vim-denops/denops.vim /tmp/denops.vim echo "DENOPS_TEST_DENOPS_PATH=/tmp/denops.vim" >> "$GITHUB_ENV" + - name: Try switching denops branch + run: | + git -C /tmp/denops.vim switch ${{ env.DENOPS_BRANCH }} || true + git -C /tmp/denops.vim branch + - uses: rhysd/action-setup-vim@v1 id: vim with: diff --git a/.scripts/apply-supported-versions.ts b/.scripts/apply-supported-versions.ts new file mode 100644 index 0000000..0cf046a --- /dev/null +++ b/.scripts/apply-supported-versions.ts @@ -0,0 +1,115 @@ +import { ensure, is, type Predicate } from "jsr:@core/unknownutil@^4.0.0"; + +export type SupportedVersions = { + deno: string; + vim: string; + neovim: string; +}; + +const isSupportedVersions = is.ObjectOf({ + deno: is.String, + vim: is.String, + neovim: is.String, +}) satisfies Predicate; + +function getSupportedVersionJsonUrl(branch: string): URL { + return new URL( + `https://raw.githubusercontent.com/vim-denops/denops.vim/${branch}/denops/supported_versions.json`, + ); +} + +export async function loadSupportedVersions( + branch?: string, +): Promise { + const url = getSupportedVersionJsonUrl( + branch ?? Deno.env.get("DENOPS_BRANCH") ?? "main", + ); + const resp = await fetch(url); + const json = await resp.json(); + return ensure(json, isSupportedVersions); +} + +async function updateREADME( + supportedVersions: SupportedVersions, +): Promise { + const url = new URL(import.meta.resolve("../README.md")); + let text = await Deno.readTextFile(url); + // Deno + text = text.replace( + /Deno\s+\d+\.\d+\.\d+/, + `Deno ${supportedVersions.deno}`, + ); + text = text.replace( + /Deno-Support%20\d+\.\d+\.\d+/, + `Deno-Support%20${supportedVersions.deno}`, + ); + text = text.replace( + /https:\/\/github\.com\/denoland\/deno\/tree\/v\d+\.\d+\.\d+/, + `https://github.com/denoland/deno/tree/v${supportedVersions.deno}`, + ); + // Vim + text = text.replace( + /Vim\s+\d+\.\d+\.\d+/, + `Vim ${supportedVersions.vim}`, + ); + text = text.replace( + /Vim-Support%20\d+\.\d+\.\d+/, + `Vim-Support%20${supportedVersions.vim}`, + ); + text = text.replace( + /https:\/\/github\.com\/vim\/vim\/tree\/v\d+\.\d+\.\d+/, + `https://github.com/vim/vim/tree/v${supportedVersions.vim}`, + ); + // Neovim + text = text.replace( + /Neovim\s+\d+\.\d+\.\d+/, + `Neovim ${supportedVersions.neovim}`, + ); + text = text.replace( + /Neovim-Support%20\d+\.\d+\.\d+/, + `Neovim-Support%20${supportedVersions.neovim}`, + ); + text = text.replace( + /https:\/\/github\.com\/neovim\/neovim\/tree\/v\d+\.\d+\.\d+/, + `https://github.com/neovim/neovim/tree/v${supportedVersions.neovim}`, + ); + await Deno.writeTextFile(url, text); +} + +async function updateGithubWorkflowsTest( + supportedVersions: SupportedVersions, +): Promise { + const url = new URL(import.meta.resolve("../.github/workflows/test.yml")); + let text = await Deno.readTextFile(url); + // Deno + text = text.replace( + /deno_version:(.*?)"\d+\.\d+\.\d+"/s, + `deno_version:$1"${supportedVersions.deno}"`, + ); + // Vim + text = text.replace( + /vim:(.*?)"v\d+\.\d+\.\d+"/s, + `vim:$1"v${supportedVersions.vim}"`, + ); + // Neovim + text = text.replace( + /nvim:(.*?)"v\d+\.\d+\.\d+"/s, + `nvim:$1"v${supportedVersions.neovim}"`, + ); + await Deno.writeTextFile(url, text); +} + +async function main(): Promise { + const supportedVersions = await loadSupportedVersions(); + await updateREADME(supportedVersions); + await updateGithubWorkflowsTest(supportedVersions); +} + +if (import.meta.main) { + try { + await main(); + } catch (error) { + console.error(error); + Deno.exit(1); + } +} diff --git a/README.md b/README.md index ff740b6..e97a3af 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,10 @@ [![Test](https://github.com/vim-denops/deno-denops-test/actions/workflows/test.yml/badge.svg)](https://github.com/vim-denops/deno-denops-test/actions/workflows/test.yml) [![codecov](https://codecov.io/github/vim-denops/deno-denops-test/branch/main/graph/badge.svg?token=X9O5XB4O1S)](https://codecov.io/github/vim-denops/deno-denops-test) +[![Deno 1.45.0 or above](https://img.shields.io/badge/Deno-Support%201.45.0-yellowgreen.svg?logo=deno)](https://github.com/denoland/deno/tree/v1.45.0) +[![Vim 9.1.0448 or above](https://img.shields.io/badge/Vim-Support%209.1.0448-yellowgreen.svg?logo=vim)](https://github.com/vim/vim/tree/v9.1.0448) +[![Neovim 0.10.0 or above](https://img.shields.io/badge/Neovim-Support%200.10.0-yellowgreen.svg?logo=neovim&logoColor=white)](https://github.com/neovim/neovim/tree/v0.10.0) + A [Deno] module designed for testing [denops.vim]. This module is intended to be used in the unit tests of denops plugins. diff --git a/deno.jsonc b/deno.jsonc index fbd0fe0..78ef2e1 100644 --- a/deno.jsonc +++ b/deno.jsonc @@ -27,7 +27,8 @@ "test:coverage": "deno task test --coverage=.coverage", "coverage": "deno coverage .coverage", "update": "deno run --allow-env --allow-read --allow-write=. --allow-run=git,deno --allow-net=jsr.io,registry.npmjs.org jsr:@molt/cli ./*.ts", - "update:commit": "deno task -q update --commit --pre-commit=fmt,lint" + "update:commit": "deno task -q update --commit --pre-commit=fmt,lint", + "apply:supported-versions": "deno run --allow-env --allow-net --allow-read --allow-write .scripts/apply-supported-versions.ts" }, "imports": { "jsr:@denops/test": "./mod.ts" From d8dcebda3a28160376ff4b7499f22bdf8c972b0c Mon Sep 17 00:00:00 2001 From: Alisue Date: Sat, 3 Aug 2024 18:16:28 +0900 Subject: [PATCH 2/2] :memo: Update GitHub Action example in README --- README.md | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e97a3af..a2e860c 100644 --- a/README.md +++ b/README.md @@ -89,11 +89,33 @@ Deno.test("denops.call", async () => { Copy and modify the following GitHub Workflow to run tests in GitHub Action ```yaml +name: Test + +on: + push: + branches: + - main + pull_request: + paths: + - "**.md" + - "**.ts" + - "deno.jsonc" + - ".github/workflows/test.yml" + workflow_dispatch: + inputs: + denops_branch: + description: 'Denops branch to test' + required: false + default: 'main' + # Use 'bash' as default shell even on Windows defaults: run: shell: bash --noprofile --norc -eo pipefail {0} +env: + DENOPS_BRANCH: ${{ github.event.inputs.denops_branch || 'main' }} + jobs: test: strategy: @@ -103,7 +125,7 @@ jobs: - macos-latest - ubuntu-latest deno_version: - - "1.45.x" + - "1.45.0" - "1.x" host_version: - vim: "v9.1.0448" @@ -126,6 +148,11 @@ jobs: git clone https://github.com/vim-denops/denops.vim /tmp/denops.vim echo "DENOPS_TEST_DENOPS_PATH=/tmp/denops.vim" >> "$GITHUB_ENV" + - name: Try switching denops branch + run: | + git -C /tmp/denops.vim switch ${{ env.DENOPS_BRANCH }} || true + git -C /tmp/denops.vim branch + - uses: rhysd/action-setup-vim@v1 id: vim with: