Skip to content

Commit

Permalink
add publish_step1_chec_version
Browse files Browse the repository at this point in the history
  • Loading branch information
boly38 committed Dec 2, 2024
1 parent 1c73980 commit d7608b2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
25 changes: 25 additions & 0 deletions .github/publish_step1_check_version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const packageJsonPath = path.resolve(__dirname, '../package.json');
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
const version = packageJson.version;

console.log(`Package version is ${version}`);

// Comparer avec le tag GitHub
const githubRefName = (process.env.GITHUB_REF_NAME || '').replace('refs/tags/', '');
if (githubRefName !== `v${version}`) {
console.error(`🔴 Error: Tag ${githubRefName} does not match version v${version}`);
process.exit(1);
}

// Exporter VERSION dans l'environnement GitHub Actions
const githubEnv = process.env.GITHUB_ENV;
if (githubEnv) {
fs.appendFileSync(githubEnv, `VERSION=${version}\n`);
}
17 changes: 7 additions & 10 deletions .github/workflows/try_win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,11 @@ jobs:
echo "jq --version"
jq --version
- name: 0) Read package.json version
id: package_version
- name: Check and Set Package Version
run: node .github/publish_step1_check_version.js
env:
GITHUB_REF_NAME: ${{ github.ref_name }}
- name: show env
id: show_env
run: |
# Extract the version from package.json and store it as an environment variable
for /f "delims=" %%i in ('jq -r ".version" package.json') do set VERSION=%%i
echo Package version is %VERSION%
if not "%GITHUB_REF_NAME%"=="v%VERSION%" (
echo 🔴 Error: Tag %GITHUB_REF_NAME% does not match version v%VERSION%
exit /b 1
)
echo "VERSION=%VERSION%" >> $GITHUB_ENV
echo "env.VERSION:${{ env.VERSION }}"

0 comments on commit d7608b2

Please sign in to comment.