Skip to content

Commit c49013d

Browse files
authored
fix: GitHub action
1 parent 201c33c commit c49013d

File tree

5 files changed

+71
-39
lines changed

5 files changed

+71
-39
lines changed

.github/workflows/main.yml

Lines changed: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -35,37 +35,10 @@ jobs:
3535
next-release-version: ${{ steps.get-next-release.outputs.next-release-version }}
3636
next-release-git-tag: ${{ steps.get-next-release.outputs.next-release-git-tag }}
3737
next-release-notes: ${{ steps.get-next-release.outputs.next-release-notes }}
38-
prepare-commit:
39-
needs: get-next-release
40-
if: needs.get-next-release.outputs.next-release-published == 'true'
41-
runs-on: ubuntu-latest
42-
permissions:
43-
contents: write
44-
steps:
45-
- name: Checkout repository
46-
uses: actions/checkout@v4
47-
- name: Bump Cargo.toml version
48-
run: |
49-
sed -i 's/"version": "[0-9]\+\.[0-9]\+\.[0-9]\+"/"version": "${{ needs.get-next-release.outputs.next-release-version }}"/' src-tauri/tauri.conf.json
50-
- name: Prepare commit changes
51-
id: current-commit
52-
run: |
53-
git config user.name "github-actions"
54-
git config user.email "github-actions@github.com"
55-
git add src-tauri/tauri.conf.json
56-
git commit -m "Bump version [skip ci]"
57-
git push --dry-run
58-
echo "last-commit-sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
59-
- name: Show last commit SHA
60-
run: |
61-
echo "Last commit SHA: ${{ steps.current-commit.outputs.last-commit-sha }}"
62-
outputs:
63-
last-commit-sha: ${{ steps.current-commit.outputs.last-commit-sha }}
6438

6539
build:
6640
needs:
6741
- get-next-release
68-
- prepare-commit
6942
if: needs.get-next-release.outputs.next-release-published == 'true'
7043
permissions:
7144
contents: write
@@ -85,8 +58,6 @@ jobs:
8558
steps:
8659
- name: Checkout repository
8760
uses: actions/checkout@v4
88-
with:
89-
ref: ${{ needs.prepare-commit.outputs.last-commit-sha }}
9061

9162
- name: Rust setup
9263
uses: dtolnay/rust-toolchain@stable
@@ -117,6 +88,16 @@ jobs:
11788
# If you don't have `beforeBuildCommand` configured you may want to build your frontend here too.
11889
run: npm install # Change this to npm, yarn or pnpm.
11990

91+
- name: Bump tauri.config.json version
92+
run: npm run bump-tauri-version ${{ needs.get-next-release.outputs.next-release-version }}
93+
- name: Push commit
94+
run: |
95+
git config user.name "github-actions"
96+
git config user.email "github-actions@github.com"
97+
git add src-tauri/tauri.conf.json
98+
git commit -m "Bump version [skip ci]"
99+
git push --dry-run
100+
120101
- name: Build the app
121102
id: tauri-action
122103
uses: tauri-apps/tauri-action@v0.4.3
@@ -133,13 +114,20 @@ jobs:
133114
args: ${{ matrix.args }}
134115

135116
push-changes:
136-
needs: build
117+
needs:
118+
- get-next-release
119+
- build
137120
if: success()
138121
runs-on: ubuntu-latest
139122
steps:
140123
- name: Checkout repository
141124
uses: actions/checkout@v4
142-
with:
143-
ref: ${{ needs.prepare-commit.outputs.last-commit-sha }}
144-
- name: Push commit changes
145-
run: git push
125+
- name: Bump tauri.config.json version
126+
run: npm run bump-tauri-version ${{ needs.get-next-release.outputs.next-release-version }}
127+
- name: Push commit
128+
run: |
129+
git config user.name "github-actions"
130+
git config user.email "github-actions@github.com"
131+
git add src-tauri/tauri.conf.json
132+
git commit -m "Bump version [skip ci]"
133+
git push

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"build": "vite build --config vite.config.js",
1515
"preview": "vite preview",
1616
"tauri": "tauri",
17-
"semantic-release": "semantic-release"
17+
"semantic-release": "semantic-release",
18+
"bump-tauri-version": "node tools/bump-tauri-version.js"
1819
},
1920
"devDependencies": {
2021
"@semantic-release/exec": "^6.0.3",

tools/bump-tauri-version.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import fs from "fs";
2+
import path from "path";
3+
import { DIRNAME } from "./constants.js";
4+
5+
const filePath = path.resolve(DIRNAME, "../src-tauri/tauri.conf.json");
6+
const newVersion = process.argv[2];
7+
8+
if (!newVersion) {
9+
console.error("Version argument is required");
10+
process.exit(1);
11+
}
12+
13+
// Lire le contenu du fichier tauri.conf.json
14+
const fileContent = fs.readFileSync(filePath, "utf8");
15+
const config = JSON.parse(fileContent);
16+
const currentVersion = config.package.version;
17+
18+
// Fonction pour comparer les versions
19+
function isVersionGreater(newVer, currentVer) {
20+
const newParts = newVer.split(".").map(Number);
21+
const currentParts = currentVer.split(".").map(Number);
22+
23+
for (let i = 0; i < newParts.length; i++) {
24+
if (newParts[i] > currentParts[i]) return true;
25+
if (newParts[i] < currentParts[i]) return false;
26+
}
27+
return false;
28+
}
29+
30+
if (!isVersionGreater(newVersion, currentVersion)) {
31+
console.error("New version must be greater than the current version");
32+
process.exit(1);
33+
}
34+
35+
const updatedContent = fileContent.replace(
36+
/"version": "\d+\.\d+\.\d+"/,
37+
`"version": "${newVersion}"`
38+
);
39+
40+
fs.writeFileSync(filePath, updatedContent, "utf8");
41+
console.log(`Version updated to ${newVersion}`);

tools/constants.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import path from "path";
2+
import { fileURLToPath } from "url";
3+
export const DIRNAME = path.dirname(fileURLToPath(import.meta.url));

tools/prisma-prepare-schema.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
#!/usr/bin/env node
22
import fs from "fs";
33
import path from "path";
4-
import { fileURLToPath } from "url";
5-
const filePath = process.argv[2];
4+
import { DIRNAME } from "./constants.js";
65

7-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
6+
const filePath = process.argv[2];
87

98
if (!filePath) {
109
console.error("No file path specified.");
@@ -25,7 +24,7 @@ if (!filePath) {
2524
.replace(/generator client \{.*?\}/s, newString);
2625

2726
fs.writeFile(
28-
path.resolve(__dirname, "..", `schema.prisma`),
27+
path.resolve(DIRNAME, "..", `schema.prisma`),
2928
result,
3029
"utf-8",
3130
(error) => {

0 commit comments

Comments
 (0)