Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable adding a note to the release #274

Merged
merged 1 commit into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Inputs are provided using the `with:` section of your workflow YML file.
| default_branch | Used to finalize a release when code is pushed to this branch | false | Repo configured [default branch](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-branches#about-the-default-branch) |
| multi_dockerignore | Respect .dockerignore in each service | false | false |
| debug | Enable debug logs for balena push build | false | false |
| note | Enable adding a note to the release | false | |

`balena_token` and other tokens needs to be stored in GitHub as an [encrypted secret](https://docs.github.com/en/actions/security-guides/encrypted-secrets#creating-encrypted-secrets-for-a-repository) that GitHub Actions can access.

Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ inputs:
description: Enable debug logs for balena push build
required: false
default: "false"
note:
description: Enable adding a note to the release
required: false
default: ""
outputs:
release_id:
description: ID of the release built
Expand Down
1 change: 1 addition & 0 deletions src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ export async function run(
noCache: inputs.layerCache === false,
multiDockerignore: inputs.multiDockerignore,
debug: inputs.debug,
note: inputs.note,
});
} catch (e: any) {
core.error(e.message);
Expand Down
12 changes: 11 additions & 1 deletion src/balena-utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as core from '@actions/core';
import { exec } from '@actions/exec';
import { spawn } from 'child_process';
import * as balena from 'balena-sdk';
import { spawn } from 'child_process';

import { Release } from './types';

Expand All @@ -23,13 +23,15 @@ type BuildOptions = {
tags: Tags;
multiDockerignore: boolean;
debug: boolean;
note: string;
};

const DEFAULT_BUILD_OPTIONS: Partial<BuildOptions> = {
draft: true,
noCache: false,
multiDockerignore: false,
debug: false,
note: "",
};

let sdk: ReturnType<typeof balena.getSdk> | null = null;
Expand Down Expand Up @@ -111,6 +113,14 @@ export async function push(
pushOpt.push('--debug');
}

if (buildOpt.note.trim()) {
pushOpt.push('--note');

// sanitize note string to escape quotes
const note = buildOpt.note.trim().replace(/"/g, '\\"').replace(/'/g, "\\'");
treygilliland marked this conversation as resolved.
Show resolved Hide resolved
pushOpt.push(`"${note}"`);
}

let releaseId: string | null = null;

return new Promise((resolve, reject) => {
Expand Down
1 change: 1 addition & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const inputs: Inputs = {
defaultBranch: core.getInput('default_branch', { required: false }),
multiDockerignore: core.getBooleanInput('multi_dockerignore', { required: false }),
debug: core.getBooleanInput('debug', { required: false }),
note: core.getInput('note', { required: false }),
};

(async () => {
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export type Inputs = {
defaultBranch: string;
multiDockerignore: boolean;
debug: boolean;
note: string;
};

export type RepoContext = {
Expand Down
5 changes: 5 additions & 0 deletions tests/src/action.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const inputs: Partial<Inputs> = {
defaultBranch: '',
multiDockerignore: true,
debug: true,
note: 'My useful note',
};

describe('src/action', () => {
Expand Down Expand Up @@ -139,6 +140,7 @@ describe('src/action', () => {
draft: false,
multiDockerignore: true,
debug: true,
note: 'My useful note',
noCache: true,
tags: {
sha: 'fba0317620597271695087c168c50d8c94975a29',
Expand Down Expand Up @@ -185,6 +187,7 @@ describe('src/action', () => {
expect(pushStub.lastCall.lastArg).to.deep.equal({
multiDockerignore: true,
debug: true,
note: 'My useful note',
noCache: false,
tags: {
sha: 'fba0317620597271695087c168c50d8c94975a29',
Expand Down Expand Up @@ -242,6 +245,7 @@ describe('src/action', () => {
draft: false,
multiDockerignore: true,
debug: true,
note: 'My useful note',
tags: {
sha: 'fba0317620597271695087c168c50d8c94975a29',
},
Expand All @@ -266,6 +270,7 @@ describe('src/action', () => {
noCache: false,
multiDockerignore: true,
debug: true,
note: 'My useful note',
draft: false,
tags: {
sha: 'fba0317620597271695087c168c50d8c94975a29',
Expand Down
5 changes: 4 additions & 1 deletion tests/src/balena-utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ describe('src/balena-utils', () => {
]);
});

it('Sets --draft, --nocache and --multi-dockerignore and --debug', async () => {
it('Sets --draft, --nocache and --multi-dockerignore and --debug and --note', async () => {
setTimeout(() => {
mockProcess.emit('exit', 0); // make process exit
}, 500);
Expand All @@ -138,6 +138,7 @@ describe('src/balena-utils', () => {
draft: true,
multiDockerignore: true,
debug: true,
note: 'My useful note',
tags: { sha: 'fba0317620597271695087c168c50d8c94975a29' },
});
} catch (e) {
Expand All @@ -156,6 +157,8 @@ describe('src/balena-utils', () => {
'--nocache',
'--multi-dockerignore',
'--debug',
'--note',
'"My useful note"',
]);
});

Expand Down
2 changes: 2 additions & 0 deletions tests/src/main.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ describe('src/main', () => {
source: dynamicSource,
github_token: 'ghTokenExample',
default_branch: '',
note: 'My useful note',
}[inputName];
});

Expand Down Expand Up @@ -112,6 +113,7 @@ describe('src/main', () => {
defaultBranch: '',
multiDockerignore: true,
debug: true,
note: 'My useful note',
});
// Since github actions pass by default there's no need to check if the action passes
// So, let's check if the action correctly handles failures instead
Expand Down
Loading