diff --git a/.github/workflows/validate-ts-version.yml b/.github/workflows/validate-ts-version.yml new file mode 100644 index 0000000..151da48 --- /dev/null +++ b/.github/workflows/validate-ts-version.yml @@ -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 diff --git a/scripts/extract-typescript-version.js b/scripts/extract-typescript-version.js new file mode 100644 index 0000000..4c66f85 --- /dev/null +++ b/scripts/extract-typescript-version.js @@ -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'); + } +});