Skip to content

Commit

Permalink
Release Charm Action (#38)
Browse files Browse the repository at this point in the history
* get and update gh Release

* charmcraft parse status and release

* helper function for parsing gh release body

* release charm action

* build release charm action

* catch error from github tagging

* Add charm path input to support multi charm repos

charmcraft.metadata() would fail if metadata.yaml is not in the current
directory
update readme with more information

* polish readme

* no longer support revision number as input

* Update integrate.yaml

turn off bundle test pending #23 and #40

* add description for multi charm repo

* Update release-charm/README.md

Co-authored-by: Simon Aronsson <simme@arcticbit.se>
  • Loading branch information
agathanatasha and simskij committed Apr 29, 2022
1 parent 2a52773 commit b01573c
Show file tree
Hide file tree
Showing 19 changed files with 23,459 additions and 61 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/integrate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ jobs:
channel: '${{ steps.channel.outputs.name }}'
github-token: '${{ secrets.GITHUB_TOKEN }}'

- name: Upload bundle to charmhub
uses: ./upload-bundle
with:
credentials: '${{ secrets.CHARMCRAFT_AUTH }}'
bundle-path: test-bundle/
github-token: '${{ secrets.GITHUB_TOKEN }}'
# - name: Upload bundle to charmhub
# uses: ./upload-bundle
# with:
# credentials: '${{ secrets.CHARMCRAFT_AUTH }}'
# bundle-path: test-bundle/
# github-token: '${{ secrets.GITHUB_TOKEN }}'
106 changes: 104 additions & 2 deletions dist/channel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21704,6 +21704,75 @@ class Charmcraft {
return { ok: lines.length <= 0, out, err };
});
}
status(charm) {
return __awaiter(this, void 0, void 0, function* () {
const result = yield (0, exec_1.getExecOutput)('charmcraft', ['status', charm], this.execOptions);
return result.stdout;
});
}
getRevisionInfoFromChannel(charm, track, channel) {
return __awaiter(this, void 0, void 0, function* () {
// For now we have to parse the `charmcraft status` output this will soon be fixed
// when we can get json output from charmcraft.
// Issue tracked here: https://github.com/canonical/charmcraft/issues/183
const acceptedChannels = ['stable', 'candidate', 'beta', 'edge'];
if (!acceptedChannels.includes(channel)) {
throw new Error(`Provided channel ${channel} is not supported. This actions currently only works with one of the following default channels: edge, beta, candidate, stable`);
}
const charmcraftStatus = yield this.status(charm);
const channelLine = {
stable: 0,
candidate: 1,
beta: 2,
edge: 3,
};
const lines = charmcraftStatus.split('\n');
for (let i = 1; i < lines.length; i += 4) {
// find line with track name
if (lines[i].includes(track)) {
i += channelLine[channel];
const targetLine = channel === 'stable'
? lines[i].slice(lines[i].search(/stable/g))
: lines[i];
const splitLine = targetLine.trim().split(/\s{2,}/);
const revision = splitLine[2];
if (revision === '-') {
throw new Error(`No revision available in ${track}/${channel}`);
}
const resources = splitLine[3].split(',').reduce((acc, res) => {
if (res === '-') {
return acc;
}
const [resName, resRev] = res.trim().split(' ');
const revisionNum = resRev.replace(/\D/g, '');
acc.push({ resourceName: resName, resourceRev: revisionNum });
return acc;
}, []);
return { charmRev: revision, resources };
}
}
throw new Error(`No track with name ${track}`);
});
}
release(charm, charmRevision, destinationChannel, resourceInfo) {
return __awaiter(this, void 0, void 0, function* () {
const resourceArgs = [];
resourceInfo.forEach((resource) => {
resourceArgs.push('--resource');
resourceArgs.push(`${resource.resourceName}:${resource.resourceRev}`);
});
const args = [
'release',
charm,
'--revision',
charmRevision,
'--channel',
destinationChannel,
...resourceArgs,
];
yield (0, exec_1.exec)('charmcraft', args, this.execOptions);
});
}
}
exports.Charmcraft = Charmcraft;

