From c49013d2661dd7f9d9f539bbf572de9df3e0a9fd Mon Sep 17 00:00:00 2001 From: VinceHi Date: Fri, 28 Jun 2024 22:46:05 +0200 Subject: [PATCH] fix: GitHub action --- .github/workflows/main.yml | 56 +++++++++++++--------------------- package.json | 3 +- tools/bump-tauri-version.js | 41 +++++++++++++++++++++++++ tools/constants.js | 3 ++ tools/prisma-prepare-schema.js | 7 ++--- 5 files changed, 71 insertions(+), 39 deletions(-) create mode 100755 tools/bump-tauri-version.js create mode 100644 tools/constants.js diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4958716..910520f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -35,37 +35,10 @@ jobs: next-release-version: ${{ steps.get-next-release.outputs.next-release-version }} next-release-git-tag: ${{ steps.get-next-release.outputs.next-release-git-tag }} next-release-notes: ${{ steps.get-next-release.outputs.next-release-notes }} - prepare-commit: - needs: get-next-release - if: needs.get-next-release.outputs.next-release-published == 'true' - runs-on: ubuntu-latest - permissions: - contents: write - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - name: Bump Cargo.toml version - run: | - sed -i 's/"version": "[0-9]\+\.[0-9]\+\.[0-9]\+"/"version": "${{ needs.get-next-release.outputs.next-release-version }}"/' src-tauri/tauri.conf.json - - name: Prepare commit changes - id: current-commit - run: | - git config user.name "github-actions" - git config user.email "github-actions@github.com" - git add src-tauri/tauri.conf.json - git commit -m "Bump version [skip ci]" - git push --dry-run - echo "last-commit-sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT" - - name: Show last commit SHA - run: | - echo "Last commit SHA: ${{ steps.current-commit.outputs.last-commit-sha }}" - outputs: - last-commit-sha: ${{ steps.current-commit.outputs.last-commit-sha }} build: needs: - get-next-release - - prepare-commit if: needs.get-next-release.outputs.next-release-published == 'true' permissions: contents: write @@ -85,8 +58,6 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v4 - with: - ref: ${{ needs.prepare-commit.outputs.last-commit-sha }} - name: Rust setup uses: dtolnay/rust-toolchain@stable @@ -117,6 +88,16 @@ jobs: # If you don't have `beforeBuildCommand` configured you may want to build your frontend here too. run: npm install # Change this to npm, yarn or pnpm. + - name: Bump tauri.config.json version + run: npm run bump-tauri-version ${{ needs.get-next-release.outputs.next-release-version }} + - name: Push commit + run: | + git config user.name "github-actions" + git config user.email "github-actions@github.com" + git add src-tauri/tauri.conf.json + git commit -m "Bump version [skip ci]" + git push --dry-run + - name: Build the app id: tauri-action uses: tauri-apps/tauri-action@v0.4.3 @@ -133,13 +114,20 @@ jobs: args: ${{ matrix.args }} push-changes: - needs: build + needs: + - get-next-release + - build if: success() runs-on: ubuntu-latest steps: - name: Checkout repository uses: actions/checkout@v4 - with: - ref: ${{ needs.prepare-commit.outputs.last-commit-sha }} - - name: Push commit changes - run: git push + - name: Bump tauri.config.json version + run: npm run bump-tauri-version ${{ needs.get-next-release.outputs.next-release-version }} + - name: Push commit + run: | + git config user.name "github-actions" + git config user.email "github-actions@github.com" + git add src-tauri/tauri.conf.json + git commit -m "Bump version [skip ci]" + git push diff --git a/package.json b/package.json index 0b914cc..2cbd55f 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,8 @@ "build": "vite build --config vite.config.js", "preview": "vite preview", "tauri": "tauri", - "semantic-release": "semantic-release" + "semantic-release": "semantic-release", + "bump-tauri-version": "node tools/bump-tauri-version.js" }, "devDependencies": { "@semantic-release/exec": "^6.0.3", diff --git a/tools/bump-tauri-version.js b/tools/bump-tauri-version.js new file mode 100755 index 0000000..9cb8402 --- /dev/null +++ b/tools/bump-tauri-version.js @@ -0,0 +1,41 @@ +import fs from "fs"; +import path from "path"; +import { DIRNAME } from "./constants.js"; + +const filePath = path.resolve(DIRNAME, "../src-tauri/tauri.conf.json"); +const newVersion = process.argv[2]; + +if (!newVersion) { + console.error("Version argument is required"); + process.exit(1); +} + +// Lire le contenu du fichier tauri.conf.json +const fileContent = fs.readFileSync(filePath, "utf8"); +const config = JSON.parse(fileContent); +const currentVersion = config.package.version; + +// Fonction pour comparer les versions +function isVersionGreater(newVer, currentVer) { + const newParts = newVer.split(".").map(Number); + const currentParts = currentVer.split(".").map(Number); + + for (let i = 0; i < newParts.length; i++) { + if (newParts[i] > currentParts[i]) return true; + if (newParts[i] < currentParts[i]) return false; + } + return false; +} + +if (!isVersionGreater(newVersion, currentVersion)) { + console.error("New version must be greater than the current version"); + process.exit(1); +} + +const updatedContent = fileContent.replace( + /"version": "\d+\.\d+\.\d+"/, + `"version": "${newVersion}"` +); + +fs.writeFileSync(filePath, updatedContent, "utf8"); +console.log(`Version updated to ${newVersion}`); diff --git a/tools/constants.js b/tools/constants.js new file mode 100644 index 0000000..e9f6912 --- /dev/null +++ b/tools/constants.js @@ -0,0 +1,3 @@ +import path from "path"; +import { fileURLToPath } from "url"; +export const DIRNAME = path.dirname(fileURLToPath(import.meta.url)); diff --git a/tools/prisma-prepare-schema.js b/tools/prisma-prepare-schema.js index e9499cb..fadc438 100644 --- a/tools/prisma-prepare-schema.js +++ b/tools/prisma-prepare-schema.js @@ -1,10 +1,9 @@ #!/usr/bin/env node import fs from "fs"; import path from "path"; -import { fileURLToPath } from "url"; -const filePath = process.argv[2]; +import { DIRNAME } from "./constants.js"; -const __dirname = path.dirname(fileURLToPath(import.meta.url)); +const filePath = process.argv[2]; if (!filePath) { console.error("No file path specified."); @@ -25,7 +24,7 @@ if (!filePath) { .replace(/generator client \{.*?\}/s, newString); fs.writeFile( - path.resolve(__dirname, "..", `schema.prisma`), + path.resolve(DIRNAME, "..", `schema.prisma`), result, "utf-8", (error) => {