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

Fail release-libraries action if the lib has libpatch greater than expected version #135

Merged
merged 4 commits into from
May 24, 2024
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
314 changes: 268 additions & 46 deletions dist/channel/index.js

Large diffs are not rendered by default.

314 changes: 268 additions & 46 deletions dist/check-libraries/index.js

Large diffs are not rendered by default.

314 changes: 268 additions & 46 deletions dist/release-charm/index.js

Large diffs are not rendered by default.

314 changes: 268 additions & 46 deletions dist/release-libraries/index.js

Large diffs are not rendered by default.

314 changes: 268 additions & 46 deletions dist/upload-bundle/index.js

Large diffs are not rendered by default.

314 changes: 268 additions & 46 deletions dist/upload-charm/index.js

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions release-libraries/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ inputs:
required: true
description: |
Github Token needed for automatic tagging when publishing
fail-build:
required: false
default: true
description: >
Whether to fail the entire build if publishing lib fails for any reason.
runs:
using: node20
main: ../dist/release-libraries/index.js
Expand Down
48 changes: 48 additions & 0 deletions src/services/charmcraft/charmcraft.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -845,4 +845,52 @@ describe('the charmcraft service', () => {
);
});
});

describe('test publishing libs', () => {
describe('with a correct version', () => {
it('should succeed without a failure', async () => {
const charmcraft = new Charmcraft('token');

mockExec.mockResolvedValue({
exitCode: 0,
stderr: '',
stdout:
'Library charms.test.v0.lib sent to the store with version 0.2',
});

const response = await charmcraft.publishLib('test', 'v0', 'lib');
expect(response).toBeTruthy();

expect(mockExec).toHaveBeenCalled();
expect(mockExec).toHaveBeenCalledWith(
'charmcraft',
['publish-lib', 'charms.test.v0.lib'],
expect.anything(),
);
});
});

describe('with an incorrect version', () => {
it('should return a failure', async () => {
const charmcraft = new Charmcraft('token');

mockExec.mockResolvedValue({
exitCode: 0,
stderr: '',
stdout:
"Library charms.test.v0.lib has a wrong LIBPATCH number, it's too high and needs to be consecutive Charmhub highest version is 0.1.",
});

const response = await charmcraft.publishLib('test', 'v0', 'lib');
expect(response).toBeFalsy();

expect(mockExec).toHaveBeenCalled();
expect(mockExec).toHaveBeenCalledWith(
'charmcraft',
['publish-lib', 'charms.test.v0.lib'],
expect.anything(),
);
});
});
});
});
17 changes: 12 additions & 5 deletions src/services/charmcraft/charmcraft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,12 +422,19 @@ class Charmcraft {
async publishLib(charm: string, majorVersion: string, libName: string) {
const args = ['publish-lib', `charms.${charm}.${majorVersion}.${libName}`];
debug(`about to publish lib with ${args}`);
await exec('charmcraft', args, this.execOptions).catch((reason: any) => {
const msg: string = `charmcraft ${args} ${this.execOptions} failed with ${reason}`;
debug(msg);
core.setFailed(msg);
const { exitCode, stdout, stderr } = await getExecOutput(
'charmcraft',
args,
this.execOptions,
);
if (exitCode !== 0 || stdout.indexOf('has a wrong LIBPATCH number') > 0) {
if (exitCode !== 0) {
core.setFailed(stderr);
} else {
core.setFailed(stdout);
}
return false;
});
}
return true;
}
}
Expand Down
Loading