diff --git a/README.md b/README.md index 492edeb9..7bd64530 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,7 @@ Inputs are provided using the `with:` section of your workflow YML file. | layer_cache | Use cached layers of previously built images for this project | false | true | | registry_secrets | JSON string containing image registry credentials used to pull base images | false | | | 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 | `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. diff --git a/action.yml b/action.yml index 8378140d..944a116f 100644 --- a/action.yml +++ b/action.yml @@ -55,6 +55,10 @@ inputs: description: Branch for finalizing releases required: false default: "" + multi_dockerignore: + description: Use service's dockerignore file + required: false + default: false outputs: release_id: description: ID of the release built diff --git a/src/action.ts b/src/action.ts index a28adc54..89d5660f 100644 --- a/src/action.ts +++ b/src/action.ts @@ -136,6 +136,7 @@ export async function run( releaseId = await balena.push(inputs.fleet, inputs.source, inputs.cache, { ...buildOptions, noCache: inputs.layerCache === false, + multiDockerignore: inputs.multiDockerignore, }); } catch (e: any) { core.error(e.message); diff --git a/src/balena-utils.ts b/src/balena-utils.ts index 91f1d907..f5a58f47 100644 --- a/src/balena-utils.ts +++ b/src/balena-utils.ts @@ -21,11 +21,13 @@ type BuildOptions = { noCache: boolean; draft: boolean; tags: Tags; + multiDockerignore: boolean; }; const DEFAULT_BUILD_OPTIONS: Partial = { draft: true, noCache: false, + multiDockerignore: false, }; let sdk: ReturnType | null = null; @@ -99,6 +101,10 @@ export async function push( pushOpt.push('--nocache'); } + if (buildOpt.multiDockerignore) { + pushOpt.push('--multi-dockerignore'); + } + let releaseId: string | null = null; return new Promise((resolve, reject) => { diff --git a/src/main.ts b/src/main.ts index 9c0f4d4d..eb30b50a 100644 --- a/src/main.ts +++ b/src/main.ts @@ -25,6 +25,7 @@ const inputs: Inputs = { githubToken: core.getInput('github_token', { required: false }), layerCache: core.getBooleanInput('layer_cache', { required: false }), defaultBranch: core.getInput('default_branch', { required: false }), + multiDockerignore: core.getBooleanInput('multi_dockerignore', { required: false }), }; (async () => { diff --git a/src/types.ts b/src/types.ts index d38f0834..98c42a41 100644 --- a/src/types.ts +++ b/src/types.ts @@ -9,6 +9,7 @@ export type Inputs = { createTag: boolean; layerCache: boolean; defaultBranch: string; + multiDockerignore: boolean; }; export type RepoContext = { diff --git a/tests/src/action.spec.ts b/tests/src/action.spec.ts index 0a15d8b3..86e9cd68 100644 --- a/tests/src/action.spec.ts +++ b/tests/src/action.spec.ts @@ -31,6 +31,7 @@ const inputs: Partial = { source: '/src', layerCache: true, defaultBranch: '', + multiDockerignore: true, }; describe('src/action', () => { @@ -135,6 +136,7 @@ describe('src/action', () => { expect(pushStub.lastCall.args[1]).to.equal('/src'); expect(pushStub.lastCall.lastArg).to.deep.equal({ draft: false, + multiDockerignore: true, noCache: true, tags: { sha: 'fba0317620597271695087c168c50d8c94975a29', @@ -179,6 +181,7 @@ describe('src/action', () => { await action.run(prContext, { ...inputs, createTag: true }); // Check that the last arg (buildOptions) does not contain draft: true expect(pushStub.lastCall.lastArg).to.deep.equal({ + multiDockerignore: true, noCache: false, tags: { sha: 'fba0317620597271695087c168c50d8c94975a29', @@ -234,6 +237,7 @@ describe('src/action', () => { expect(pushStub.lastCall.lastArg).to.deep.equal({ noCache: false, draft: false, + multiDockerignore: true, tags: { sha: 'fba0317620597271695087c168c50d8c94975a29', }, @@ -256,6 +260,7 @@ describe('src/action', () => { // Check that the last arg (buildOptions) does not contain draft: true expect(pushStub.lastCall.lastArg).to.deep.equal({ noCache: false, + multiDockerignore: true, draft: false, tags: { sha: 'fba0317620597271695087c168c50d8c94975a29', diff --git a/tests/src/balena-utils.spec.ts b/tests/src/balena-utils.spec.ts index 52687a4f..e305e94a 100644 --- a/tests/src/balena-utils.spec.ts +++ b/tests/src/balena-utils.spec.ts @@ -127,7 +127,7 @@ describe('src/balena-utils', () => { ]); }); - it('Sets --draft or --nocache', async () => { + it('Sets --draft, --nocache and --multi-dockerignore', async () => { setTimeout(() => { mockProcess.emit('exit', 0); // make process exit }, 500); @@ -136,6 +136,7 @@ describe('src/balena-utils', () => { await balenaUtils.push('org/fleet', '/tmp/source', false, { noCache: true, draft: true, + multiDockerignore: true, tags: { sha: 'fba0317620597271695087c168c50d8c94975a29' }, }); } catch (e) { @@ -152,6 +153,7 @@ describe('src/balena-utils', () => { 'fba0317620597271695087c168c50d8c94975a29', '--draft', '--nocache', + '--multi-dockerignore', ]); }); diff --git a/tests/src/main.spec.ts b/tests/src/main.spec.ts index 69a399ea..1b269733 100644 --- a/tests/src/main.spec.ts +++ b/tests/src/main.spec.ts @@ -55,6 +55,7 @@ describe('src/main', () => { create_tag: true, create_ref: false, layer_cache: true, + multi_dockerignore: true, }[inputName]; }); }); @@ -108,6 +109,7 @@ describe('src/main', () => { githubToken: 'ghTokenExample', layerCache: true, defaultBranch: '', + multiDockerignore: true, }); // 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