feat(ci): support to run release-tamagotchi.yml workflow for deb and rpm files

This commit is contained in:
Neko Ayaka
2025-10-20 13:00:30 +08:00
parent 32934b9bbe
commit ad786013b0
7 changed files with 280 additions and 168 deletions
+1 -1
View File
@@ -23,7 +23,7 @@
"build:mac": "pnpm run build && electron-builder --mac",
"build:linux": "pnpm run build && electron-builder --linux",
"rename-artifacts": "mkdir -p bundle && tsx scripts/rename-artifacts.ts",
"name-of-artifacts": "tsx scripts/name-of-artifacts.ts"
"artifacts-metadata": "tsx scripts/artifacts-metadata.ts"
},
"dependencies": {
"@date-fns/utc": "^2.1.1",
@@ -0,0 +1,70 @@
import process from 'node:process'
import { cac } from 'cac'
import { getElectronBuilderConfig, getFilenames, getVersion } from './utils'
async function main() {
const cli = cac('name-of-artifact')
.option(
'--release',
'Rename with version from package.json',
{ default: false },
)
.option(
'--auto-tag',
'Automatically tag the release with the latest git ref',
{ default: false },
)
.option(
'--tag <tag>',
'Tag to use for the release',
{ default: '', type: [String] },
)
.option(
'--get-bundle-name',
'Get the bundle name',
{ default: false },
)
.option(
'--get-product-name',
'Get the product name',
{ default: false },
)
.option(
'--get-version',
'Get the version',
{ default: false },
)
const args = cli.parse()
const argOptions = args.options as {
release: boolean
autoTag: boolean
tag: string[]
getBundleName: boolean
getProductName: boolean
getVersion: boolean
}
const target = args.args[0]
if (argOptions.getBundleName) {
const filenames = await getFilenames(target, argOptions)
console.info(filenames[0].releaseArtifactFilename)
}
if (argOptions.getProductName) {
const electronBuilderConfig = await getElectronBuilderConfig()
console.info(electronBuilderConfig.productName)
}
if (argOptions.getVersion) {
const version = await getVersion({ release: argOptions.release, autoTag: argOptions.autoTag, tag: argOptions.tag })
console.info(version)
}
}
main()
.catch((error) => {
console.error('Error during generating name:', error)
process.exit(1)
})
@@ -1,60 +0,0 @@
import process from 'node:process'
import { existsSync, mkdirSync, writeFileSync } from 'node:fs'
import { dirname } from 'node:path'
import { cac } from 'cac'
import { getFilename } from './utils'
async function main() {
const cli = cac('name-of-artifact')
.option(
'--release',
'Rename with version from package.json',
{ default: false },
)
.option(
'--auto-tag',
'Automatically tag the release with the latest git ref',
{ default: false },
)
.option(
'--tag <tag>',
'Tag to use for the release',
{ default: '', type: [String] },
)
.option(
'--out <path>',
'Path to output the filename',
{ default: 'bundle_name', type: [String] },
)
const args = cli.parse()
const argOptions = args.options as {
release: boolean
autoTag: boolean
tag: string[]
out: string[]
}
const target = args.args[0]
const filename = await getFilename(target, argOptions)
if (argOptions.out[0]) {
if (!existsSync(dirname(argOptions.out[0]))) {
mkdirSync(dirname(argOptions.out[0]), { recursive: true })
}
writeFileSync(argOptions.out[0], filename, { encoding: 'utf-8' })
}
else {
console.info(filename)
}
}
main()
.catch((error) => {
console.error('Error during generating name:', error)
process.exit(1)
})
@@ -7,7 +7,7 @@ import { cac } from 'cac'
import packageJSON from '../package.json' assert { type: 'json' }
import { getElectronBuilderConfig, getFilename, getVersion } from './utils'
import { getElectronBuilderConfig, getFilenames, getVersion } from './utils'
async function main() {
const cli = cac('rename-artifact')
@@ -66,39 +66,15 @@ async function main() {
mkdirSync(bundlePrefix, { recursive: true })
let renameFrom = ''
let renameTo = ''
const filename = await getFilename(target, argOptions)
console.info(filename, 'is the target filename')
const filenames = await getFilenames(target, argOptions)
console.info(filenames, 'is the target filename')
switch (target) {
case 'x86_64-pc-windows-msvc':
renameFrom = join(srcPrefix, `${beforeProductName}-${beforeVersion}-windows-x64-setup.exe`)
renameTo = join(bundlePrefix, filename)
break
case 'x86_64-unknown-linux-gnu':
renameFrom = join(srcPrefix, `${beforeProductName}-${beforeVersion}-linux-x86_64.AppImage`)
renameTo = join(bundlePrefix, filename)
break
case 'aarch64-unknown-linux-gnu':
renameFrom = join(srcPrefix, `${beforeProductName}-${beforeVersion}-linux-arm64.AppImage`)
renameTo = join(bundlePrefix, filename)
break
case 'aarch64-apple-darwin':
renameFrom = join(srcPrefix, `${beforeProductName}-${beforeVersion}-darwin-arm64.dmg`)
renameTo = join(bundlePrefix, filename)
break
case 'x86_64-apple-darwin':
renameFrom = join(srcPrefix, `${beforeProductName}-${beforeVersion}-darwin-x64.dmg`)
renameTo = join(bundlePrefix, filename)
break
default:
console.error('Target is not supported')
process.exit(1)
for (const filename of filenames) {
const renameFrom = join(srcPrefix, filename.outputFilename)
const renameTo = join(bundlePrefix, filename.releaseArtifactFilename)
console.info('renaming, from:', renameFrom, 'to:', renameTo)
renameSync(renameFrom, renameTo)
}
console.info('renaming, from:', renameFrom, 'to:', renameTo)
renameSync(renameFrom, renameTo)
}
main()
+137 -50
View File
@@ -57,7 +57,34 @@ export async function getElectronBuilderConfig() {
return yaml.parse(await readFile(resolve(import.meta.dirname, '..', 'electron-builder.yml'), 'utf-8')) as Configuration
}
export async function getFilename(target: string, options: { release: boolean, autoTag: boolean, tag: string[] }) {
export function applyTemplateOfArtifactName(
template: string,
productName: string,
version: string,
arch: string,
ext: string,
): string {
return template
// eslint-disable-next-line no-template-curly-in-string
.replace('${productName}', productName)
// eslint-disable-next-line no-template-curly-in-string
.replace('${version}', version)
// eslint-disable-next-line no-template-curly-in-string
.replace('${arch}', arch)
// eslint-disable-next-line no-template-curly-in-string
.replace('${ext}', ext)
}
interface FilenameOutputEntry {
target: string
extension: string
outputFilename: string
releaseArtifactFilename: string
productName: string
version: string
}
export async function getFilenames(target: string, options: { release: boolean, autoTag: boolean, tag: string[] }): Promise<FilenameOutputEntry[]> {
const electronBuilder = await getElectronBuilderConfig()
const version = await getVersion(options)
@@ -65,62 +92,122 @@ export async function getFilename(target: string, options: { release: boolean, a
throw new Error('<Target> is required')
}
const beforeVersion = version
const productName = electronBuilder.productName!
switch (target) {
case 'x86_64-pc-windows-msvc':
return electronBuilder.nsis?.artifactName
// eslint-disable-next-line no-template-curly-in-string
?.replace('${productName}', electronBuilder.productName!)
// eslint-disable-next-line no-template-curly-in-string
.replace('${version}', version)
// eslint-disable-next-line no-template-curly-in-string
.replace('${arch}', 'x64')
// eslint-disable-next-line no-template-curly-in-string
.replace('${ext}', 'exe') ?? `${electronBuilder.productName}-${version}-windows-x64-setup.exe`
break
return [
{
target: 'x86_64-pc-windows-msvc',
extension: 'exe',
outputFilename: applyTemplateOfArtifactName(electronBuilder.nsis?.artifactName!, productName, beforeVersion, 'x64', 'exe'),
releaseArtifactFilename: applyTemplateOfArtifactName(electronBuilder.nsis?.artifactName!, productName, version, 'x64', 'exe'),
productName,
version,
},
]
case 'x86_64-unknown-linux-gnu':
return electronBuilder.linux?.artifactName
// eslint-disable-next-line no-template-curly-in-string
?.replace('${productName}', electronBuilder.productName!)
// eslint-disable-next-line no-template-curly-in-string
.replace('${version}', version)
// eslint-disable-next-line no-template-curly-in-string
.replace('${arch}', 'x64')
// eslint-disable-next-line no-template-curly-in-string
.replace('${ext}', 'AppImage') ?? `${electronBuilder.productName}-${version}-linux-x64.AppImage`
break
{
const artifacts: FilenameOutputEntry[] = []
if (electronBuilder.linux?.artifactName) {
if (
(Array.isArray(electronBuilder.linux.target) && electronBuilder.linux.target.includes('deb'))
|| electronBuilder.linux.target === 'deb'
) {
artifacts.push(
{
target: 'x86_64-unknown-linux-gnu',
extension: 'deb',
outputFilename: applyTemplateOfArtifactName(electronBuilder.linux.artifactName!, productName, beforeVersion, 'x64', 'deb'),
releaseArtifactFilename: applyTemplateOfArtifactName(electronBuilder.linux.artifactName!, productName, version, 'x64', 'deb'),
productName,
version,
},
)
}
if (
(Array.isArray(electronBuilder.linux.target) && electronBuilder.linux.target.includes('rpm'))
|| electronBuilder.linux.target === 'rpm'
) {
artifacts.push(
{
target: 'x86_64-unknown-linux-gnu',
extension: 'rpm',
outputFilename: applyTemplateOfArtifactName(electronBuilder.linux.artifactName!, productName, beforeVersion, 'x64', 'rpm'),
releaseArtifactFilename: applyTemplateOfArtifactName(electronBuilder.linux.artifactName!, productName, version, 'x64', 'rpm'),
productName,
version,
},
)
}
}
return artifacts
}
case 'aarch64-unknown-linux-gnu':
return electronBuilder.linux?.artifactName
// eslint-disable-next-line no-template-curly-in-string
?.replace('${productName}', electronBuilder.productName!)
// eslint-disable-next-line no-template-curly-in-string
.replace('${version}', version)
// eslint-disable-next-line no-template-curly-in-string
.replace('${arch}', 'arm64')
// eslint-disable-next-line no-template-curly-in-string
.replace('${ext}', 'AppImage') ?? `${electronBuilder.productName}-${version}-linux-arm64.AppImage`
break
{
const artifacts: FilenameOutputEntry[] = []
if (electronBuilder.linux?.artifactName) {
if (
(Array.isArray(electronBuilder.linux.target) && electronBuilder.linux.target.includes('deb'))
|| electronBuilder.linux.target === 'deb'
) {
artifacts.push(
{
target: 'aarch64-unknown-linux-gnu',
extension: 'deb',
outputFilename: applyTemplateOfArtifactName(electronBuilder.linux.artifactName!, productName, beforeVersion, 'arm64', 'deb'),
releaseArtifactFilename: applyTemplateOfArtifactName(electronBuilder.linux.artifactName!, productName, version, 'arm64', 'deb'),
productName,
version,
},
)
}
if (
(Array.isArray(electronBuilder.linux.target) && electronBuilder.linux.target.includes('rpm'))
|| electronBuilder.linux.target === 'rpm'
) {
artifacts.push(
{
target: 'aarch64-unknown-linux-gnu',
extension: 'rpm',
outputFilename: applyTemplateOfArtifactName(electronBuilder.linux.artifactName!, productName, beforeVersion, 'arm64', 'rpm'),
releaseArtifactFilename: applyTemplateOfArtifactName(electronBuilder.linux.artifactName!, productName, version, 'arm64', 'rpm'),
productName,
version,
},
)
}
}
return artifacts
}
case 'aarch64-apple-darwin':
return electronBuilder.dmg?.artifactName
// eslint-disable-next-line no-template-curly-in-string
?.replace('${productName}', electronBuilder.productName!)
// eslint-disable-next-line no-template-curly-in-string
.replace('${version}', version)
// eslint-disable-next-line no-template-curly-in-string
.replace('${arch}', 'arm64')
// eslint-disable-next-line no-template-curly-in-string
.replace('${ext}', 'dmg') ?? `${electronBuilder.productName}-${version}-darwin-arm64.dmg`
break
return [
{
target: 'aarch64-apple-darwin',
extension: 'dmg',
outputFilename: applyTemplateOfArtifactName(electronBuilder.dmg?.artifactName!, productName, beforeVersion, 'arm64', 'dmg'),
releaseArtifactFilename: applyTemplateOfArtifactName(electronBuilder.dmg?.artifactName!, productName, version, 'arm64', 'dmg'),
productName,
version,
},
]
case 'x86_64-apple-darwin':
return electronBuilder.dmg?.artifactName
// eslint-disable-next-line no-template-curly-in-string
?.replace('${productName}', electronBuilder.productName!)
// eslint-disable-next-line no-template-curly-in-string
.replace('${version}', version)
// eslint-disable-next-line no-template-curly-in-string
.replace('${arch}', 'x64')
// eslint-disable-next-line no-template-curly-in-string
.replace('${ext}', 'dmg') ?? `${electronBuilder.productName}-${version}-darwin-x64.dmg`
return [
{
target: 'x86_64-apple-darwin',
extension: 'dmg',
outputFilename: applyTemplateOfArtifactName(electronBuilder.dmg?.artifactName!, productName, beforeVersion, 'x64', 'dmg'),
releaseArtifactFilename: applyTemplateOfArtifactName(electronBuilder.dmg?.artifactName!, productName, version, 'x64', 'dmg'),
productName,
version,
},
]
default:
console.error('Target is not supported')
process.exit(1)