From a5b4de5ed175f6902ae2436d6d354f1a7181bf37 Mon Sep 17 00:00:00 2001 From: redat97 Date: Mon, 11 Dec 2023 13:34:56 -0500 Subject: [PATCH] issue #47: validate workflow behavior --- .github/workflows/vercel-deployment.yml | 42 ++++++++++++++----------- scripts/extract-typescript-version.js | 18 +++++++++++ src/_versions.ts | 2 +- 3 files changed, 42 insertions(+), 20 deletions(-) create mode 100644 scripts/extract-typescript-version.js diff --git a/.github/workflows/vercel-deployment.yml b/.github/workflows/vercel-deployment.yml index 738a295..309fc2f 100644 --- a/.github/workflows/vercel-deployment.yml +++ b/.github/workflows/vercel-deployment.yml @@ -2,27 +2,31 @@ name: Vercel Preview Deployment on: push: - branches: - - main - pull_request: + +env: + TYPESCRIPT_VERSION: 0.1.1 + FILE_PATH: "src/_version.ts" jobs: + extract-version: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 - lint-test: - uses: ai-cfia/github-workflows/.github/workflows/workflow-lint-test-node.yml@main + - name: Setup Node.js + uses: actions/setup-node@v2 + with: + node-version: '18' - vercel-deployment-dev: - needs: lint-test - uses: ai-cfia/github-workflows/.github/workflows/workflow-vercel-deployment.yml@53-update-vercel-deployment-to-add-setup-node-step - with: - project-name: 'finesse-frontend' - deployment-environment: 'dev' - secrets: inherit + - name: Extract Version + id: extract_version + run: node ./scripts/extract-typescript-version.js - vercel-deployment-uat: - if: github.ref == 'refs/heads/main' - uses: ai-cfia/github-workflows/.github/workflows/workflow-vercel-deployment.yml@53-update-vercel-deployment-to-add-setup-node-step - with: - project-name: 'finesse-frontend' - deployment-environment: 'uat' - secrets: inherit + - name: Check Version + run: | + if [ "${{ steps.extract_version.outputs.version }}" != "${{ env.TYPESCRIPT_VERSION }}" ]; then + echo "You should be using typescript version ${EXPECTED_VERSION} instead of ${{ steps.extract_version.outputs.version }} "; + exit 1; + fi diff --git a/scripts/extract-typescript-version.js b/scripts/extract-typescript-version.js new file mode 100644 index 0000000..3b062f6 --- /dev/null +++ b/scripts/extract-typescript-version.js @@ -0,0 +1,18 @@ +const fs = require('fs'); + +const filePath = 'src/_version.ts'; + +fs.readFile(filePath, 'utf8', (err, data) => { + if (err) { + console.error('Error reading the file:', err); + return; + } + + const versionMatch = data.match(/version: '([^']+)'/); + 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'); + } +}); diff --git a/src/_versions.ts b/src/_versions.ts index 667c9e0..21b4b6f 100644 --- a/src/_versions.ts +++ b/src/_versions.ts @@ -9,7 +9,7 @@ export interface TsAppVersion { gitTag?: string; }; export const versions: TsAppVersion = { - version: '0.2.0', + version: '0.1.0', name: 'finesse-frontend', versionDate: '2023-12-04T21:25:19.734Z', gitCommitHash: '1b203ac',