mirror of
https://github.com/tauri-apps/tauri-action.git
synced 2026-01-31 00:35:20 +01:00
feat: upload assets to the release associated with given tagName (#895)
Co-authored-by: FabianLars <fabianlars@fabianlars.de>
This commit is contained in:
5
.changes/feat-upload-with-tag-name.md
Normal file
5
.changes/feat-upload-with-tag-name.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
action: patch
|
||||
---
|
||||
|
||||
Upload assets to the release associated with given `tagName`
|
||||
12
README.md
12
README.md
@@ -116,13 +116,13 @@ These inputs allow you to modify the GitHub release.
|
||||
|
||||
| Name | Required | Description | Type | Default |
|
||||
| ------------------ | :------: | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------ | ------------------------- |
|
||||
| `releaseId` | false | The id of the release to upload artifacts as release assets | number | |
|
||||
| `tagName` | false | The tag name of the release to create or the tag of the release belonging to `releaseId` | string | |
|
||||
| `releaseName` | false | The name of the release to create | string | |
|
||||
| `releaseId` | false | The id of the release to upload artifacts as release assets. If set, `tagName` and `releaseName` will not be considered to find a release. | number | |
|
||||
| `tagName` | false | The tag name of the release to upload/create or the tag of the release belonging to `releaseId` | string | |
|
||||
| `releaseName` | false | The name of the release to create. Required if there's no existing release for `tagName` | string | |
|
||||
| `releaseBody` | false | The body of the release to create | string | |
|
||||
| `releaseDraft` | false | Whether the release to create is a draft or not | bool | false |
|
||||
| `releaseDraft` | false | Whether the release to find or create is a draft or not | bool | false |
|
||||
| `prerelease` | false | Whether the release to create is a prerelease or not | bool | false |
|
||||
| `releaseCommitish` | false | Any branch or commit SHA the Git tag is created from, unused if the Git tag already exists | string | SHA of current commit |
|
||||
| `releaseCommitish` | false | Any branch or commit SHA the Git tag is created from, unused if the Git tag already exists. | string | SHA of current commit |
|
||||
| `owner` | false | The account owner of the repository the release will be uploaded to. Requires `GITHUB_TOKEN` in env and a `releaseCommitish` target if it doesn't match the current repo. | string | owner of the current repo |
|
||||
| `repo` | false | The name of the repository the release will be uploaded to. Requires `GITHUB_TOKEN` in env and a `releaseCommitish` target if it doesn't match the current repo. | string | name of the current repo |
|
||||
|
||||
@@ -149,7 +149,9 @@ These inputs allow you to modify the GitHub release.
|
||||
- When your Tauri app is not in the root of the repo, use the `projectPath` input.
|
||||
- Usually it will work without it, but the action will install and use a global `@tauri-apps/cli` installation instead of your project's CLI which can cause issues if you also configured `tauriScript` or if you have multiple `tauri.conf.json` files in your repo.
|
||||
- Additionally, relative paths provided via the `--config` flag will be resolved relative to the `projectPath` to match Tauri's behavior.
|
||||
- If `releaseId` is set, the action will use this release to upload assets to. If `tagName` is set the action will try to find an existing release for that tag. If there's none, the action requires `releaseName` to create a new release for the specified `tagName`.
|
||||
- If you create the release yourself and provide a `releaseId` but do not set `tagName`, the download url for updater bundles in `latest.json` will point to `releases/latest/download/<bundle>` which can cause issues if your repo contains releases that do not include updater bundles.
|
||||
- If you provide a `tagName` to an existing release, `releaseDraft` must be set to `true` if the existing release is a draft.
|
||||
- If you only want to build the app without having the action upload any assets, for example if you want to only use [`actions/upload-artifact`](https://github.com/actions/upload-artifact), simply omit `tagName`, `releaseName` and `releaseId`.
|
||||
|
||||
## Partners
|
||||
|
||||
@@ -7,7 +7,7 @@ inputs:
|
||||
releaseId:
|
||||
description: 'The id of the release to upload artifacts as release assets'
|
||||
tagName:
|
||||
description: 'The tag name of the release to create'
|
||||
description: 'The tag name of the release to create or upload to'
|
||||
releaseName:
|
||||
description: 'The name of the release to create'
|
||||
releaseBody:
|
||||
|
||||
2
dist/index.js
vendored
2
dist/index.js
vendored
File diff suppressed because one or more lines are too long
10
pnpm-lock.yaml
generated
10
pnpm-lock.yaml
generated
@@ -1297,15 +1297,16 @@ snapshots:
|
||||
picocolors: 1.1.1
|
||||
sisteransi: 1.0.5
|
||||
|
||||
'@covector/apply@0.10.0':
|
||||
'@covector/apply@0.10.0(mocha@10.4.0)':
|
||||
dependencies:
|
||||
'@covector/files': 0.8.0
|
||||
effection: 2.0.8(mocha@10.4.0)
|
||||
semver: 7.6.3
|
||||
transitivePeerDependencies:
|
||||
- encoding
|
||||
- mocha
|
||||
|
||||
'@covector/assemble@0.12.0(mocha@10.4.0)':
|
||||
'@covector/assemble@0.12.0':
|
||||
dependencies:
|
||||
'@covector/command': 0.8.0
|
||||
'@covector/files': 0.8.0
|
||||
@@ -1318,7 +1319,6 @@ snapshots:
|
||||
unified: 9.2.2
|
||||
transitivePeerDependencies:
|
||||
- encoding
|
||||
- mocha
|
||||
- supports-color
|
||||
|
||||
'@covector/changelog@0.12.0':
|
||||
@@ -1747,8 +1747,8 @@ snapshots:
|
||||
covector@0.12.3(mocha@10.4.0):
|
||||
dependencies:
|
||||
'@clack/prompts': 0.7.0
|
||||
'@covector/apply': 0.10.0
|
||||
'@covector/assemble': 0.12.0(mocha@10.4.0)
|
||||
'@covector/apply': 0.10.0(mocha@10.4.0)
|
||||
'@covector/assemble': 0.12.0
|
||||
'@covector/changelog': 0.12.0
|
||||
'@covector/command': 0.8.0
|
||||
'@covector/files': 0.8.0
|
||||
|
||||
@@ -28,11 +28,12 @@ function allReleases(
|
||||
);
|
||||
}
|
||||
|
||||
export async function createRelease(
|
||||
/// Try to get release by tag. If there's none, releaseName is required to create one.
|
||||
export async function getOrCreateRelease(
|
||||
owner: string,
|
||||
repo: string,
|
||||
tagName: string,
|
||||
releaseName: string,
|
||||
releaseName?: string,
|
||||
body?: string,
|
||||
commitish?: string,
|
||||
draft = true,
|
||||
@@ -91,18 +92,23 @@ export async function createRelease(
|
||||
// @ts-expect-error Catching errors in typescript is a headache
|
||||
if (error.status === 404 || error.message === 'release not found') {
|
||||
console.log(`Couldn't find release with tag ${tagName}. Creating one.`);
|
||||
const createdRelease = await github.rest.repos.createRelease({
|
||||
owner,
|
||||
repo,
|
||||
tag_name: tagName,
|
||||
name: releaseName,
|
||||
body: bodyFileContent || body,
|
||||
draft,
|
||||
prerelease,
|
||||
target_commitish: commitish || context.sha,
|
||||
});
|
||||
|
||||
release = createdRelease.data;
|
||||
if (!releaseName) {
|
||||
console.error('"releaseName" not set but required to create release.');
|
||||
} else {
|
||||
const createdRelease = await github.rest.repos.createRelease({
|
||||
owner,
|
||||
repo,
|
||||
tag_name: tagName,
|
||||
name: releaseName,
|
||||
body: bodyFileContent || body,
|
||||
draft,
|
||||
prerelease,
|
||||
target_commitish: commitish || context.sha,
|
||||
});
|
||||
|
||||
release = createdRelease.data;
|
||||
}
|
||||
} else {
|
||||
console.log(
|
||||
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
||||
|
||||
21
src/index.ts
21
src/index.ts
@@ -5,7 +5,7 @@ import * as core from '@actions/core';
|
||||
import { context } from '@actions/github';
|
||||
import stringArgv from 'string-argv';
|
||||
|
||||
import { createRelease } from './create-release';
|
||||
import { getOrCreateRelease } from './create-release';
|
||||
import { uploadAssets as uploadReleaseAssets } from './upload-release-assets';
|
||||
import { uploadVersionJSON } from './upload-version-json';
|
||||
import { buildProject } from './build';
|
||||
@@ -49,16 +49,6 @@ async function run(): Promise<void> {
|
||||
const updaterJsonPreferNsis =
|
||||
core.getInput('updaterJsonPreferNsis')?.toLowerCase() === 'true';
|
||||
|
||||
// If releaseId is set we'll use this to upload the assets to.
|
||||
// If tagName is set we also require releaseName to create a new release.
|
||||
// If neither releaseId nor tagName are set we won't try to upload anything at the end.
|
||||
if (!releaseId) {
|
||||
if (Boolean(tagName) && !releaseName)
|
||||
throw new Error(
|
||||
'`releaseName` is required if `tagName` is set when creating a release.',
|
||||
);
|
||||
}
|
||||
|
||||
const buildOptions: BuildOptions = {
|
||||
tauriScript,
|
||||
args,
|
||||
@@ -111,7 +101,7 @@ async function run(): Promise<void> {
|
||||
const artifacts = releaseArtifacts.concat(debugArtifacts);
|
||||
|
||||
if (artifacts.length === 0) {
|
||||
if (releaseId || tagName || releaseName) {
|
||||
if (releaseId || tagName) {
|
||||
throw new Error('No artifacts were found.');
|
||||
} else {
|
||||
console.log(
|
||||
@@ -161,6 +151,9 @@ async function run(): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
// If releaseId is set we'll use this to upload the assets to.
|
||||
// If tagName is set we will try to upload assets to the release associated with the given tagName.
|
||||
// If there's no release for that tag, we require releaseName to create a new one.
|
||||
if (tagName && !releaseId) {
|
||||
const templates = [
|
||||
{
|
||||
@@ -176,11 +169,11 @@ async function run(): Promise<void> {
|
||||
body = body.replace(regex, template.value);
|
||||
});
|
||||
|
||||
const releaseData = await createRelease(
|
||||
const releaseData = await getOrCreateRelease(
|
||||
owner,
|
||||
repo,
|
||||
tagName,
|
||||
releaseName,
|
||||
releaseName || undefined,
|
||||
body,
|
||||
commitish || undefined,
|
||||
draft,
|
||||
|
||||
@@ -58,7 +58,7 @@ export async function uploadAssets(
|
||||
|
||||
console.log(`Uploading ${assetName}...`);
|
||||
|
||||
await github.rest.repos.uploadReleaseAsset({
|
||||
return await github.rest.repos.uploadReleaseAsset({
|
||||
headers,
|
||||
name: assetName,
|
||||
// https://github.com/tauri-apps/tauri-action/pull/45
|
||||
|
||||
Reference in New Issue
Block a user