Skip to content

Commit

Permalink
issue #47: add workflow and script
Browse files Browse the repository at this point in the history
issue #47: add workflow and script
  • Loading branch information
vivalareda committed Dec 12, 2023
1 parent fd03251 commit fda0c51
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/validate-ts-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: TS version validation

on:
push:

env:
TYPESCRIPT_VERSION: ${{ secrets.TYPESCRIPT_VERSION }}
SCRIPT_PATH: "./scripts/extract-typescript-version.js"

jobs:
extract-version:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '18'

- name: Extract Version
id: extract_version
run: node ${{ env.SCRIPT_PATH }}

- name: Check Version
run: |
if [ "${{ steps.extract_version.outputs.version }}" != "${{ env.TYPESCRIPT_VERSION }}" ]; then
echo "Please change the TypeScript version to ${{ env.TYPESCRIPT_VERSION }} in your _versions.ts file";
exit 1;
fi
18 changes: 18 additions & 0 deletions scripts/extract-typescript-version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const fs = require('fs');

const filePath = 'src/_versions.ts';

fs.readFile(filePath, 'utf8', (err, data) => {
if (err) {
console.error('Error reading the file:', err);
return;
}

const versionMatch = data.match(/version:\s*'(\d+\.\d+\.\d+)'/);
if (versionMatch && versionMatch[1]) {
console.log("Extracted Version:", versionMatch[1]);
process.stdout.write(`::set-output name=version::${versionMatch[1]}`);
} else {
console.error('Version could not be extracted');
}
});

0 comments on commit fda0c51

Please sign in to comment.