feat: Support --target input in args (#301)

Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
This commit is contained in:
Fabian-Lars
2022-10-31 22:46:55 +01:00
committed by GitHub
parent 87ceccdc2e
commit a99d0bae58
5 changed files with 99 additions and 68 deletions

View File

@@ -0,0 +1,6 @@
---
"@tauri-apps/action-core": patch
"action": patch
---
Correctly handle `--target` option in `args` input.

File diff suppressed because one or more lines are too long

View File

@@ -9,20 +9,11 @@ interface Release {
htmlUrl: string
}
interface GitHubReleaseAsset {
id: number
name: string
state: string
size: number
browser_download_url: string
}
interface GitHubRelease {
id: number
upload_url: string
html_url: string
tag_name: string
assets: GitHubReleaseAsset[]
}
function allReleases(
@@ -34,30 +25,6 @@ function allReleases(
)
}
function getAssetPlatform(platform: string, fileName: string): string | null {
// macOS
if (
(fileName.includes(".app.tar.gz") || fileName.includes(".dmg")) &&
platform === "darwin"
) {
return 'darwin'
}
// Windows
if (fileName.includes('.msi') && platform === "win32") {
return 'win64'
}
// Linux
if ((fileName.includes('AppImage') || fileName.includes("deb")) && platform === "linux") {
return 'linux'
}
return null
}
export default async function createRelease(
tagName: string,
releaseName: string,
@@ -94,26 +61,13 @@ export default async function createRelease(
console.log(`Looking for a draft release with tag ${tagName}...`)
for await (const response of allReleases(github)) {
let releaseWithTag = response.data.find(
release => release.tag_name === tagName
(release) => release.tag_name === tagName
)
if (releaseWithTag) {
release = releaseWithTag
console.log(
`Found draft release with tag ${tagName} on the release list.`
)
// Remove all assets from the existing release
for (const asset of release.assets) {
if (getAssetPlatform(process.platform, asset.name)) {
console.log(
`Deleting asset ${asset.name} from the existing draft release`
)
await github.rest.repos.deleteReleaseAsset({
asset_id: asset.id,
owner,
repo,
})
}
}
break
}
}

View File

@@ -10,8 +10,29 @@ export default async function uploadAssets(
throw new Error('GITHUB_TOKEN is required')
}
const extensions = [
'.app.tar.gz.sig',
'.app.tar.gz',
'.dmg',
'.AppImage.tar.gz.sig',
'.AppImage.tar.gz',
'.AppImage',
'.deb',
'.msi.zip.sig',
'.msi.zip',
'.msi'
]
const github = getOctokit(process.env.GITHUB_TOKEN)
const existingAssets = (
await github.rest.repos.listReleaseAssets({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: releaseId
})
).data
// Determine content-length for header to upload asset
const contentLength = (filePath: string) => fs.statSync(filePath).size
@@ -21,12 +42,36 @@ export default async function uploadAssets(
'content-length': contentLength(assetPath)
}
const ext = path.extname(assetPath)
const filename = path.basename(assetPath).replace(ext, '')
const assetName = path.dirname(assetPath).includes(`target${path.sep}debug`)
? `${filename}-debug${ext}`
: `${filename}${ext}`
const basename = path.basename(assetPath)
const exts = extensions.filter((s) => basename.includes(s))
const ext = exts[0] || path.extname(assetPath)
const filename = basename.replace(ext, '')
let arch = ''
if (ext === '.app.tar.gz.sig' || ext === '.app.tar.gz') {
arch = assetPath.includes('universal-apple-darwin')
? '_universal'
: assetPath.includes('aarch64-apple-darwin')
? '_aarch64'
: '_x64'
}
const assetName = assetPath.includes(`${path.sep}debug${path.sep}`)
? `${filename}-debug${arch}${ext}`
: `${filename}${arch}${ext}`
const existingAsset = existingAssets.find((a) => a.name === assetName)
if (existingAsset) {
console.log(`Deleting existing ${assetName}...`)
await github.rest.repos.deleteReleaseAsset({
owner: context.repo.owner,
repo: context.repo.repo,
asset_id: existingAsset.id
})
}
console.log(`Uploading ${assetName}...`)
await github.rest.repos.uploadReleaseAsset({
headers,
name: assetName,

View File

@@ -395,22 +395,37 @@ export async function buildProject(
const cratePath = getWorkspaceDir(app.tauriPath) ?? app.tauriPath
const found = [...tauriArgs].findIndex(
(e) => e === '-t' || e === '--target'
)
const targetPath = found >= 0 ? [...tauriArgs][found + 1] : ''
const artifactsPath = join(
getTargetDir(cratePath),
targetPath,
debug ? 'debug' : 'release'
)
let arch =
targetPath.search('-') >= 0
? targetPath.split('-')[0]
: process.arch
if (platform() === 'darwin') {
if (arch === "x86_64") arch = "x64"
return [
join(
artifactsPath,
`bundle/dmg/${fileAppName}_${app.version}_${process.arch}.dmg`
`bundle/dmg/${fileAppName}_${app.version}_${arch}.dmg`
),
join(artifactsPath, `bundle/macos/${fileAppName}.app`),
join(artifactsPath, `bundle/macos/${fileAppName}.app.tar.gz`),
join(artifactsPath, `bundle/macos/${fileAppName}.app.tar.gz.sig`),
join(artifactsPath, `bundle/macos/${fileAppName}.app.tar.gz.sig`)
]
} else if (platform() === 'win32') {
arch = arch.startsWith('i') ? 'x86' : 'x64'
// If multiple Wix languages are specified, multiple installers (.msi) will be made
// The .zip and .sig are only generated for the first specified language
let langs
@@ -426,47 +441,58 @@ export async function buildProject(
artifacts.push(
join(
artifactsPath,
`bundle/msi/${fileAppName}_${app.version}_${process.arch}_${lang}.msi`
`bundle/msi/${fileAppName}_${app.version}_${arch}_${lang}.msi`
)
)
artifacts.push(
join(
artifactsPath,
`bundle/msi/${fileAppName}_${app.version}_${process.arch}_${lang}.msi.zip`
`bundle/msi/${fileAppName}_${app.version}_${arch}_${lang}.msi.zip`
)
)
artifacts.push(
join(
artifactsPath,
`bundle/msi/${fileAppName}_${app.version}_${process.arch}_${lang}.msi.zip.sig`
`bundle/msi/${fileAppName}_${app.version}_${arch}_${lang}.msi.zip.sig`
)
)
})
return artifacts
} else {
const arch =
process.arch === 'x64'
const debianArch =
arch === 'x64' || arch === 'x86_64'
? 'amd64'
: process.arch === 'x32'
: arch === 'x32' || arch === 'i686'
? 'i386'
: process.arch
: arch === 'arm'
? 'armhf'
: arch === 'aarch64'
? 'arm64'
: arch
const appImageArch =
arch === 'x64' || arch === 'x86_64'
? 'amd64'
: arch === 'x32' || arch === 'i686'
? 'i386'
: arch
return [
join(
artifactsPath,
`bundle/deb/${fileAppName}_${app.version}_${arch}.deb`
`bundle/deb/${fileAppName}_${app.version}_${debianArch}.deb`
),
join(
artifactsPath,
`bundle/appimage/${fileAppName}_${app.version}_${arch}.AppImage`
`bundle/appimage/${fileAppName}_${app.version}_${appImageArch}.AppImage`
),
join(
artifactsPath,
`bundle/appimage/${fileAppName}_${app.version}_${arch}.AppImage.tar.gz`
`bundle/appimage/${fileAppName}_${app.version}_${appImageArch}.AppImage.tar.gz`
),
join(
artifactsPath,
`bundle/appimage/${fileAppName}_${app.version}_${arch}.AppImage.tar.gz.sig`
),
`bundle/appimage/${fileAppName}_${app.version}_${appImageArch}.AppImage.tar.gz.sig`
)
]
}
})