From 3a13c654d379ab67f9abab0f40cb0ef42d656ea7 Mon Sep 17 00:00:00 2001 From: Neko Ayaka Date: Fri, 31 Oct 2025 17:55:50 +0800 Subject: [PATCH] chore(ci): improve rename and bundle name of flatpak --- .github/workflows/release-tamagotchi.yml | 8 +-- .../scripts/artifacts-metadata.ts | 16 ++++++ apps/stage-tamagotchi/scripts/utils.ts | 50 ++++++++++++++++++- 3 files changed, 70 insertions(+), 4 deletions(-) diff --git a/.github/workflows/release-tamagotchi.yml b/.github/workflows/release-tamagotchi.yml index 3dc90b94a..a84f02162 100644 --- a/.github/workflows/release-tamagotchi.yml +++ b/.github/workflows/release-tamagotchi.yml @@ -147,12 +147,12 @@ jobs: if: ${{ matrix.os == 'ubuntu-latest' || matrix.os == 'ubuntu-24.04-arm' }} working-directory: ./apps/stage-tamagotchi run: | - mkdir -p bundle + mkdir -p dist # Auto-install required SDK/Platform/BaseApp from Flathub in user scope flatpak-builder --user --install-deps-from=flathub ./flatpak ai.moeru.airi.flatpak.yml --force-clean flatpak build-export ./flatpak-repo ./flatpak - flatpak build-bundle ./flatpak-repo bundle/ai.moeru.airi-${{ matrix.arch }}.flatpak ai.moeru.airi - echo "FLATPAK_BUNDLE_NAME=ai.moeru.airi-${{ matrix.arch }}.flatpak" >> $GITHUB_ENV + export FLATPAK_OUTPUT_NAME=$(pnpm exec tsx scripts/artifacts-metadata.ts ${{ matrix.target }} --get-output-filename flatpak) + flatpak build-bundle ./flatpak-repo dist/${FLATPAK_OUTPUT_NAME} ai.moeru.airi # --------- # Nightly (schedule) builds only @@ -188,6 +188,7 @@ jobs: run: | echo "DEB_BUNDLE_NAME=$(pnpm exec tsx scripts/artifacts-metadata.ts ${{ matrix.target }} --get-filename deb)" >> $GITHUB_ENV echo "RPM_BUNDLE_NAME=$(pnpm exec tsx scripts/artifacts-metadata.ts ${{ matrix.target }} --get-filename rpm)" >> $GITHUB_ENV + echo "FLATPAK_BUNDLE_NAME=$(pnpm exec tsx scripts/artifacts-metadata.ts ${{ matrix.target }} --get-filename flatpak)" >> $GITHUB_ENV - name: Upload Artifacts (Nightly + Non-Linux) if: ${{ github.event_name == 'schedule' && (matrix.os != 'ubuntu-latest' && matrix.os != 'ubuntu-24.04-arm') }} @@ -251,6 +252,7 @@ jobs: run: | echo "DEB_BUNDLE_NAME=$(pnpm exec tsx scripts/artifacts-metadata.ts ${{ matrix.target }} --get-filename deb --release ${{ !inputs.build_only && !inputs.artifacts_only }} --tag ${{ inputs.tag }} --auto-tag ${{ !inputs.build_only }})" >> $GITHUB_ENV echo "RPM_BUNDLE_NAME=$(pnpm exec tsx scripts/artifacts-metadata.ts ${{ matrix.target }} --get-filename rpm --release ${{ !inputs.build_only && !inputs.artifacts_only }} --tag ${{ inputs.tag }} --auto-tag ${{ !inputs.build_only }})" >> $GITHUB_ENV + echo "FLATPAK_BUNDLE_NAME=$(pnpm exec tsx scripts/artifacts-metadata.ts ${{ matrix.target }} --get-filename flatpak --release ${{ !inputs.build_only && !inputs.artifacts_only }} --tag ${{ inputs.tag }} --auto-tag ${{ !inputs.build_only }})" >> $GITHUB_ENV - name: Upload Artifacts (Manual + Non-Release + Non-Linux) if: ${{ github.event_name == 'workflow_dispatch' && !inputs.build_only && inputs.artifacts_only && (matrix.os != 'ubuntu-latest' && matrix.os != 'ubuntu-24.04-arm') }} diff --git a/apps/stage-tamagotchi/scripts/artifacts-metadata.ts b/apps/stage-tamagotchi/scripts/artifacts-metadata.ts index 1cb04fd74..7bbfe7160 100644 --- a/apps/stage-tamagotchi/scripts/artifacts-metadata.ts +++ b/apps/stage-tamagotchi/scripts/artifacts-metadata.ts @@ -16,6 +16,11 @@ async function main() { 'Get the release artifact filename for a specific extension (e.g., deb, rpm, dmg, exe)', { default: '', type: [String] }, ) + .option( + '--get-output-filename ', + 'Get the build output filename for a specific extension (pre-rename)', + { default: '', type: [String] }, + ) .option( '--auto-tag', 'Automatically tag the release with the latest git ref', @@ -52,6 +57,7 @@ async function main() { getProductName: boolean getVersion: boolean getFilename: string[] + getOutputFilename: string[] } const target = args.args[0] @@ -69,6 +75,16 @@ async function main() { } console.info(match.releaseArtifactFilename) } + if (argOptions.getOutputFilename && argOptions.getOutputFilename[0]) { + const ext = String(argOptions.getOutputFilename[0]).trim() + const filenames = await getFilenames(target, argOptions) + const match = filenames.find(f => f.extension === ext) + if (!match) { + console.error(`No artifact found for extension: ${ext}`) + process.exit(1) + } + console.info(match.outputFilename) + } if (argOptions.getProductName) { const electronBuilderConfig = await getElectronBuilderConfig() console.info(electronBuilderConfig.productName) diff --git a/apps/stage-tamagotchi/scripts/utils.ts b/apps/stage-tamagotchi/scripts/utils.ts index 8cf379c24..4f197cc2c 100644 --- a/apps/stage-tamagotchi/scripts/utils.ts +++ b/apps/stage-tamagotchi/scripts/utils.ts @@ -84,7 +84,7 @@ interface FilenameOutputEntry { version: string } -function mapArchFor( +export function mapArchFor( target: string, ext: string, ): string { @@ -213,6 +213,30 @@ export async function getFilenames(target: string, options: { release: boolean, }, ) } + + // Flatpak artifact (built outside electron-builder, but we follow linux template) + artifacts.push( + { + target: 'x86_64-unknown-linux-gnu', + extension: 'flatpak', + outputFilename: applyTemplateOfArtifactName( + electronBuilder.linux.artifactName!, + productName, + beforeVersion, + mapArchFor(target, 'flatpak'), + 'flatpak', + ), + releaseArtifactFilename: applyTemplateOfArtifactName( + electronBuilder.linux.artifactName!, + productName, + version, + mapArchFor(target, 'flatpak'), + 'flatpak', + ), + productName, + version, + }, + ) } return artifacts @@ -276,6 +300,30 @@ export async function getFilenames(target: string, options: { release: boolean, }, ) } + + // Flatpak artifact (built outside electron-builder, but we follow linux template) + artifacts.push( + { + target: 'aarch64-unknown-linux-gnu', + extension: 'flatpak', + outputFilename: applyTemplateOfArtifactName( + electronBuilder.linux.artifactName!, + productName, + beforeVersion, + mapArchFor(target, 'flatpak'), + 'flatpak', + ), + releaseArtifactFilename: applyTemplateOfArtifactName( + electronBuilder.linux.artifactName!, + productName, + version, + mapArchFor(target, 'flatpak'), + 'flatpak', + ), + productName, + version, + }, + ) } return artifacts