Skip to content

feat: add option to publish to CI catalog #842

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

Merged
merged 1 commit into from
May 16, 2025
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
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ If you need to bypass the proxy for some hosts, configure the `NO_PROXY` environ
| `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` |
| `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. | - |
| `retryLimit` | The maximum number of retries for failing HTTP requests. | `3` |
| `publishToCatalog` | [EXPERIMENTAL] Publishes CI/CD components to the catalog. See [publishToCatalog](#publishToCatalog). | `false` |

#### assets

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

> 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

#### publishToCatalog

**Note**: This is an EXPERIMENTAL option that might change in the future.

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.

The publishing is done via the `glab` CLI, so make sure to [install it before](https://gitlab.com/gitlab-org/cli#installation).

## Compatibility

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.
Expand Down
32 changes: 19 additions & 13 deletions lib/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import resolveConfig from "./resolve-config.js";
import getAssets from "./glob-assets.js";
import { RELEASE_NAME } from "./definitions/constants.js";
import getProjectContext from "./get-project-context.js";

import { execa } from "execa";
const isUrlScheme = (value) => /^(https|http|ftp):\/\//.test(value);

export default async (pluginConfig, context) => {
Expand All @@ -22,19 +22,15 @@ export default async (pluginConfig, context) => {
nextRelease: { gitTag, gitHead, notes, version },
logger,
} = context;
const { gitlabToken, gitlabUrl, gitlabApiUrl, assets, milestones, proxy, retryLimit } = resolveConfig(
pluginConfig,
context
);
const { gitlabToken, gitlabUrl, gitlabApiUrl, assets, milestones, proxy, retryLimit, publishToCatalog } =
resolveConfig(pluginConfig, context);
const assetsList = [];
const { projectPath, projectApiUrl } = getProjectContext(context, gitlabUrl, gitlabApiUrl, repositoryUrl);

const encodedGitTag = encodeURIComponent(gitTag);
const encodedVersion = encodeURIComponent(version);
const apiOptions = {
headers: {
"PRIVATE-TOKEN": gitlabToken,
},
headers: { "PRIVATE-TOKEN": gitlabToken },
hooks: {
beforeError: [
(error) => {
Expand Down Expand Up @@ -187,11 +183,7 @@ export default async (pluginConfig, context) => {
debug("POST-ing the following JSON to %s:\n%s", createReleaseEndpoint, JSON.stringify(json, null, 2));

try {
await got.post(createReleaseEndpoint, {
...apiOptions,
...proxy,
json,
});
await got.post(createReleaseEndpoint, { ...apiOptions, ...proxy, json });
} catch (error) {
logger.error("An error occurred while making a request to the GitLab release API:\n%O", error);
throw error;
Expand All @@ -201,5 +193,19 @@ export default async (pluginConfig, context) => {

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

if (publishToCatalog) {
try {
await execa("glab", ["repo", "publish", "catalog", gitTag], {
cwd,
timeout: 30 * 1000,
env: { GITLAB_TOKEN: gitlabToken },
});
logger.log("Published tag %s to the CI catalog", gitTag);
} catch (error) {
logger.error("An error occurred while publishing tag %s to the CI catalog:\n%O", gitTag, error);
throw error;
}
}

return { name: RELEASE_NAME, url: releaseUrl };
};
2 changes: 2 additions & 0 deletions lib/resolve-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default (
labels,
assignee,
retryLimit,
publishToCatalog,
},
{
envCi: { service } = {},
Expand Down Expand Up @@ -67,6 +68,7 @@ export default (
labels: isNil(labels) ? "semantic-release" : labels === false ? false : labels,
assignee,
retryLimit: retryLimit ?? DEFAULT_RETRY_LIMIT,
publishToCatalog: publishToCatalog ?? false,
};
};

Expand Down
Loading