diff --git a/.changes/debug-build.md b/.changes/debug-build.md new file mode 100644 index 0000000000..c6eae573dd --- /dev/null +++ b/.changes/debug-build.md @@ -0,0 +1,5 @@ +--- +"action": patch +--- + +Adds an option to include a debug build with the `includeDebug` (bool) input. diff --git a/README.md b/README.md index bde5c502f4..6152433b15 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ jobs: yarn build - name: install app dependencies and build it run: yarn && yarn build - - uses: tauri-apps/tauri-action + - uses: tauri-apps/tauri-action@v0 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: @@ -71,6 +71,7 @@ jobs: | `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 | | `iconPath` | false | path to the PNG icon to use as app icon, relative to the projectPath | string | | +| `includeDebug` | false | whether to include a debug build or not | bool | | ## Outputs diff --git a/action.yml b/action.yml index 3a84e9810a..6c597569cd 100644 --- a/action.yml +++ b/action.yml @@ -26,6 +26,8 @@ inputs: description: 'path to the distributable folder with your index.html and JS/CSS' iconPath: description: 'path to the PNG icon to use as app icon, relative to the projectPath' + includeDebug: + description: 'whether to include a debug build or not' outputs: releaseId: description: 'The ID of the created release' diff --git a/dist/main.js b/dist/main.js index 97b10cf54f..7c93333392 100644 --- a/dist/main.js +++ b/dist/main.js @@ -155,6 +155,7 @@ function run() { const configPath = path_1.join(projectPath, core.getInput('configPath') || 'tauri.conf.json'); const distPath = core.getInput('distPath'); const iconPath = core.getInput('iconPath'); + const includeDebug = core.getInput('includeDebug') === 'true'; let tagName = core.getInput('tagName').replace('refs/tags/', ''); let releaseName = core.getInput('releaseName').replace('refs/tags/', ''); let body = core.getInput('releaseBody'); @@ -164,7 +165,12 @@ function run() { if (Boolean(tagName) !== Boolean(releaseName)) { throw new Error('`tag` is required along with `releaseName` when creating a release.'); } - const artifacts = yield buildProject(projectPath, false, { configPath: fs_1.existsSync(configPath) ? configPath : null, distPath, iconPath }); + const options = { configPath: fs_1.existsSync(configPath) ? configPath : null, distPath, iconPath }; + const artifacts = yield buildProject(projectPath, false, options); + if (includeDebug) { + const debugArtifacts = yield buildProject(projectPath, true, options); + artifacts.push(...debugArtifacts); + } if (artifacts.length === 0) { throw new Error('No artifacts were found.'); } @@ -179,8 +185,8 @@ function run() { templates.forEach(template => { const regex = new RegExp(template.key, 'g'); tagName = tagName.replace(regex, template.value); - releaseName = releaseName.replace(releaseName, template.value); - body = body.replace(body, template.value); + releaseName = releaseName.replace(regex, template.value); + body = body.replace(regex, template.value); }); const releaseData = yield create_release_1.default(tagName, releaseName, body, commitish || undefined, draft, prerelease); uploadUrl = releaseData.uploadUrl; diff --git a/dist/upload-release-assets.js b/dist/upload-release-assets.js index 5dad7c24f0..a502a3ce08 100644 --- a/dist/upload-release-assets.js +++ b/dist/upload-release-assets.js @@ -25,10 +25,12 @@ function uploadAssets(uploadUrl, assets) { const contentLength = (filePath) => fs_1.default.statSync(filePath).size; for (const assetPath of assets) { const headers = { 'content-type': 'application/zip', 'content-length': contentLength(assetPath) }; + const ext = path_1.default.extname(assetPath); + const filename = path_1.default.basename(assetPath).replace(ext, ''); yield github.repos.uploadReleaseAsset({ url: uploadUrl, headers, - name: path_1.default.basename(assetPath), + name: path_1.default.dirname(assetPath).endsWith('debug') ? `${filename}-debug${ext}` : `${filename}${ext}`, data: fs_1.default.readFileSync(assetPath) }); } diff --git a/src/create-release.ts b/src/create-release.ts index 0f44493a3a..258d8f7d9f 100644 --- a/src/create-release.ts +++ b/src/create-release.ts @@ -3,22 +3,22 @@ import { GitHub, context } from '@actions/github' import fs from 'fs' interface Release { - id: number, - uploadUrl: string, + id: number + uploadUrl: string htmlUrl: string } interface GitHubRelease { - id: number; - upload_url: string; - html_url: string; - tag_name: string; - body: string; - target_commitish: string; + id: number + upload_url: string + html_url: string + tag_name: string + body: string + target_commitish: string } function allReleases(github: GitHub): AsyncIterableIterator<{ data: GitHubRelease[] }> { - const params = { per_page: 100, ...context.repo }; + const params = { per_page: 100, ...context.repo } return github.paginate.iterator( github.repos.listReleases.endpoint.merge(params) ); @@ -52,7 +52,7 @@ export default async function createRelease(tagName: string, releaseName: string if (draft) { 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); + let releaseWithTag = response.data.find(release => release.tag_name === tagName) if (releaseWithTag) { release = releaseWithTag console.log(`Found draft release with tag ${tagName} on the release list.`) @@ -89,8 +89,8 @@ export default async function createRelease(tagName: string, releaseName: string } else { console.log( `⚠️ Unexpected error fetching GitHub release for tag ${tagName}: ${error}` - ); - throw error; + ) + throw error } } diff --git a/src/main.ts b/src/main.ts index 1d024e9350..c2ce31ebad 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,4 +1,4 @@ -import { platform } from 'os'; +import { platform } from 'os' import * as core from '@actions/core' import execa from 'execa' import { join, resolve } from 'path' @@ -150,19 +150,25 @@ async function run(): Promise { const configPath = join(projectPath, core.getInput('configPath') || 'tauri.conf.json') const distPath = core.getInput('distPath') const iconPath = core.getInput('iconPath') + const includeDebug = core.getInput('includeDebug') === 'true' - let tagName = core.getInput('tagName').replace('refs/tags/', ''); - let releaseName = core.getInput('releaseName').replace('refs/tags/', ''); - let body = core.getInput('releaseBody'); - const draft = core.getInput('releaseDraft') === 'true'; - const prerelease = core.getInput('prerelease') === 'true'; - const commitish = core.getInput('releaseCommitish') || null; + let tagName = core.getInput('tagName').replace('refs/tags/', '') + let releaseName = core.getInput('releaseName').replace('refs/tags/', '') + let body = core.getInput('releaseBody') + const draft = core.getInput('releaseDraft') === 'true' + const prerelease = core.getInput('prerelease') === 'true' + const commitish = core.getInput('releaseCommitish') || null if (Boolean(tagName) !== Boolean(releaseName)) { throw new Error('`tag` is required along with `releaseName` when creating a release.') } - const artifacts = await buildProject(projectPath, false, { configPath: existsSync(configPath) ? configPath : null, distPath, iconPath }) + const options = { configPath: existsSync(configPath) ? configPath : null, distPath, iconPath } + const artifacts = await buildProject(projectPath, false, options) + if (includeDebug) { + const debugArtifacts = await buildProject(projectPath, true, options) + artifacts.push(...debugArtifacts) + } if (artifacts.length === 0) { throw new Error('No artifacts were found.') diff --git a/src/upload-release-assets.ts b/src/upload-release-assets.ts index 5ec2b42064..0ed748e839 100644 --- a/src/upload-release-assets.ts +++ b/src/upload-release-assets.ts @@ -1,4 +1,3 @@ -import * as core from '@actions/core' import { GitHub } from '@actions/github' import fs from 'fs' import path from 'path' @@ -16,10 +15,12 @@ export default async function uploadAssets(uploadUrl: string, assets: string[]) for (const assetPath of assets) { const headers = { 'content-type': 'application/zip', 'content-length': contentLength(assetPath) } + const ext = path.extname(assetPath) + const filename = path.basename(assetPath).replace(ext, '') await github.repos.uploadReleaseAsset({ url: uploadUrl, headers, - name: path.basename(assetPath), + name: path.dirname(assetPath).endsWith('debug') ? `${filename}-debug${ext}` : `${filename}${ext}`, data: fs.readFileSync(assetPath) }) }