Skip to content

Commit

Permalink
Enable adding a note to the release
Browse files Browse the repository at this point in the history
Change-type: minor
  • Loading branch information
treygilliland committed Oct 31, 2023
1 parent 4495424 commit 469c682
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 1 deletion.
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
10 changes: 10 additions & 0 deletions src/balena-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
pushOpt.push('--note');

// sanitize note string to escape quotes
const note = buildOpt.note.trim().replace(/"/g, '\\"').replace(/'/g, "\\'");
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

0 comments on commit 469c682

Please sign in to comment.