Skip to content

Commit

Permalink
feat(action) add option to include a debug build (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Jul 12, 2020
1 parent aa485d7 commit a6b824c
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 27 deletions.
5 changes: 5 additions & 0 deletions .changes/debug-build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"action": patch
---

Adds an option to include a debug build with the `includeDebug` (bool) input.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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

Expand Down
2 changes: 2 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
12 changes: 9 additions & 3 deletions dist/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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.');
}
Expand All @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion dist/upload-release-assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
});
}
Expand Down
24 changes: 12 additions & 12 deletions src/create-release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
Expand Down Expand Up @@ -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.`)
Expand Down Expand Up @@ -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
}
}

Expand Down
22 changes: 14 additions & 8 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -150,19 +150,25 @@ async function run(): Promise<void> {
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.')
Expand Down
5 changes: 3 additions & 2 deletions src/upload-release-assets.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as core from '@actions/core'
import { GitHub } from '@actions/github'
import fs from 'fs'
import path from 'path'
Expand All @@ -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)
})
}
Expand Down

0 comments on commit a6b824c

Please sign in to comment.