Skip to content

Commit 197c94a

Browse files
committed
feat: add option to publish to CI catalog
1 parent dcd0ab5 commit 197c94a

File tree

4 files changed

+26
-12
lines changed

4 files changed

+26
-12
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ If you need to bypass the proxy for some hosts, configure the `NO_PROXY` environ
9696
| `labels` | The [labels](https://docs.gitlab.com/ee/user/project/labels.html#labels) to add to the issue created when a release fails. Set to `false` to not add any label. Labels should be comma-separated as described in the [official docs](https://docs.gitlab.com/ee/api/issues.html#new-issue), e.g. `"semantic-release,bot"`. | `semantic-release` |
9797
| `assignee` | The [assignee](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#assignee) to add to the issue created when a release fails. | - |
9898
| `retryLimit` | The maximum number of retries for failing HTTP requests. | `3` |
99+
| `publishToCatalog` | [EXPERIMENTAL] Publishes CI/CD components to the catalog. See [publishToCatalog](#publishToCatalog). | `false` |
99100

100101
#### assets
101102

@@ -211,6 +212,14 @@ The fail comment condition is generated with [Lodash template](https://lodash.co
211212

212213
> check the [GitLab API Issue object](https://docs.gitlab.com/ee/api/issues.html#single-issue) for properties which can be used for the filter
213214
215+
#### publishToCatalog
216+
217+
**Note**: This is an EXPERIMENTAL option that might change in the future.
218+
219+
Use this option to [publish CI/CD components to the catalog](https://gitlab.com/gitlab-org/cli/-/blob/main/docs/source/repo/publish/catalog.md) as part of the release process.
220+
221+
The publishing is done via the `glab` CLI, so make sure to [install it before](https://gitlab.com/gitlab-org/cli#installation).
222+
214223
## Compatibility
215224

216225
The latest version of this plugin is compatible with all currently-supported versions of GitLab, [which is the current major version and previous two major versions](https://about.gitlab.com/support/statement-of-support.html#version-support). This plugin is not guaranteed to work with unsupported versions of GitLab.

lib/publish.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,15 @@ export default async (pluginConfig, context) => {
2222
nextRelease: { gitTag, gitHead, notes, version },
2323
logger,
2424
} = context;
25-
const { gitlabToken, gitlabUrl, gitlabApiUrl, assets, milestones, proxy, retryLimit } = resolveConfig(
26-
pluginConfig,
27-
context
28-
);
25+
const { gitlabToken, gitlabUrl, gitlabApiUrl, assets, milestones, proxy, retryLimit, publishToCatalog } =
26+
resolveConfig(pluginConfig, context);
2927
const assetsList = [];
3028
const { projectPath, projectApiUrl } = getProjectContext(context, gitlabUrl, gitlabApiUrl, repositoryUrl);
3129

3230
const encodedGitTag = encodeURIComponent(gitTag);
3331
const encodedVersion = encodeURIComponent(version);
3432
const apiOptions = {
35-
headers: {
36-
"PRIVATE-TOKEN": gitlabToken,
37-
},
33+
headers: { "PRIVATE-TOKEN": gitlabToken },
3834
hooks: {
3935
beforeError: [
4036
(error) => {
@@ -187,11 +183,7 @@ export default async (pluginConfig, context) => {
187183
debug("POST-ing the following JSON to %s:\n%s", createReleaseEndpoint, JSON.stringify(json, null, 2));
188184

189185
try {
190-
await got.post(createReleaseEndpoint, {
191-
...apiOptions,
192-
...proxy,
193-
json,
194-
});
186+
await got.post(createReleaseEndpoint, { ...apiOptions, ...proxy, json });
195187
} catch (error) {
196188
logger.error("An error occurred while making a request to the GitLab release API:\n%O", error);
197189
throw error;
@@ -201,5 +193,15 @@ export default async (pluginConfig, context) => {
201193

202194
const releaseUrl = urlJoin(gitlabUrl, projectPath, `/-/releases/${encodedGitTag}`);
203195

196+
if (publishToCatalog) {
197+
try {
198+
await execa("glab", ["repo", "publish", "catalog", gitTag], { cwd, timeout: 30 * 1000 });
199+
logger.log("Published tag %s to the CI catalog", gitTag);
200+
} catch (error) {
201+
logger.error("An error occurred while publishing tag %s to the CI catalog:\n%O", gitTag, error);
202+
throw error;
203+
}
204+
}
205+
204206
return { name: RELEASE_NAME, url: releaseUrl };
205207
};

lib/resolve-config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export default (
1616
labels,
1717
assignee,
1818
retryLimit,
19+
publishToCatalog,
1920
},
2021
{
2122
envCi: { service } = {},
@@ -67,6 +68,7 @@ export default (
6768
labels: isNil(labels) ? "semantic-release" : labels === false ? false : labels,
6869
assignee,
6970
retryLimit: retryLimit ?? DEFAULT_RETRY_LIMIT,
71+
publishToCatalog: publishToCatalog ?? false,
7072
};
7173
};
7274

test/resolve-config.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const defaultOptions = {
1818
assignee: undefined,
1919
proxy: {},
2020
retryLimit: 3,
21+
publishToCatalog: false,
2122
};
2223

2324
test("Returns user config", (t) => {

0 commit comments

Comments
 (0)