Expand Down Expand Up @@ -21942,7 +22011,7 @@ class Tagger {
}
_build(owner, repo, hash, revision, channel, resources, tagPrefix) {
const name = `${tagPrefix ? `${tagPrefix}-` : ''}rev${revision}`;
const message = `${resources} Released to '${channel}' at ${this._get_date_text()}`;
const message = `${resources} Released to '${channel}' at ${this.get_date_text()}`;
return {
owner,
repo,
Expand All @@ -21955,10 +22024,43 @@ class Tagger {
target_commitish: hash,
};
}
_get_date_text() {
get_date_text() {
// 12:00 UTC on 10 Feb 2022
return (0, dayjs_1.default)().utc().format('HH:mm UTC on D MMM YYYY');
}
getReleaseByTag(tagName) {
return __awaiter(this, void 0, void 0, function* () {
const { owner, repo } = github_1.context.repo;
try {
const { data } = yield this.kit.rest.repos.getReleaseByTag({
owner,
repo,
tag: tagName,
});
return data;
}
catch (error) {
throw new Error(`Cannot find release by tag ${tagName}`);
}
});
}
updateRelease(release_id, newReleaseBody) {
return __awaiter(this, void 0, void 0, function* () {
const { owner, repo } = github_1.context.repo;
try {
const { data } = yield this.kit.rest.repos.updateRelease({
owner,
repo,
release_id,
body: newReleaseBody,
});
return data;
}
catch (error) {
throw new Error(`Failed to update release with id ${release_id}`);
}
});
}
}
exports.Tagger = Tagger;

Expand Down
106 changes: 104 additions & 2 deletions dist/check-libraries/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21839,6 +21839,75 @@ class Charmcraft {
return { ok: lines.length <= 0, out, err };
});
}
status(charm) {
return __awaiter(this, void 0, void 0, function* () {
const result = yield (0, exec_1.getExecOutput)('charmcraft', ['status', charm], this.execOptions);
return result.stdout;
});
}
getRevisionInfoFromChannel(charm, track, channel) {
return __awaiter(this, void 0, void 0, function* () {
// For now we have to parse the `charmcraft status` output this will soon be fixed
// when we can get json output from charmcraft.
// Issue tracked here: https://github.com/canonical/charmcraft/issues/183
const acceptedChannels = ['stable', 'candidate', 'beta', 'edge'];
if (!acceptedChannels.includes(channel)) {
throw new Error(`Provided channel ${channel} is not supported. This actions currently only works with one of the following default channels: edge, beta, candidate, stable`);
}
const charmcraftStatus = yield this.status(charm);
const channelLine = {
stable: 0,
candidate: 1,
beta: 2,
edge: 3,
};
const lines = charmcraftStatus.split('\n');
for (let i = 1; i < lines.length; i += 4) {
// find line with track name
if (lines[i].includes(track)) {
i += channelLine[channel];
const targetLine = channel === 'stable'
? lines[i].slice(lines[i].search(/stable/g))
: lines[i];
const splitLine = targetLine.trim().split(/\s{2,}/);
const revision = splitLine[2];
if (revision === '-') {
throw new Error(`No revision available in ${track}/${channel}`);
}
const resources = splitLine[3].split(',').reduce((acc, res) => {
if (res === '-') {
return acc;
}
const [resName, resRev] = res.trim().split(' ');
const revisionNum = resRev.replace(/\D/g, '');
acc.push({ resourceName: resName, resourceRev: revisionNum });
return acc;
}, []);
return { charmRev: revision, resources };
}
}
throw new Error(`No track with name ${track}`);
});
}
release(charm, charmRevision, destinationChannel, resourceInfo) {
return __awaiter(this, void 0, void 0, function* () {
const resourceArgs = [];
resourceInfo.forEach((resource) => {
resourceArgs.push('--resource');
resourceArgs.push(`${resource.resourceName}:${resource.resourceRev}`);
});
const args = [
'release',
charm,
'--revision',
charmRevision,
'--channel',
destinationChannel,
...resourceArgs,
];
yield (0, exec_1.exec)('charmcraft', args, this.execOptions);
});
}
}
exports.Charmcraft = Charmcraft;

Expand Down Expand Up @@ -22077,7 +22146,7 @@ class Tagger {
}
_build(owner, repo, hash, revision, channel, resources, tagPrefix) {
const name = `${tagPrefix ? `${tagPrefix}-` : ''}rev${revision}`;
const message = `${resources} Released to '${channel}' at ${this._get_date_text()}`;
const message = `${resources} Released to '${channel}' at ${this.get_date_text()}`;
return {
owner,
repo,
Expand All @@ -22090,10 +22159,43 @@ class Tagger {
target_commitish: hash,
};
}
_get_date_text() {
get_date_text() {
// 12:00 UTC on 10 Feb 2022
return (0, dayjs_1.default)().utc().format('HH:mm UTC on D MMM YYYY');
}
getReleaseByTag(tagName) {
return __awaiter(this, void 0, void 0, function* () {
const { owner, repo } = github_1.context.repo;
try {
const { data } = yield this.kit.rest.repos.getReleaseByTag({
owner,
repo,
tag: tagName,
});
return data;
}
catch (error) {
throw new Error(`Cannot find release by tag ${tagName}`);
}
});
}
updateRelease(release_id, newReleaseBody) {
return __awaiter(this, void 0, void 0, function* () {
const { owner, repo } = github_1.context.repo;
try {
const { data } = yield this.kit.rest.repos.updateRelease({
owner,
repo,
release_id,
body: newReleaseBody,
});
return data;
}
catch (error) {
throw new Error(`Failed to update release with id ${release_id}`);
}
});
}
}
exports.Tagger = Tagger;

Expand Down
Loading

0 comments on commit b01573c

Please sign in to comment.