Skip to content

Commit ba32426

Browse files
committed
Use script instead of marketplace action
1 parent 5612472 commit ba32426

File tree

3 files changed

+97
-40
lines changed

3 files changed

+97
-40
lines changed

.github/actions/env.ts

Lines changed: 0 additions & 28 deletions
This file was deleted.

.github/actions/release.ts

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import path from 'path'
2+
import { fileURLToPath } from 'url'
3+
import fs from 'node:fs/promises'
4+
import child_process from 'child_process'
5+
import { promisify } from 'util'
6+
import * as github from '@actions/github'
7+
8+
const exec = promisify(child_process.exec)
9+
10+
declare global {
11+
namespace NodeJS {
12+
interface ProcessEnv {
13+
CLIENT_SECRET: string
14+
CLIENT_ID: string
15+
GITHUB_TOKEN: string
16+
}
17+
}
18+
}
19+
20+
const dirname = path.dirname(fileURLToPath(import.meta.url))
21+
const envPath = path.join(dirname, '..', '..', '.env')
22+
const tauriConfPath = path.join(dirname, '..', '..', 'src-tauri', 'tauri.conf.json')
23+
const packageJsonPath = path.join(dirname, '..', '..', 'package.json')
24+
const token = process.env.GITHUB_TOKEN
25+
const secret = process.env.CLIENT_SECRET
26+
const id = process.env.CLIENT_ID
27+
28+
const envFileContent = `\
29+
VITE_CLIENT_SECRET=${secret}
30+
VITE_CLIENT_ID=${id}
31+
`
32+
33+
async function run() {
34+
await fs.writeFile(envPath, envFileContent, 'utf-8')
35+
await exec('pnpm tauri build --target universal-apple-darwin')
36+
37+
const tauriConf = JSON.parse(
38+
await fs.readFile(tauriConfPath, 'utf-8'),
39+
) as typeof import('../../src-tauri/tauri.conf.json')
40+
41+
const packageJSON = JSON.parse(
42+
await fs.readFile(packageJsonPath, 'utf-8'),
43+
) as typeof import('../../package.json')
44+
45+
if (packageJSON.version !== tauriConf.package.version)
46+
throw new Error('Tauri config and Package JSON versions are not the same, update both of them!')
47+
48+
const dmgFileName = `Gitification_${packageJSON.version}_universal.dmg`
49+
50+
const dmgPath = path.join(
51+
dirname,
52+
'..',
53+
'..',
54+
'src-tauri',
55+
'target',
56+
'universal-apple-darwin',
57+
'release',
58+
'bundle',
59+
'dmg',
60+
dmgFileName,
61+
)
62+
63+
const octokit = github.getOctokit(token)
64+
65+
const remoteRelease = await octokit.rest.repos.getLatestRelease({
66+
owner: 'Gitification-App',
67+
repo: 'gitification',
68+
})
69+
70+
if (remoteRelease.data.name === packageJSON.version.toString()) {
71+
console.log('No version change detected, skipping build.')
72+
return
73+
}
74+
75+
const release = await octokit.rest.repos.createRelease({
76+
owner: 'Gitification-App',
77+
repo: 'gitification',
78+
tag_name: packageJSON.version.toString(),
79+
name: packageJSON.version.toString(),
80+
})
81+
82+
octokit.rest.repos.uploadReleaseAsset({
83+
owner: 'Gitification-App',
84+
repo: 'gitification',
85+
name: dmgFileName,
86+
release_id: release.data.id,
87+
// @ts-expect-error type
88+
data: (await fs.readFile(dmgPath)).buffer,
89+
})
90+
}
91+
92+
run()

.github/workflows/release.yml

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,15 @@ jobs:
2727
with:
2828
version: latest
2929

30-
- name: Create ENV
31-
run: pnpx tsx .github/actions/env.ts
32-
env:
33-
CLIENT_SECRET: ${{ secrets.CLIENT_SECRET }}
34-
CLIENT_ID: ${{ secrets.CLIENT_ID }}
35-
3630
- name: install Rust stable
3731
uses: dtolnay/rust-toolchain@stable
3832
with:
3933
targets: 'aarch64-apple-darwin,x86_64-apple-darwin'
4034

41-
- uses: tauri-apps/tauri-action@v0
35+
- name: Run Release
36+
run: pnpx tsx .github/actions/release.ts
4237
env:
38+
CLIENT_SECRET: ${{ secrets.CLIENT_SECRET }}
39+
CLIENT_ID: ${{ secrets.CLIENT_ID }}
4340
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
44-
with:
45-
tagName: gitification-v__VERSION__
46-
releaseName: 'Gitification v__VERSION__'
47-
prerelease: false
48-
# args: --target universal-apple-darwin
41+

0 commit comments

Comments
 (0)