Skip to content

Commit

Permalink
Merge pull request #32 from vim-denops/check-supported-versions
Browse files Browse the repository at this point in the history
☕ Check supported versions in CI
  • Loading branch information
lambdalisue authored Aug 3, 2024
2 parents 30ff1ea + d8dcebd commit a57a9cd
Show file tree
Hide file tree
Showing 4 changed files with 168 additions and 3 deletions.
20 changes: 19 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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"
Expand All @@ -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:
Expand Down
115 changes: 115 additions & 0 deletions .scripts/apply-supported-versions.ts
Original file line number Diff line number Diff line change
@@ -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<SupportedVersions>;

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<SupportedVersions> {
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<void> {
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<void> {
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<void> {
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);
}
}
33 changes: 32 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -85,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:
Expand All @@ -99,7 +125,7 @@ jobs:
- macos-latest
- ubuntu-latest
deno_version:
- "1.45.x"
- "1.45.0"
- "1.x"
host_version:
- vim: "v9.1.0448"
Expand All @@ -122,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:
Expand Down
3 changes: 2 additions & 1 deletion deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit a57a9cd

Please sign in to comment.