Skip to content

Commit a4df2e2

Browse files
authored
Pull release number from cargo.toml (#16)
* pull release number from cargo.toml * skip release if tag already exists
1 parent c65b4d9 commit a4df2e2

File tree

3 files changed

+73
-18
lines changed

3 files changed

+73
-18
lines changed

.github/workflows/release.yml

Lines changed: 72 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,90 @@ concurrency:
1717
cancel-in-progress: true
1818

1919
env:
20+
APP_CARGO_TOML: src-tauri/Cargo.toml
2021
CN_APP_SLUG: ${{ github.event.inputs.app-slug || 'quantum' }}
2122

2223
jobs:
2324
draft:
2425
runs-on: ubuntu-latest
25-
26+
outputs:
27+
tag_name: ${{ steps.read_version.outputs.value }}
28+
needs_release: ${{ steps.create_tag.outputs.tag_existed != 'true' }}
29+
permissions:
30+
contents: write
2631
steps:
2732
- uses: actions/checkout@v4
2833

29-
- name: create draft release
34+
- name: Read version number
35+
uses: SebRollen/toml-action@v1.0.2
36+
id: read_version
37+
with:
38+
file: ${{ env.APP_CARGO_TOML }}
39+
field: "package.version"
40+
41+
- name: Create tag
42+
id: create_tag
43+
uses: actions/github-script@v7
44+
with:
45+
script: |
46+
const tag = "${{ steps.read_version.outputs.value }}";
47+
const tagRef = `tags/${tag}`;
48+
49+
const TAG_EXISTED = "tag_existed";
50+
51+
async function main() {
52+
let tagExisted = true;
53+
54+
try {
55+
await github.rest.git.getRef({
56+
ref: tagRef,
57+
owner: context.repo.owner,
58+
repo: context.repo.repo,
59+
});
60+
61+
tagExisted = true;
62+
core.notice(`Release skipped as tag '${tag}' already exists. Update the version in '${{ env.APP_CARGO_TOML }}' to perform a release.`);
63+
} catch (error) {
64+
if ("status" in error && error.status === 404) tagExisted = false;
65+
else throw error;
66+
}
67+
68+
core.setOutput(TAG_EXISTED, tagExisted);
69+
70+
if (!tagExisted)
71+
await github.rest.git.createRef({
72+
ref: `refs/${tagRef}`,
73+
owner: context.repo.owner,
74+
repo: context.repo.repo,
75+
sha: context.sha,
76+
});
77+
}
78+
79+
main();
80+
81+
- name: Create draft release
82+
if: ${{ steps.create_tag.outputs.tag_existed != 'true' }}
3083
uses: crabnebula-dev/cloud-release@v0.1.0
3184
with:
32-
command: release draft ${{ env.CN_APP_SLUG }} --framework tauri
85+
command: release draft ${{ vars.CN_APP_ID }} "${{ steps.read_version.outputs.value }}" --framework tauri
3386
api-key: ${{ secrets.CN_API_KEY }}
3487

3588
build:
3689
needs: draft
37-
90+
runs-on: ${{ matrix.os }}
91+
if: ${{ needs.draft.outputs.needs_release == 'true' }}
3892
strategy:
3993
fail-fast: false
4094
matrix:
41-
os: [ubuntu-latest, macos-latest, windows-latest]
42-
43-
runs-on: ${{ matrix.os }}
44-
95+
settings:
96+
- host: macos-latest
97+
target: x86_64-apple-darwin
98+
- host: macos-latest
99+
target: aarch64-apple-darwin
100+
- host: windows-latest
101+
target: x86_64-pc-windows-msvc
102+
- host: ubuntu-latest
103+
target: x86_64-unknown-linux-gnu
45104
steps:
46105
- uses: actions/checkout@v4
47106
- name: Install pnpm
@@ -59,35 +118,33 @@ jobs:
59118
cache: false
60119

61120
- name: install Linux dependencies
62-
if: matrix.os == 'ubuntu-latest'
121+
if: matrix.host == 'ubuntu-latest'
63122
run: |
64123
sudo apt-get update
65124
sudo apt-get install -y libwebkit2gtk-4.0-dev webkit2gtk-4.1
66125
67126
- name: build tauri app
68127
run: |
69128
pnpm install
70-
pnpm run tauri build
129+
pnpm run tauri build --ci --target ${{ matrix.settings.target }}
71130
env:
72131
TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY }}
73132
TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY_PASSWORD }}
74133

75134
- name: upload assets
76135
uses: crabnebula-dev/cloud-release@v0.1.0
77136
with:
78-
command: release upload ${{ env.CN_APP_SLUG }} --framework tauri
137+
command: release upload ${{ env.CN_APP_SLUG }} "${{ steps.read_version.outputs.value }}" --framework tauri
79138
api-key: ${{ secrets.CN_API_KEY }}
80139

81140
publish:
82-
needs: build
83-
141+
needs: [draft, build]
84142
runs-on: ubuntu-latest
85-
86143
steps:
87144
- uses: actions/checkout@v4
88145

89146
- name: publish release
90147
uses: crabnebula-dev/cloud-release@v0.1.0
91148
with:
92-
command: release publish ${{ env.CN_APP_SLUG }} --framework tauri
149+
command: release publish ${{ env.CN_APP_SLUG }} "${{ needs.draft.outputs.tag_name }}" --framework tauri
93150
api-key: ${{ secrets.CN_API_KEY }}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "quantum",
3-
"version": "0.0.0",
3+
"private": true,
44
"type": "module",
55
"description": "",
66
"scripts": {

src-tauri/tauri.conf.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"$schema": "../node_modules/@tauri-apps/cli/schema.json",
33
"productName": "quantum",
4-
"version": "0.0.0",
54
"identifier": "quantum.template.dev",
65
"build": {
76
"beforeDevCommand": "pnpm dev",
@@ -17,7 +16,6 @@
1716
"pubkey": "public key"
1817
}
1918
},
20-
2119
"app": {
2220
"windows": [
2321
{

0 commit comments

Comments
 (0)