Skip to content

Commit

Permalink
fix: GitHub action
Browse files Browse the repository at this point in the history
  • Loading branch information
vincehi committed Jun 28, 2024
1 parent 201c33c commit c49013d
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 39 deletions.
56 changes: 22 additions & 34 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
41 changes: 41 additions & 0 deletions tools/bump-tauri-version.js
Original file line number Diff line number Diff line change
@@ -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}`);
3 changes: 3 additions & 0 deletions tools/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import path from "path";
import { fileURLToPath } from "url";
export const DIRNAME = path.dirname(fileURLToPath(import.meta.url));
7 changes: 3 additions & 4 deletions tools/prisma-prepare-schema.js
Original file line number Diff line number Diff line change
@@ -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.");
Expand All @@ -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) => {
Expand Down

0 comments on commit c49013d

Please sign in to comment.