Skip to content

Merge beta to master #854

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

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
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. It depends on a GitLab feature flag that, as of May 2025, is only enabled for a subset of projects on GitLab.com. Follow the [upstream issue](https://gitlab.com/gitlab-org/gitlab/-/issues/463253) for progress.

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
4 changes: 4 additions & 0 deletions lib/definitions/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,8 @@ Please make sure the GitLab user associated with the token has the [permission t

Please make sure to create a [GitLab personal access token](https://docs.gitlab.com/ce/user/profile/personal_access_tokens.html) and to set it in the \`GL_TOKEN\` or \`GITLAB_TOKEN\` environment variable on your CI environment. The token must allow to push to the repository ${repositoryUrl}.`,
}),
EGLABNOTINSTALLED: () => ({
message: 'GitLab CLI not installed.',
details: 'The [GitLab CLI needs to be installed](https://gitlab.com/gitlab-org/cli#installation) so that the project\'s CI components can be published.',
}),
};
5 changes: 5 additions & 0 deletions lib/glab.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { execa } from "execa";

export default async (args, options) => {
return execa("glab", args, options);
};
39 changes: 28 additions & 11 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 glab from "./glab.js";
const isUrlScheme = (value) => /^(https|http|ftp):\/\//.test(value);

export default async (pluginConfig, context) => {
Expand All @@ -22,17 +22,24 @@ export default async (pluginConfig, context) => {
nextRelease: { gitTag, gitHead, notes, version },
logger,
} = context;
const { gitlabToken, gitlabUrl, gitlabApiUrl, assets, milestones, proxy, retryLimit, retryStatusCodes } =
resolveConfig(pluginConfig, context);
const {
gitlabToken,
gitlabUrl,
gitlabApiUrl,
assets,
milestones,
proxy,
retryLimit,
retryStatusCodes,
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 @@ -185,11 +192,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 @@ -199,5 +202,19 @@ export default async (pluginConfig, context) => {

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

if (publishToCatalog) {
try {
await 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 @@ -71,6 +72,7 @@ export default (
assignee,
retryLimit: retryLimit ?? DEFAULT_RETRY_LIMIT,
retryStatusCodes: DEFAULT_RETRY_STATUS_CODES,
publishToCatalog: publishToCatalog ?? false,
};
};

Expand Down
18 changes: 17 additions & 1 deletion lib/verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import AggregateError from "aggregate-error";
import resolveConfig from "./resolve-config.js";
import getProjectContext from "./get-project-context.js";
import getError from "./get-error.js";
import glab from "./glab.js";

const isNonEmptyString = (value) => isString(value) && value.trim();
const isStringOrStringArray = (value) =>
Expand All @@ -30,7 +31,10 @@ export default async (pluginConfig, context) => {
options: { repositoryUrl },
logger,
} = context;
const { gitlabToken, gitlabUrl, gitlabApiUrl, proxy, ...options } = resolveConfig(pluginConfig, context);
const { gitlabToken, gitlabUrl, gitlabApiUrl, proxy, publishToCatalog, ...options } = resolveConfig(
pluginConfig,
context
);
const { projectPath, projectApiUrl } = getProjectContext(context, gitlabUrl, gitlabApiUrl, repositoryUrl);

debug("apiUrl: %o", gitlabApiUrl);
Expand Down Expand Up @@ -89,6 +93,18 @@ export default async (pluginConfig, context) => {
}
}

if (publishToCatalog === true) {
try {
logger.log("Verifying that the GitLab CLI is installed");
await glab(["version"], {
timeout: 5 * 1000,
});
} catch (error) {
logger.error("The GitLab CLI is required but failed to run:\n%O", error);
errors.push(getError("EGLABNOTINSTALLED"));
}
}

if (errors.length > 0) {
throw new AggregateError(errors);
}
Expand Down
Loading