diff --git a/.changes/gitea.md b/.changes/gitea.md new file mode 100644 index 0000000..a0c48c7 --- /dev/null +++ b/.changes/gitea.md @@ -0,0 +1,5 @@ +--- +action: minor +--- + +Added experimental support for Gitea hosted instances. diff --git a/.changes/github-base-url.md b/.changes/github-base-url.md new file mode 100644 index 0000000..4acfe0e --- /dev/null +++ b/.changes/github-base-url.md @@ -0,0 +1,5 @@ +--- +action: patch +--- + +Added a config to set the GitHub API URL which should help users with self-hosted instances and those using GitHub Enterprise. diff --git a/README.md b/README.md index d9a7b8f..8cdc411 100644 --- a/README.md +++ b/README.md @@ -114,19 +114,21 @@ These inputs allow you to change how your Tauri project will be build. 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. 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 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 | -| `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 | -| `assetNamePattern` | false | The naming pattern to use for the uploaded assets. If not set, the names given by Tauri's CLI are kept. | string | none | -| `uploadPlainBinary` | false | Whether to upload the unbundled executable binary or not. Requires Tauri v2+. To prevent issues with Tauri's [`bundle_type`](https://docs.rs/tauri-utils/latest/tauri_utils/platform/fn.bundle_type.html) value this should only be used with the `--no-bundle` flag. | bool | false | +| Name | Required | Description | Type | Default | +| ------------------- | :------: | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------ | ------------------------------------------- | +| `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 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 | +| `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 | +| `githubBaseUrl` | false | The base URL of the GitHub API to use. This is useful if you want to use a self-hosted GitHub instance or a GitHub Enterprise server. | string | `$GITHUB_API_URL` or https://api.github.com | +| `isGitea` | false | Whether to run in Gitea compatibility mode. Set this if `githubBaseUrl` targets a Gitea instance, since some API endpoints differ from GitHub. | bool | false | +| `assetNamePattern` | false | The naming pattern to use for the uploaded assets. If not set, the names given by Tauri's CLI are kept. | string | none | +| `uploadPlainBinary` | false | Whether to upload the unbundled executable binary or not. Requires Tauri v2+. To prevent issues with Tauri's [`bundle_type`](https://docs.rs/tauri-utils/latest/tauri_utils/platform/fn.bundle_type.html) value this should only be used with the `--no-bundle` flag. | bool | false | ## Outputs @@ -160,6 +162,7 @@ These inputs allow you to modify the GitHub release. - `[mode]` will be replaced with `debug` or `release`, depending on `includeDebug` and `includeRelease`. - `[setup]` will be replaced with `-setup` which can be used to differenciate between the NSIS installer and the binary from `uploadPlainBinary`. For all other bundle types it will be an empty string. - `[_setup]` behaves like `[setup]` but with `_setup` instead of `-setup`. +- Gitea support is experimental. It was implemented and tested solely by the community. ## Partners diff --git a/action.yml b/action.yml index 62646d0..3d4bcf7 100644 --- a/action.yml +++ b/action.yml @@ -58,6 +58,11 @@ inputs: description: 'The account owner of the repository' repo: description: 'The name of the repository' + githubBaseUrl: + description: 'The base URL of the GitHub API to use. This is useful if you want to use a self-hosted GitHub instance or a GitHub Enterprise server.' + isGitea: + description: 'Whether to run in Gitea compatibility mode. Set this if `githubBaseUrl` targets a Gitea instance, since some API endpoints differ from GitHub' + default: 'false' assetNamePattern: description: 'The naming pattern to use for the uploaded assets' uploadPlainBinary: diff --git a/dist/index.js b/dist/index.js index 0f0d2a1..4d683f2 100644 --- a/dist/index.js +++ b/dist/index.js @@ -42926,12 +42926,14 @@ function allReleases(github, owner, repo) { return github.paginate.iterator(github.rest.repos.listReleases.endpoint.merge(params)); } /// Try to get release by tag. If there's none, releaseName is required to create one. -async function getOrCreateRelease(owner, repo, tagName, releaseName, body, commitish, draft = true, prerelease = true) { +async function getOrCreateRelease(owner, repo, tagName, githubBaseUrl, releaseName, body, commitish, draft = true, prerelease = true) { if (process.env.GITHUB_TOKEN === undefined) { throw new Error('GITHUB_TOKEN is required'); } // Get authenticated GitHub client (Ocktokit): https://github.com/actions/toolkit/tree/master/packages/github#usage - const github = (0,_actions_github__WEBPACK_IMPORTED_MODULE_2__.getOctokit)(process.env.GITHUB_TOKEN); + const github = (0,_actions_github__WEBPACK_IMPORTED_MODULE_2__.getOctokit)(process.env.GITHUB_TOKEN, { + baseUrl: githubBaseUrl, + }); const bodyPath = _actions_core__WEBPACK_IMPORTED_MODULE_1__.getInput('body_path', { required: false }); let bodyFileContent = null; if (bodyPath !== '' && !!bodyPath) { @@ -43067,6 +43069,10 @@ async function run() { const draft = _actions_core__WEBPACK_IMPORTED_MODULE_2__.getBooleanInput('releaseDraft'); const prerelease = _actions_core__WEBPACK_IMPORTED_MODULE_2__.getBooleanInput('prerelease'); const commitish = _actions_core__WEBPACK_IMPORTED_MODULE_2__.getInput('releaseCommitish') || null; + const githubBaseUrl = _actions_core__WEBPACK_IMPORTED_MODULE_2__.getInput('githubBaseUrl') || + process.env.GITHUB_API_URL || + 'https://api.github.com'; + const isGitea = _actions_core__WEBPACK_IMPORTED_MODULE_2__.getBooleanInput('isGitea'); // TODO: Change its default to true for v2 apps // Not using getBooleanInput so we can differentiate between true,false,unset later. const updaterJsonPreferNsis = _actions_core__WEBPACK_IMPORTED_MODULE_2__.getInput('updaterJsonPreferNsis')?.toLowerCase() === 'true'; @@ -43150,16 +43156,16 @@ async function run() { releaseName = releaseName.replace(regex, template.value); body = body.replace(regex, template.value); }); - const releaseData = await (0,_create_release__WEBPACK_IMPORTED_MODULE_4__/* .getOrCreateRelease */ .l)(owner, repo, tagName, releaseName || undefined, body, commitish || undefined, draft, prerelease); + const releaseData = await (0,_create_release__WEBPACK_IMPORTED_MODULE_4__/* .getOrCreateRelease */ .l)(owner, repo, tagName, githubBaseUrl, releaseName || undefined, body, commitish || undefined, draft, prerelease); releaseId = releaseData.id; _actions_core__WEBPACK_IMPORTED_MODULE_2__.setOutput('releaseUploadUrl', releaseData.uploadUrl); _actions_core__WEBPACK_IMPORTED_MODULE_2__.setOutput('releaseId', releaseData.id.toString()); _actions_core__WEBPACK_IMPORTED_MODULE_2__.setOutput('releaseHtmlUrl', releaseData.htmlUrl); } if (releaseId) { - await (0,_upload_release_assets__WEBPACK_IMPORTED_MODULE_5__/* .uploadAssets */ .r)(owner, repo, releaseId, artifacts, retryAttempts, assetNamePattern); + await (0,_upload_release_assets__WEBPACK_IMPORTED_MODULE_5__/* .uploadAssets */ .r)(owner, repo, releaseId, artifacts, retryAttempts, githubBaseUrl, isGitea, assetNamePattern); if (includeUpdaterJson) { - await (0,_upload_version_json__WEBPACK_IMPORTED_MODULE_6__/* .uploadVersionJSON */ .Y)(owner, repo, info.version, body, tagName, releaseId, releaseArtifacts.length !== 0 ? releaseArtifacts : debugArtifacts, targetInfo, info.unzippedSigs, updaterJsonPreferNsis, updaterJsonKeepUniversal, retryAttempts, assetNamePattern); + await (0,_upload_version_json__WEBPACK_IMPORTED_MODULE_6__/* .uploadVersionJSON */ .Y)(owner, repo, info.version, body, tagName, releaseId, releaseArtifacts.length !== 0 ? releaseArtifacts : debugArtifacts, targetInfo, info.unzippedSigs, updaterJsonPreferNsis, updaterJsonKeepUniversal, retryAttempts, githubBaseUrl, isGitea, assetNamePattern); } } else { @@ -43193,11 +43199,13 @@ __webpack_async_result__(); -async function uploadAssets(owner, repo, releaseId, assets, retryAttempts, assetNamePattern) { +async function uploadAssets(owner, repo, releaseId, assets, retryAttempts, githubBaseUrl, isGitea, assetNamePattern) { if (process.env.GITHUB_TOKEN === undefined) { throw new Error('GITHUB_TOKEN is required'); } - const github = (0,_actions_github__WEBPACK_IMPORTED_MODULE_1__.getOctokit)(process.env.GITHUB_TOKEN); + const github = (0,_actions_github__WEBPACK_IMPORTED_MODULE_1__.getOctokit)(process.env.GITHUB_TOKEN, { + baseUrl: githubBaseUrl, + }); const existingAssets = (await github.rest.repos.listReleaseAssets({ owner: owner, repo: repo, @@ -43221,11 +43229,16 @@ async function uploadAssets(owner, repo, releaseId, assets, retryAttempts, asset .replace(/[\u0300-\u036f]/g, '')); if (existingAsset) { console.log(`Deleting existing ${assetName}...`); - await github.rest.repos.deleteReleaseAsset({ - owner: owner, - repo: repo, - asset_id: existingAsset.id, - }); + if (isGitea) { + await (0,_utils__WEBPACK_IMPORTED_MODULE_2__/* .deleteGiteaReleaseAsset */ .Rx)(github, owner, repo, releaseId, existingAsset.id); + } + else { + await github.rest.repos.deleteReleaseAsset({ + owner: owner, + repo: repo, + asset_id: existingAsset.id, + }); + } } console.log(`Uploading ${assetName}...`); await (0,_utils__WEBPACK_IMPORTED_MODULE_2__/* .retry */ .L5)(() => github.rest.repos.uploadReleaseAsset({ @@ -43237,6 +43250,7 @@ async function uploadAssets(owner, repo, releaseId, assets, retryAttempts, asset owner: owner, repo: repo, release_id: releaseId, + baseUrl: githubBaseUrl, }), retryAttempts + 1); } } @@ -43264,11 +43278,13 @@ async function uploadAssets(owner, repo, releaseId, assets, retryAttempts, asset -async function uploadVersionJSON(owner, repo, version, notes, tagName, releaseId, artifacts, targetInfo, unzippedSig, updaterJsonPreferNsis, updaterJsonKeepUniversal, retryAttempts, assetNamePattern) { +async function uploadVersionJSON(owner, repo, version, notes, tagName, releaseId, artifacts, targetInfo, unzippedSig, updaterJsonPreferNsis, updaterJsonKeepUniversal, retryAttempts, githubBaseUrl, isGitea, assetNamePattern) { if (process.env.GITHUB_TOKEN === undefined) { throw new Error('GITHUB_TOKEN is required'); } - const github = (0,_actions_github__WEBPACK_IMPORTED_MODULE_2__.getOctokit)(process.env.GITHUB_TOKEN); + const github = (0,_actions_github__WEBPACK_IMPORTED_MODULE_2__.getOctokit)(process.env.GITHUB_TOKEN, { + baseUrl: githubBaseUrl, + }); const versionFilename = 'latest.json'; const versionFile = (0,node_path__WEBPACK_IMPORTED_MODULE_1__.resolve)(process.cwd(), versionFilename); const versionContent = { @@ -43285,16 +43301,31 @@ async function uploadVersionJSON(owner, repo, version, notes, tagName, releaseId }); const asset = assets.data.find((e) => e.name === versionFilename); if (asset) { - const assetData = (await github.request('GET /repos/{owner}/{repo}/releases/assets/{asset_id}', { - owner: owner, - repo: repo, - asset_id: asset.id, - headers: { - accept: 'application/octet-stream', - }, - })).data; - // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment - versionContent.platforms = JSON.parse(Buffer.from(assetData).toString()).platforms; + if (isGitea) { + const info = (await github.request('GET /repos/{owner}/{repo}/releases/{release_id}/assets/{asset_id}', { + owner, + repo, + release_id: releaseId, + asset_id: asset.id, + })).data; + const data = (await github.request(`GET ${info.browser_download_url}`)) + .data; + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + versionContent.platforms = JSON.parse(data).platforms; + } + else { + const assetData = (await github.request(`GET /repos/{owner}/{repo}/releases/assets/{asset_id}`, { + owner: owner, + repo: repo, + release_id: releaseId, + asset_id: asset.id, + headers: { + accept: 'application/octet-stream', + }, + })).data; + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + versionContent.platforms = JSON.parse(Buffer.from(assetData).toString()).platforms; + } } const downloadUrls = new Map(); for (const data of assets.data) { @@ -43424,13 +43455,18 @@ async function uploadVersionJSON(owner, repo, version, notes, tagName, releaseId } (0,node_fs__WEBPACK_IMPORTED_MODULE_0__.writeFileSync)(versionFile, JSON.stringify(versionContent, null, 2)); if (asset) { - // https://docs.github.com/en/rest/releases/assets#update-a-release-asset - await github.rest.repos.deleteReleaseAsset({ - owner: owner, - repo: repo, - release_id: releaseId, - asset_id: asset.id, - }); + if (isGitea) { + await (0,_utils__WEBPACK_IMPORTED_MODULE_4__/* .deleteGiteaReleaseAsset */ .Rx)(github, owner, repo, releaseId, asset.id); + } + else { + // https://docs.github.com/en/rest/releases/assets#update-a-release-asset + await github.rest.repos.deleteReleaseAsset({ + owner: owner, + repo: repo, + release_id: releaseId, + asset_id: asset.id, + }); + } } const artifact = (0,_utils__WEBPACK_IMPORTED_MODULE_4__/* .createArtifact */ .Dg)({ path: versionFile, @@ -43441,7 +43477,7 @@ async function uploadVersionJSON(owner, repo, version, notes, tagName, releaseId bundle: '', version, }); - await (0,_upload_release_assets__WEBPACK_IMPORTED_MODULE_3__/* .uploadAssets */ .r)(owner, repo, releaseId, [artifact], retryAttempts); + await (0,_upload_release_assets__WEBPACK_IMPORTED_MODULE_3__/* .uploadAssets */ .r)(owner, repo, releaseId, [artifact], retryAttempts, githubBaseUrl, isGitea); } @@ -43454,6 +43490,7 @@ async function uploadVersionJSON(owner, repo, version, notes, tagName, releaseId // EXPORTS __nccwpck_require__.d(__webpack_exports__, { Dg: () => (/* binding */ createArtifact), + Rx: () => (/* binding */ deleteGiteaReleaseAsset), NK: () => (/* binding */ execCommand), wm: () => (/* binding */ getAssetName), Vp: () => (/* binding */ getInfo), @@ -53502,6 +53539,16 @@ async function retry(fn, attempts) { } } } +// Helper function to delete a Gitea release asset +// This is a workaround since Gitea's API is incompatible with the GitHub API +function deleteGiteaReleaseAsset(github, owner, repo, releaseId, assetId) { + return github.request('DELETE /repos/{owner}/{repo}/releases/{release_id}/assets/{asset_id}', { + owner, + repo, + release_id: releaseId, + asset_id: assetId, + }); +} // TODO: Properly resolve the eslint issues in this file. diff --git a/src/create-release.ts b/src/create-release.ts index 12a0f6e..c98beca 100644 --- a/src/create-release.ts +++ b/src/create-release.ts @@ -33,6 +33,7 @@ export async function getOrCreateRelease( owner: string, repo: string, tagName: string, + githubBaseUrl: string, releaseName?: string, body?: string, commitish?: string, @@ -44,7 +45,9 @@ export async function getOrCreateRelease( } // Get authenticated GitHub client (Ocktokit): https://github.com/actions/toolkit/tree/master/packages/github#usage - const github = getOctokit(process.env.GITHUB_TOKEN); + const github = getOctokit(process.env.GITHUB_TOKEN, { + baseUrl: githubBaseUrl, + }); const bodyPath = core.getInput('body_path', { required: false }); let bodyFileContent: string | null = null; diff --git a/src/index.ts b/src/index.ts index 109b5fd..7911997 100644 --- a/src/index.ts +++ b/src/index.ts @@ -45,6 +45,11 @@ async function run(): Promise { const draft = core.getBooleanInput('releaseDraft'); const prerelease = core.getBooleanInput('prerelease'); const commitish = core.getInput('releaseCommitish') || null; + const githubBaseUrl = + core.getInput('githubBaseUrl') || + process.env.GITHUB_API_URL || + 'https://api.github.com'; + const isGitea = core.getBooleanInput('isGitea'); // TODO: Change its default to true for v2 apps // Not using getBooleanInput so we can differentiate between true,false,unset later. @@ -178,6 +183,7 @@ async function run(): Promise { owner, repo, tagName, + githubBaseUrl, releaseName || undefined, body, commitish || undefined, @@ -197,6 +203,8 @@ async function run(): Promise { releaseId, artifacts, retryAttempts, + githubBaseUrl, + isGitea, assetNamePattern, ); @@ -214,6 +222,8 @@ async function run(): Promise { updaterJsonPreferNsis, updaterJsonKeepUniversal, retryAttempts, + githubBaseUrl, + isGitea, assetNamePattern, ); } diff --git a/src/upload-release-assets.ts b/src/upload-release-assets.ts index 2a4ecce..931fe49 100644 --- a/src/upload-release-assets.ts +++ b/src/upload-release-assets.ts @@ -2,7 +2,7 @@ import fs from 'node:fs'; import { getOctokit } from '@actions/github'; -import { getAssetName, retry } from './utils'; +import { deleteGiteaReleaseAsset, getAssetName, retry } from './utils'; import type { Artifact } from './types'; export async function uploadAssets( @@ -11,13 +11,17 @@ export async function uploadAssets( releaseId: number, assets: Artifact[], retryAttempts: number, + githubBaseUrl: string, + isGitea: boolean, assetNamePattern?: string, ) { if (process.env.GITHUB_TOKEN === undefined) { throw new Error('GITHUB_TOKEN is required'); } - const github = getOctokit(process.env.GITHUB_TOKEN); + const github = getOctokit(process.env.GITHUB_TOKEN, { + baseUrl: githubBaseUrl, + }); const existingAssets = ( await github.rest.repos.listReleaseAssets({ @@ -49,13 +53,24 @@ export async function uploadAssets( .normalize('NFD') .replace(/[\u0300-\u036f]/g, ''), ); + if (existingAsset) { console.log(`Deleting existing ${assetName}...`); - await github.rest.repos.deleteReleaseAsset({ - owner: owner, - repo: repo, - asset_id: existingAsset.id, - }); + if (isGitea) { + await deleteGiteaReleaseAsset( + github, + owner, + repo, + releaseId, + existingAsset.id, + ); + } else { + await github.rest.repos.deleteReleaseAsset({ + owner: owner, + repo: repo, + asset_id: existingAsset.id, + }); + } } console.log(`Uploading ${assetName}...`); @@ -71,6 +86,7 @@ export async function uploadAssets( owner: owner, repo: repo, release_id: releaseId, + baseUrl: githubBaseUrl, }), retryAttempts + 1, ); diff --git a/src/upload-version-json.ts b/src/upload-version-json.ts index 0d9f7e2..4c85fd4 100644 --- a/src/upload-version-json.ts +++ b/src/upload-version-json.ts @@ -4,7 +4,7 @@ import { basename, extname, resolve } from 'node:path'; import { getOctokit } from '@actions/github'; import { uploadAssets } from './upload-release-assets'; -import { getAssetName } from './utils'; +import { deleteGiteaReleaseAsset, getAssetName } from './utils'; import type { Artifact, TargetInfo } from './types'; import { createArtifact } from './utils'; @@ -36,13 +36,17 @@ export async function uploadVersionJSON( updaterJsonPreferNsis: boolean, updaterJsonKeepUniversal: boolean, retryAttempts: number, + githubBaseUrl: string, + isGitea: boolean, assetNamePattern?: string, ) { if (process.env.GITHUB_TOKEN === undefined) { throw new Error('GITHUB_TOKEN is required'); } - const github = getOctokit(process.env.GITHUB_TOKEN); + const github = getOctokit(process.env.GITHUB_TOKEN, { + baseUrl: githubBaseUrl, + }); const versionFilename = 'latest.json'; const versionFile = resolve(process.cwd(), versionFilename); @@ -62,25 +66,49 @@ export async function uploadVersionJSON( const asset = assets.data.find((e) => e.name === versionFilename); if (asset) { - const assetData = ( - await github.request( - 'GET /repos/{owner}/{repo}/releases/assets/{asset_id}', - { - owner: owner, - repo: repo, - asset_id: asset.id, - headers: { - accept: 'application/octet-stream', + if (isGitea) { + const info = ( + await github.request( + 'GET /repos/{owner}/{repo}/releases/{release_id}/assets/{asset_id}', + { + owner, + repo, + release_id: releaseId, + asset_id: asset.id, }, - }, - ) - ).data as unknown as ArrayBuffer; + ) + ).data as { browser_download_url: string }; - // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment - versionContent.platforms = JSON.parse( - Buffer.from(assetData).toString(), - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access - ).platforms; + const data = (await github.request(`GET ${info.browser_download_url}`)) + .data as string; + + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + versionContent.platforms = JSON.parse( + data, + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access + ).platforms; + } else { + const assetData = ( + await github.request( + `GET /repos/{owner}/{repo}/releases/assets/{asset_id}`, + { + owner: owner, + repo: repo, + release_id: releaseId, + asset_id: asset.id, + headers: { + accept: 'application/octet-stream', + }, + }, + ) + ).data as unknown as ArrayBuffer; + + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + versionContent.platforms = JSON.parse( + Buffer.from(assetData).toString(), + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access + ).platforms; + } } const downloadUrls = new Map(); @@ -239,13 +267,17 @@ export async function uploadVersionJSON( writeFileSync(versionFile, JSON.stringify(versionContent, null, 2)); if (asset) { - // https://docs.github.com/en/rest/releases/assets#update-a-release-asset - await github.rest.repos.deleteReleaseAsset({ - owner: owner, - repo: repo, - release_id: releaseId, - asset_id: asset.id, - }); + if (isGitea) { + await deleteGiteaReleaseAsset(github, owner, repo, releaseId, asset.id); + } else { + // https://docs.github.com/en/rest/releases/assets#update-a-release-asset + await github.rest.repos.deleteReleaseAsset({ + owner: owner, + repo: repo, + release_id: releaseId, + asset_id: asset.id, + }); + } } const artifact = createArtifact({ @@ -258,5 +290,13 @@ export async function uploadVersionJSON( version, }); - await uploadAssets(owner, repo, releaseId, [artifact], retryAttempts); + await uploadAssets( + owner, + repo, + releaseId, + [artifact], + retryAttempts, + githubBaseUrl, + isGitea, + ); } diff --git a/src/utils.ts b/src/utils.ts index b70f176..cc1510c 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -22,6 +22,7 @@ import type { TargetInfo, TargetPlatform, } from './types'; +import { GitHub } from '@actions/github/lib/utils'; /*** constants ***/ export const extensions = [ @@ -512,4 +513,24 @@ export async function retry( } } +// Helper function to delete a Gitea release asset +// This is a workaround since Gitea's API is incompatible with the GitHub API +export function deleteGiteaReleaseAsset( + github: InstanceType, + owner: string, + repo: string, + releaseId: number, + assetId: number, +) { + return github.request( + 'DELETE /repos/{owner}/{repo}/releases/{release_id}/assets/{asset_id}', + { + owner, + repo, + release_id: releaseId, + asset_id: assetId, + }, + ); +} + // TODO: Properly resolve the eslint issues in this file.