11#!/usr/bin/env node
22
33/**
4- * Linux release build: run `tauri build`, then rewrite the .deb dependency
5- * metadata so installs work on Debian and Ubuntu.
4+ * Rewrites .deb dependency metadata so installs work on Debian and Ubuntu, then
5+ * re-uploads the patched package to the GitHub release (overwriting the asset
6+ * that tauri-action just uploaded).
67 *
78 * Tauri's bundler emits Ubuntu 22.04 package names (libappindicator3-1,
89 * libgtk-3-0). Debian and newer Ubuntu releases use libayatana-appindicator3-1
910 * and libgtk-3-0t64 instead, so we declare both alternatives.
11+ *
12+ * Runs as a post-build step in CI. Re-upload is skipped when RELEASE_ID is not
13+ * set, so the script can also be run locally to patch a build.
1014 */
1115
1216import fs from 'node:fs'
@@ -20,19 +24,6 @@ const repoRoot = path.join(__dirname, '..')
2024const COMPATIBLE_DEPENDS =
2125 'libayatana-appindicator3-1 | libappindicator3-1, libwebkit2gtk-4.1-0, libgtk-3-0t64 | libgtk-3-0'
2226
23- function runTauriBuild ( args ) {
24- if ( args . length === 0 ) {
25- console . error ( 'Usage: node scripts/tauri-build-linux.js <tauri args...>' )
26- process . exit ( 1 )
27- }
28-
29- execSync ( `npx tauri ${ args . map ( ( arg ) => JSON . stringify ( arg ) ) . join ( ' ' ) } ` , {
30- cwd : repoRoot ,
31- stdio : 'inherit' ,
32- shell : true ,
33- } )
34- }
35-
3627function findDebArtifacts ( ) {
3728 const debDir = path . join ( repoRoot , 'src-tauri/target/release/bundle/deb' )
3829 if ( ! fs . existsSync ( debDir ) ) {
@@ -48,12 +39,9 @@ function findDebArtifacts() {
4839function patchDeb ( debPath ) {
4940 const tmpDir = fs . mkdtempSync ( path . join ( '/tmp' , 'altsendme-deb-' ) )
5041 try {
51- execSync (
52- `dpkg-deb -R ${ JSON . stringify ( debPath ) } ${ JSON . stringify ( tmpDir ) } ` ,
53- {
54- stdio : 'pipe' ,
55- }
56- )
42+ execSync ( `dpkg-deb -R ${ JSON . stringify ( debPath ) } ${ JSON . stringify ( tmpDir ) } ` , {
43+ stdio : 'pipe' ,
44+ } )
5745
5846 const controlPath = path . join ( tmpDir , 'DEBIAN' , 'control' )
5947 const original = fs . readFileSync ( controlPath , 'utf8' )
@@ -67,31 +55,58 @@ function patchDeb(debPath) {
6755 )
6856 if ( patched === original ) {
6957 console . log ( `Already compatible: ${ debPath } ` )
70- return
58+ return false
7159 }
7260
7361 fs . writeFileSync ( controlPath , patched )
74- execSync (
75- `dpkg-deb -b ${ JSON . stringify ( tmpDir ) } ${ JSON . stringify ( debPath ) } ` ,
76- {
77- stdio : 'pipe' ,
78- }
79- )
62+ execSync ( `dpkg-deb -b ${ JSON . stringify ( tmpDir ) } ${ JSON . stringify ( debPath ) } ` , {
63+ stdio : 'pipe' ,
64+ } )
8065
8166 console . log ( `Patched ${ debPath } ` )
8267 console . log ( ` Depends: ${ COMPATIBLE_DEPENDS } ` )
68+ return true
8369 } finally {
8470 fs . rmSync ( tmpDir , { recursive : true , force : true } )
8571 }
8672}
8773
88- runTauriBuild ( process . argv . slice ( 2 ) )
74+ function reuploadAsset ( debPath ) {
75+ const releaseId = process . env . RELEASE_ID
76+ const repo = process . env . GITHUB_REPOSITORY
77+ if ( ! releaseId || ! repo ) {
78+ console . log ( 'RELEASE_ID/GITHUB_REPOSITORY not set; skipping re-upload.' )
79+ return
80+ }
81+
82+ const name = path . basename ( debPath )
83+ const assetId = execSync (
84+ `gh api "repos/${ repo } /releases/${ releaseId } /assets" --jq ".[] | select(.name == \\"${ name } \\") | .id // empty"`
85+ )
86+ . toString ( )
87+ . trim ( )
88+
89+ if ( assetId ) {
90+ execSync ( `gh api --method DELETE "repos/${ repo } /releases/assets/${ assetId } "` , {
91+ stdio : 'pipe' ,
92+ } )
93+ }
94+
95+ execSync (
96+ `gh api --method POST -H "Content-Type: application/vnd.debian.binary-package" --input ${ JSON . stringify ( debPath ) } "https://uploads.github.com/repos/${ repo } /releases/${ releaseId } /assets?name=${ name } "` ,
97+ { stdio : 'pipe' }
98+ )
99+ console . log ( `Re-uploaded ${ name } to release ${ releaseId } ` )
100+ }
89101
90102const debPaths = findDebArtifacts ( )
91103if ( debPaths . length === 0 ) {
92104 console . log ( 'No .deb artifacts found; skipping dependency patch.' )
93105} else {
94106 for ( const debPath of debPaths ) {
95- patchDeb ( debPath )
107+ const changed = patchDeb ( debPath )
108+ if ( changed ) {
109+ reuploadAsset ( debPath )
110+ }
96111 }
97112}
0 commit comments