Skip to content

Commit

Permalink
☕ Add apply:supported-versions task and CI
Browse files Browse the repository at this point in the history
  • Loading branch information
lambdalisue committed Aug 3, 2024
1 parent d3a4d4d commit de48a62
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ jobs:
run: deno fmt --check
- name: Type check
run: deno task check
- name: Supported version inconsistency check
run: |
deno task apply:supported-versions
git diff --exit-code
test:
needs: check
Expand Down
102 changes: 102 additions & 0 deletions .scripts/apply_supported_versions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import supportedVersions from "../denops/supported_versions.json" with {
type: "json",
};

async function main(): Promise<void> {
await updateREADME();
await updatePluginDenops();
await updateGithubWorkflowsTest();
}

async function updateREADME(): 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 updatePluginDenops(): Promise<void> {
const url = new URL(import.meta.resolve("../plugin/denops.vim"));
let text = await Deno.readTextFile(url);
// Vim
text = text.replace(/patch-\d+\.\d+\.\d+/, `patch-${supportedVersions.vim}`);
text = text.replace(
/Vim\s+\d+\.\d+\.\d+/,
`Vim ${supportedVersions.vim}`,
);
// Neovim
text = text.replace(/nvim-\d+\.\d+\.\d+/, `nvim-${supportedVersions.neovim}`);
text = text.replace(
/Neovim\s+\d+\.\d+\.\d+/,
`Neovim ${supportedVersions.neovim}`,
);
await Deno.writeTextFile(url, text);
}

async function updateGithubWorkflowsTest(): 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);
}

if (import.meta.main) {
try {
await main();
} catch (error) {
console.error(error);
Deno.exit(1);
}
}
3 changes: 2 additions & 1 deletion deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"coverage": "deno coverage --exclude=\"test[.]ts(#.*)?$\" .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:write": "deno task -q update --write",
"update:commit": "deno task -q update --commit --prefix :package: --pre-commit=fmt,lint"
"update:commit": "deno task -q update --commit --prefix :package: --pre-commit=fmt,lint",
"apply:supported-versions": "deno run --allow-read --allow-write .scripts/apply_supported_versions.ts"
},
"exclude": [
".coverage/"
Expand Down

0 comments on commit de48a62

Please sign in to comment.