Skip to content

Commit e0885b5

Browse files
committed
feat: add option to publish to CI catalog
1 parent cfd90cf commit e0885b5

File tree

7 files changed

+239
-33
lines changed

7 files changed

+239
-33
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: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import resolveConfig from "./resolve-config.js";
1212
import getAssets from "./glob-assets.js";
1313
import { RELEASE_NAME } from "./definitions/constants.js";
1414
import getProjectContext from "./get-project-context.js";
15-
15+
import { execa } from "execa";
1616
const isUrlScheme = (value) => /^(https|http|ftp):\/\//.test(value);
1717

1818
export default async (pluginConfig, context) => {
@@ -22,17 +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, retryStatusCodes } =
25+
const { gitlabToken, gitlabUrl, gitlabApiUrl, assets, milestones, proxy, retryLimit, retryStatusCodes, publishToCatalog } =
2626
resolveConfig(pluginConfig, context);
2727
const assetsList = [];
2828
const { projectPath, projectApiUrl } = getProjectContext(context, gitlabUrl, gitlabApiUrl, repositoryUrl);
2929

3030
const encodedGitTag = encodeURIComponent(gitTag);
3131
const encodedVersion = encodeURIComponent(version);
3232
const apiOptions = {
33-
headers: {
34-
"PRIVATE-TOKEN": gitlabToken,
35-
},
33+
headers: { "PRIVATE-TOKEN": gitlabToken },
3634
hooks: {
3735
beforeError: [
3836
(error) => {
@@ -185,11 +183,7 @@ export default async (pluginConfig, context) => {
185183
debug("POST-ing the following JSON to %s:\n%s", createReleaseEndpoint, JSON.stringify(json, null, 2));
186184

187185
try {
188-
await got.post(createReleaseEndpoint, {
189-
...apiOptions,
190-
...proxy,
191-
json,
192-
});
186+
await got.post(createReleaseEndpoint, { ...apiOptions, ...proxy, json });
193187
} catch (error) {
194188
logger.error("An error occurred while making a request to the GitLab release API:\n%O", error);
195189
throw error;
@@ -199,5 +193,19 @@ export default async (pluginConfig, context) => {
199193

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

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

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 } = {},
@@ -71,6 +72,7 @@ export default (
7172
assignee,
7273
retryLimit: retryLimit ?? DEFAULT_RETRY_LIMIT,
7374
retryStatusCodes: DEFAULT_RETRY_STATUS_CODES,
75+
publishToCatalog: publishToCatalog ?? false,
7476
};
7577
};
7678

0 commit comments

Comments
 (0)