Skip to content

Commit

Permalink
Support charms using charmcraft extensions (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
weiiwang01 authored Jun 27, 2024
1 parent 19db2e9 commit e924d25
Show file tree
Hide file tree
Showing 13 changed files with 314 additions and 160 deletions.
55 changes: 35 additions & 20 deletions dist/channel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42750,7 +42750,7 @@ class Charmcraft {
`If you wish to upload the OCI image, set 'upload-image' to 'true'`;
core.warning(msg);
}
const { name: charmName, images } = this.metadata();
const { name: charmName, images } = yield this.metadata();
const flags = [];
yield Promise.all(images
// If an image resource has been overridden in the action input,
Expand All @@ -42771,7 +42771,7 @@ class Charmcraft {
}
fetchFileFlags(overrides) {
return __awaiter(this, void 0, void 0, function* () {
const { name: charmName, files } = this.metadata();
const { name: charmName, files } = yield this.metadata();
// If an image resource has been overridden in the action input,
// we don't want to upload a new version of it either.
const filtered = files.filter(([name]) => !overrides || !Object.keys(overrides).includes(name));
Expand Down Expand Up @@ -42838,27 +42838,42 @@ class Charmcraft {
};
});
}
_read() {
readMetadata() {
if (fs.existsSync('metadata.yaml')) {
return fs.readFileSync('metadata.yaml');
return yaml.load(fs.readFileSync('metadata.yaml', 'utf8'));
}
return fs.readFileSync('charmcraft.yaml');
return yaml.load(fs.readFileSync('charmcraft.yaml', 'utf8'));
}
expandExtensions() {
return __awaiter(this, void 0, void 0, function* () {
const output = yield (0, exec_1.getExecOutput)('charmcraft', ['expand-extensions'], {
silent: true,
});
return output.stdout;
});
}
charmName() {
return this.readMetadata().name;
}
metadata() {
const buffer = this._read();
const metadata = yaml.load(buffer.toString());
const resources = Object.entries(metadata.resources || {});
const files = resources
.filter(([, res]) => res.type === 'file')
.map(([name]) => name);
const images = resources
.filter(([, res]) => res.type === 'oci-image')
.map(([name, res]) => [name, res['upstream-source']]);
return {
images,
files,
name: metadata.name,
};
return __awaiter(this, void 0, void 0, function* () {
let metadata = this.readMetadata();
if (metadata.extensions) {
metadata = yaml.load(yield this.expandExtensions());
}
const resources = Object.entries(metadata.resources || {});
const files = resources
.filter(([, res]) => res.type === 'file')
.map(([name]) => name);
const images = resources
.filter(([, res]) => res.type === 'oci-image')
.map(([name, res]) => [name, res['upstream-source']]);
return {
images,
files,
name: metadata.name,
};
});
}
pack(destructive) {
return __awaiter(this, void 0, void 0, function* () {
Expand Down Expand Up @@ -42891,7 +42906,7 @@ class Charmcraft {
}
hasDriftingLibs() {
return __awaiter(this, void 0, void 0, function* () {
const { name } = this.metadata();
const { name } = yield this.metadata();
const args = ['fetch-lib'];
const result = yield (0, exec_1.getExecOutput)('charmcraft', args, this.execOptions);
const re = new RegExp(`${name}`);
Expand Down
55 changes: 35 additions & 20 deletions dist/check-libraries/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42945,7 +42945,7 @@ class Charmcraft {
`If you wish to upload the OCI image, set 'upload-image' to 'true'`;
core.warning(msg);
}
const { name: charmName, images } = this.metadata();
const { name: charmName, images } = yield this.metadata();
const flags = [];
yield Promise.all(images
// If an image resource has been overridden in the action input,
Expand All @@ -42966,7 +42966,7 @@ class Charmcraft {
}
fetchFileFlags(overrides) {
return __awaiter(this, void 0, void 0, function* () {
const { name: charmName, files } = this.metadata();
const { name: charmName, files } = yield this.metadata();
// If an image resource has been overridden in the action input,
// we don't want to upload a new version of it either.
const filtered = files.filter(([name]) => !overrides || !Object.keys(overrides).includes(name));
Expand Down Expand Up @@ -43033,27 +43033,42 @@ class Charmcraft {
};
});
}
_read() {
readMetadata() {
if (fs.existsSync('metadata.yaml')) {
return fs.readFileSync('metadata.yaml');
return yaml.load(fs.readFileSync('metadata.yaml', 'utf8'));
}
return fs.readFileSync('charmcraft.yaml');
return yaml.load(fs.readFileSync('charmcraft.yaml', 'utf8'));
}
expandExtensions() {
return __awaiter(this, void 0, void 0, function* () {
const output = yield (0, exec_1.getExecOutput)('charmcraft', ['expand-extensions'], {
silent: true,
});
return output.stdout;
});
}
charmName() {
return this.readMetadata().name;
}
metadata() {
const buffer = this._read();
const metadata = yaml.load(buffer.toString());
const resources = Object.entries(metadata.resources || {});
const files = resources
.filter(([, res]) => res.type === 'file')
.map(([name]) => name);
const images = resources
.filter(([, res]) => res.type === 'oci-image')
.map(([name, res]) => [name, res['upstream-source']]);
return {
images,
files,
name: metadata.name,
};
return __awaiter(this, void 0, void 0, function* () {
let metadata = this.readMetadata();
if (metadata.extensions) {
metadata = yaml.load(yield this.expandExtensions());
}
const resources = Object.entries(metadata.resources || {});
const files = resources
.filter(([, res]) => res.type === 'file')
.map(([name]) => name);
const images = resources
.filter(([, res]) => res.type === 'oci-image')
.map(([name, res]) => [name, res['upstream-source']]);
return {
images,
files,
name: metadata.name,
};
});
}
pack(destructive) {
return __awaiter(this, void 0, void 0, function* () {
Expand Down Expand Up @@ -43086,7 +43101,7 @@ class Charmcraft {
}
hasDriftingLibs() {
return __awaiter(this, void 0, void 0, function* () {
const { name } = this.metadata();
const { name } = yield this.metadata();
const args = ['fetch-lib'];
const result = yield (0, exec_1.getExecOutput)('charmcraft', args, this.execOptions);
const re = new RegExp(`${name}`);
Expand Down
57 changes: 36 additions & 21 deletions dist/promote-charm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42529,7 +42529,7 @@ class PromoteCharmAction {
try {
yield this.snap.install('charmcraft', this.charmcraftChannel);
process.chdir(this.charmPath);
const { name: charmName } = this.charmcraft.metadata();
const charmName = this.charmcraft.charmName();
const [originTrack, originChannel] = this.originChannel.split('/');
const basesArray = yield this.charmcraft.getBases(charmName, originTrack);
const revisions = yield this.getRevisions(charmName, originTrack, originChannel, basesArray);
Expand Down Expand Up @@ -42829,7 +42829,7 @@ class Charmcraft {
`If you wish to upload the OCI image, set 'upload-image' to 'true'`;
core.warning(msg);
}
const { name: charmName, images } = this.metadata();
const { name: charmName, images } = yield this.metadata();
const flags = [];
yield Promise.all(images
// If an image resource has been overridden in the action input,
Expand All @@ -42850,7 +42850,7 @@ class Charmcraft {
}
fetchFileFlags(overrides) {
return __awaiter(this, void 0, void 0, function* () {
const { name: charmName, files } = this.metadata();
const { name: charmName, files } = yield this.metadata();
// If an image resource has been overridden in the action input,
// we don't want to upload a new version of it either.
const filtered = files.filter(([name]) => !overrides || !Object.keys(overrides).includes(name));
Expand Down Expand Up @@ -42917,27 +42917,42 @@ class Charmcraft {
};
});
}
_read() {
readMetadata() {
if (fs.existsSync('metadata.yaml')) {
return fs.readFileSync('metadata.yaml');
return yaml.load(fs.readFileSync('metadata.yaml', 'utf8'));
}
return fs.readFileSync('charmcraft.yaml');
return yaml.load(fs.readFileSync('charmcraft.yaml', 'utf8'));
}
expandExtensions() {
return __awaiter(this, void 0, void 0, function* () {
const output = yield (0, exec_1.getExecOutput)('charmcraft', ['expand-extensions'], {
silent: true,
});
return output.stdout;
});
}
charmName() {
return this.readMetadata().name;
}
metadata() {
const buffer = this._read();
const metadata = yaml.load(buffer.toString());
const resources = Object.entries(metadata.resources || {});
const files = resources
.filter(([, res]) => res.type === 'file')
.map(([name]) => name);
const images = resources
.filter(([, res]) => res.type === 'oci-image')
.map(([name, res]) => [name, res['upstream-source']]);
return {
images,
files,
name: metadata.name,
};
return __awaiter(this, void 0, void 0, function* () {
let metadata = this.readMetadata();
if (metadata.extensions) {
metadata = yaml.load(yield this.expandExtensions());
}
const resources = Object.entries(metadata.resources || {});
const files = resources
.filter(([, res]) => res.type === 'file')
.map(([name]) => name);
const images = resources
.filter(([, res]) => res.type === 'oci-image')
.map(([name, res]) => [name, res['upstream-source']]);
return {
images,
files,
name: metadata.name,
};
});
}
pack(destructive) {
return __awaiter(this, void 0, void 0, function* () {
Expand Down Expand Up @@ -42970,7 +42985,7 @@ class Charmcraft {
}
hasDriftingLibs() {
return __awaiter(this, void 0, void 0, function* () {
const { name } = this.metadata();
const { name } = yield this.metadata();
const args = ['fetch-lib'];
const result = yield (0, exec_1.getExecOutput)('charmcraft', args, this.execOptions);
const re = new RegExp(`${name}`);
Expand Down
57 changes: 36 additions & 21 deletions dist/release-charm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42532,7 +42532,7 @@ class ReleaseCharmAction {
try {
yield this.snap.install('charmcraft', this.charmcraftChannel);
process.chdir(this.charmPath);
const { name: charmName } = this.charmcraft.metadata();
const { name: charmName } = yield this.charmcraft.metadata();
const [originTrack, originChannel] = this.originChannel.split('/');
const base = {
name: this.baseName,
Expand Down Expand Up @@ -42841,7 +42841,7 @@ class Charmcraft {
`If you wish to upload the OCI image, set 'upload-image' to 'true'`;
core.warning(msg);
}
const { name: charmName, images } = this.metadata();
const { name: charmName, images } = yield this.metadata();
const flags = [];
yield Promise.all(images
// If an image resource has been overridden in the action input,
Expand All @@ -42862,7 +42862,7 @@ class Charmcraft {
}
fetchFileFlags(overrides) {
return __awaiter(this, void 0, void 0, function* () {
const { name: charmName, files } = this.metadata();
const { name: charmName, files } = yield this.metadata();
// If an image resource has been overridden in the action input,
// we don't want to upload a new version of it either.
const filtered = files.filter(([name]) => !overrides || !Object.keys(overrides).includes(name));
Expand Down Expand Up @@ -42929,27 +42929,42 @@ class Charmcraft {
};
});
}
_read() {
readMetadata() {
if (fs.existsSync('metadata.yaml')) {
return fs.readFileSync('metadata.yaml');
return yaml.load(fs.readFileSync('metadata.yaml', 'utf8'));
}
return fs.readFileSync('charmcraft.yaml');
return yaml.load(fs.readFileSync('charmcraft.yaml', 'utf8'));
}
expandExtensions() {
return __awaiter(this, void 0, void 0, function* () {
const output = yield (0, exec_1.getExecOutput)('charmcraft', ['expand-extensions'], {
silent: true,
});
return output.stdout;
});
}
charmName() {
return this.readMetadata().name;
}
metadata() {
const buffer = this._read();
const metadata = yaml.load(buffer.toString());
const resources = Object.entries(metadata.resources || {});
const files = resources
.filter(([, res]) => res.type === 'file')
.map(([name]) => name);
const images = resources
.filter(([, res]) => res.type === 'oci-image')
.map(([name, res]) => [name, res['upstream-source']]);
return {
images,
files,
name: metadata.name,
};
return __awaiter(this, void 0, void 0, function* () {
let metadata = this.readMetadata();
if (metadata.extensions) {
metadata = yaml.load(yield this.expandExtensions());
}
const resources = Object.entries(metadata.resources || {});
const files = resources
.filter(([, res]) => res.type === 'file')
.map(([name]) => name);
const images = resources
.filter(([, res]) => res.type === 'oci-image')
.map(([name, res]) => [name, res['upstream-source']]);
return {
images,
files,
name: metadata.name,
};
});
}
pack(destructive) {
return __awaiter(this, void 0, void 0, function* () {
Expand Down Expand Up @@ -42982,7 +42997,7 @@ class Charmcraft {
}
hasDriftingLibs() {
return __awaiter(this, void 0, void 0, function* () {
const { name } = this.metadata();
const { name } = yield this.metadata();
const args = ['fetch-lib'];
const result = yield (0, exec_1.getExecOutput)('charmcraft', args, this.execOptions);
const re = new RegExp(`${name}`);
Expand Down
Loading

0 comments on commit e924d25

Please sign in to comment.