chore(ci): improve scripts
This commit is contained in:
@@ -0,0 +1 @@
|
||||
AIRI_nightly-20250719-76e5463_macos_arm64.dmg
|
||||
@@ -14,7 +14,8 @@
|
||||
"preview": "vite preview",
|
||||
"tauri": "tauri",
|
||||
"build:unpack": "tauri build --no-bundle",
|
||||
"rename-artifacts": "tsx scripts/rename-artifacts.ts"
|
||||
"rename-artifacts": "tsx scripts/rename-artifacts.ts",
|
||||
"name-of-artifacts": "tsx scripts/name-of-artifacts.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"@formkit/auto-animate": "^0.8.2",
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
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: '', 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.log(filename)
|
||||
}
|
||||
}
|
||||
|
||||
main()
|
||||
.catch((error) => {
|
||||
console.error('Error during generating name:', error)
|
||||
process.exit(1)
|
||||
})
|
||||
@@ -4,122 +4,105 @@ import { mkdirSync, readdirSync, renameSync } from 'node:fs'
|
||||
import { join } from 'node:path'
|
||||
|
||||
import { cac } from 'cac'
|
||||
import { execa } from 'execa'
|
||||
|
||||
import packageJSON from '../package.json' assert { type: 'json' }
|
||||
import tauriConfigJSON from '../src-tauri/tauri.conf.json' assert { type: 'json' }
|
||||
|
||||
const cli = cac('rename-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] },
|
||||
)
|
||||
import { getFilename, getVersion } from './utils'
|
||||
|
||||
const args = cli.parse()
|
||||
async function main() {
|
||||
const cli = cac('rename-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] },
|
||||
)
|
||||
|
||||
let version = packageJSON.version
|
||||
const target = args.args[0]
|
||||
const productName = tauriConfigJSON.productName
|
||||
const dirname = import.meta.dirname
|
||||
const args = cli.parse()
|
||||
|
||||
const beforeVersion = version
|
||||
const beforeProductName = productName
|
||||
let version = packageJSON.version
|
||||
const target = args.args[0]
|
||||
const productName = tauriConfigJSON.productName
|
||||
const dirname = import.meta.dirname
|
||||
|
||||
const argOptions = args.options as {
|
||||
release: boolean
|
||||
autoTag: boolean
|
||||
tag: string[]
|
||||
}
|
||||
const beforeVersion = version
|
||||
const beforeProductName = productName
|
||||
|
||||
if (argOptions.release) {
|
||||
// If --release is specified, use the version from package.json
|
||||
version = packageJSON.version
|
||||
|
||||
if (argOptions.tag) {
|
||||
if (argOptions.tag[0] !== 'true') {
|
||||
// If --tag is specified, use the provided tag
|
||||
version = String(argOptions.tag[0]).replace(/^v/, '').trim()
|
||||
}
|
||||
else {
|
||||
version = ''
|
||||
}
|
||||
|
||||
if (!version) {
|
||||
if (argOptions.autoTag) {
|
||||
// If --auto-tag is specified, fetch the latest git ref
|
||||
const res = await execa('git', ['describe', '--tags', '--abbrev=0'])
|
||||
version = String(res.stdout).replace(/^v/, '').trim()
|
||||
}
|
||||
else {
|
||||
throw new Error('Tag cannot be empty when --release is specified')
|
||||
}
|
||||
}
|
||||
const argOptions = args.options as {
|
||||
release: boolean
|
||||
autoTag: boolean
|
||||
tag: string[]
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Otherwise, fetch from the latest git ref
|
||||
const res = await execa('git', ['log', '-1', '--pretty=format:"%H"'])
|
||||
const date = new Date().toISOString().split('T')[0].replace(/-/g, '')
|
||||
version = `nightly-${date}-${String(res.stdout.replace(/"/g, '')).trim().substring(0, 7)}`
|
||||
|
||||
version = await getVersion(argOptions)
|
||||
|
||||
console.log('target:', target)
|
||||
console.log('dirname', dirname)
|
||||
console.log('version from:', beforeVersion, 'to:', version)
|
||||
console.log('product name from:', beforeProductName, 'to:', productName)
|
||||
|
||||
if (!target) {
|
||||
throw new Error('<Target> is required')
|
||||
}
|
||||
|
||||
const srcPrefix = join(dirname, '..', '..', '..', 'target', target, 'release', 'bundle')
|
||||
const bundlePrefix = join(dirname, '..', '..', '..', 'bundle')
|
||||
|
||||
console.log('renaming directory from:', srcPrefix)
|
||||
console.log('renaming directory to:', bundlePrefix)
|
||||
console.log(readdirSync(srcPrefix))
|
||||
|
||||
mkdirSync(bundlePrefix, { recursive: true })
|
||||
|
||||
let renameFrom = ''
|
||||
let renameTo = ''
|
||||
const filename = await getFilename(target, argOptions)
|
||||
|
||||
switch (target) {
|
||||
case 'x86_64-pc-windows-msvc':
|
||||
renameFrom = join(srcPrefix, 'nsis', `${beforeProductName}_${beforeVersion}_x64-setup.exe`)
|
||||
renameTo = join(bundlePrefix, filename)
|
||||
break
|
||||
case 'x86_64-unknown-linux-gnu':
|
||||
renameFrom = join(srcPrefix, 'appimage', `${beforeProductName}_${beforeVersion}_amd64.AppImage`)
|
||||
renameTo = join(bundlePrefix, filename)
|
||||
break
|
||||
case 'aarch64-unknown-linux-gnu':
|
||||
renameFrom = join(srcPrefix, 'appimage', `${beforeProductName}_${beforeVersion}_aarch64.AppImage`)
|
||||
renameTo = join(bundlePrefix, filename)
|
||||
break
|
||||
case 'aarch64-apple-darwin':
|
||||
renameFrom = join(srcPrefix, 'dmg', `${beforeProductName}_${beforeVersion}_aarch64.dmg`)
|
||||
renameTo = join(bundlePrefix, filename)
|
||||
break
|
||||
case 'x86_64-apple-darwin':
|
||||
renameFrom = join(srcPrefix, 'dmg', `${beforeProductName}_${beforeVersion}_x64.dmg`)
|
||||
renameTo = join(bundlePrefix, filename)
|
||||
break
|
||||
default:
|
||||
console.error('Target is not supported')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
console.log('renaming, from:', renameFrom, 'to:', renameTo)
|
||||
renameSync(renameFrom, renameTo)
|
||||
}
|
||||
|
||||
console.log('version:', beforeVersion, version)
|
||||
console.log('target:', target)
|
||||
console.log('productName:', beforeProductName, productName)
|
||||
console.log('dirname:', dirname)
|
||||
|
||||
if (!target) {
|
||||
throw new Error('<Target> is required')
|
||||
}
|
||||
|
||||
const srcPrefix = join(dirname, '..', '..', '..', 'target', target, 'release', 'bundle')
|
||||
const bundlePrefix = join(dirname, '..', '..', '..', 'bundle')
|
||||
|
||||
console.log('srcPrefix:', srcPrefix)
|
||||
console.log('bundlePrefix:', bundlePrefix)
|
||||
console.log(readdirSync(srcPrefix))
|
||||
|
||||
mkdirSync(bundlePrefix, { recursive: true })
|
||||
|
||||
let renameFrom = ''
|
||||
let renameTo = ''
|
||||
|
||||
switch (target) {
|
||||
case 'x86_64-pc-windows-msvc':
|
||||
renameFrom = join(srcPrefix, 'nsis', `${beforeProductName}_${beforeVersion}_x64-setup.exe`)
|
||||
renameTo = join(bundlePrefix, `${productName}_${version}_windows_amd64-setup.exe`)
|
||||
break
|
||||
case 'x86_64-unknown-linux-gnu':
|
||||
renameFrom = join(srcPrefix, 'appimage', `${beforeProductName}_${beforeVersion}_amd64.AppImage`)
|
||||
renameTo = join(bundlePrefix, `${productName}_${version}_linux_amd64.AppImage`)
|
||||
break
|
||||
case 'aarch64-unknown-linux-gnu':
|
||||
renameFrom = join(srcPrefix, 'appimage', `${beforeProductName}_${beforeVersion}_aarch64.AppImage`)
|
||||
renameTo = join(bundlePrefix, `${productName}_${version}_linux_arm64.AppImage`)
|
||||
break
|
||||
case 'aarch64-apple-darwin':
|
||||
renameFrom = join(srcPrefix, 'dmg', `${beforeProductName}_${beforeVersion}_aarch64.dmg`)
|
||||
renameTo = join(bundlePrefix, `${productName}_${version}_macos_arm64.dmg`)
|
||||
break
|
||||
case 'x86_64-apple-darwin':
|
||||
renameFrom = join(srcPrefix, 'dmg', `${beforeProductName}_${beforeVersion}_x64.dmg`)
|
||||
renameTo = join(bundlePrefix, `${productName}_${version}_macos_amd64.dmg`)
|
||||
break
|
||||
default:
|
||||
console.error('Target is not supported')
|
||||
main()
|
||||
.then(() => {
|
||||
console.log('Renaming completed successfully.')
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('Error during renaming:', error)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
console.log('renaming, from:', renameFrom, 'to:', renameTo)
|
||||
renameSync(renameFrom, renameTo)
|
||||
})
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
import process from 'node:process'
|
||||
|
||||
import { execa } from 'execa'
|
||||
|
||||
import packageJSON from '../package.json' assert { type: 'json' }
|
||||
import tauriConfigJSON from '../src-tauri/tauri.conf.json' assert { type: 'json' }
|
||||
|
||||
export async function getVersion(options: { release: boolean, autoTag: boolean, tag: string[] }) {
|
||||
if (!options.release || !options.tag) {
|
||||
// Otherwise, fetch from the latest git ref
|
||||
const res = await execa('git', ['log', '-1', '--pretty=format:"%H"'])
|
||||
const date = new Date().toISOString().split('T')[0].replace(/-/g, '')
|
||||
return `nightly-${date}-${String(res.stdout.replace(/"/g, '')).trim().substring(0, 7)}`
|
||||
}
|
||||
|
||||
// If --release is specified, use the version from package.json
|
||||
let version = packageJSON.version
|
||||
|
||||
// If --tag is specified, use the provided tag
|
||||
if (options.tag[0] !== 'true') {
|
||||
version = String(options.tag[0]).replace(/^v/, '').trim()
|
||||
}
|
||||
// Otherwise, even for --tag option (true / enabled), ignore the input
|
||||
else {
|
||||
version = ''
|
||||
}
|
||||
|
||||
if (version) {
|
||||
return version
|
||||
}
|
||||
|
||||
// If no version is provided and --auto-tag is not specified, throw an error
|
||||
if (!options.autoTag) {
|
||||
throw new Error('Tag cannot be empty when --release is specified')
|
||||
}
|
||||
|
||||
// Now, only auto-tag & release && non-specific tag is the only possibility,
|
||||
// fetch the latest git ref
|
||||
const res = await execa('git', ['describe', '--tags', '--abbrev=0'])
|
||||
return String(res.stdout).replace(/^v/, '').trim()
|
||||
}
|
||||
|
||||
export async function getFilename(target: string, options: { release: boolean, autoTag: boolean, tag: string[] }) {
|
||||
const productName = tauriConfigJSON.productName
|
||||
const version = await getVersion(options)
|
||||
|
||||
if (!target) {
|
||||
throw new Error('<Target> is required')
|
||||
}
|
||||
|
||||
switch (target) {
|
||||
case 'x86_64-pc-windows-msvc':
|
||||
return `${productName}_${version}_windows_amd64-setup.exe`
|
||||
break
|
||||
case 'x86_64-unknown-linux-gnu':
|
||||
return `${productName}_${version}_linux_amd64.AppImage`
|
||||
break
|
||||
case 'aarch64-unknown-linux-gnu':
|
||||
return `${productName}_${version}_linux_arm64.AppImage`
|
||||
break
|
||||
case 'aarch64-apple-darwin':
|
||||
return `${productName}_${version}_macos_arm64.dmg`
|
||||
break
|
||||
case 'x86_64-apple-darwin':
|
||||
return `${productName}_${version}_macos_amd64.dmg`
|
||||
default:
|
||||
console.error('Target is not supported')
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user