New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

gitlab-releaser

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gitlab-releaser - npm Package Compare versions

Comparing version 1.0.4 to 2.0.0

2

bin/gitlab-releaser.js

@@ -19,3 +19,3 @@ #!/usr/bin/env node

.option('-s, --schema <schema>', 'the schema type of the JSON input file', schemaTypes.gitlabReleaser)
.option('-t, --tag <tag>', 'the path to the output directory for HTML report files (default: "$CI_COMMIT_TAG")', env.ci.commit.tag)
.option('-t, --tag <tag>', `the tag used to retrieve release data, required if schema type is ${schemaTypes.gitlabReleaser} or if release pulls data from a CHANGELOG (default: "$CI_COMMIT_TAG")`, env.ci.commit.tag)
.parse(process.argv);

@@ -22,0 +22,0 @@ const options = program.opts();

# Changelog
## v2.0.0 (2021-06-06)
### Changed
- BREAKING: Updated command line arguments to only require a tag to be specified if it is necessary to process the command. This includes retrieving the release data if the schema is `gitlab-releaser` or if the file references CHANGELOG data. (#23)
- BREAKING: Updated the output shell script to include the `--tag-name` argument if a tag is specified in the release file or the CLI (previously it was only included if in the release file). If a tag is specified in both places, the CLI argument takes precedence. (#23)
- BREAKING: Updated `release` schema to allow zero milestones. This facilitates the case a milestone is defined in `defaults` in `gitlab-releaser`, but need to override a specific release to have no milestones, which can now be done by specifying an empty array. (#15)
- BREAKING: Deprecated support for Node 10 and 15 since end-of-life. Compatible with all current and LTS releases (`^12.20.0 || ^14.15.0 || >=16.0.0`). (#21)
### Fixed
- Fixed incorrect description for the `--tag`/`-t` CLI argument (#27)
- Updated to latest dependencies
### Miscellaneous
- Updated documentation with an example GitLab CI job template that includes a default release configuration that will only be used if no release file is present. (#26)
- Update `gitlab-releaser` schema to reference `release` schema, rather than repeat it. (#22)
## v1.0.4 (2021-05-12)

@@ -4,0 +23,0 @@

@@ -10,2 +10,4 @@ 'use strict';

const createReleaseCommand = 'release-cli create';
const getErrorLogEntry = (message) => {

@@ -15,9 +17,37 @@ return { message, level: logger.levels.error, exitOnError: true, errorCode: 1 };

const verifyTagExists = (tag, message) => {
if (!tag) {
logger.log(getErrorLogEntry(message));
}
};
const processTag = (data, tag) => {
// Ensure tag_name is included in release data, if available. If tag
// specified via CLI, it overrides tag_name from file.
if (tag) {
if (data.tag_name && data.tag_name !== tag) {
// Log warning since overriding data from release file
logger.log({
message: `Overwriting tag_name "${data.tag_name}" from release with tag "${tag}" from CLI`,
level: logger.levels.warn
});
}
// eslint-disable-next-line camelcase -- name specified in release-cli
data.tag_name = tag;
}
return data;
};
const processReleaseData = (data, tag) => {
const createReleaseCommand = 'release-cli create';
let processedData = data;
let processedData;
if (usesChangelog(data)) {
verifyTagExists(tag, 'Tag must be specified to process CHANGELOG data');
processedData = processChangelogData(data, tag);
}
const args = cli.getArgsString(processedData);
else {
processedData = data;
}
const args = cli.getArgsString(processTag(processedData, tag));
return `${createReleaseCommand}${args}`;

@@ -31,8 +61,2 @@ };

const validateTagExists = (tag) => {
if (!tag) {
logger.log(getErrorLogEntry('Tag must be specified'));
}
};
const validateSchemaType = (type) => {

@@ -45,3 +69,2 @@ if (!isValidSchemaType(type)) {

const getReleaseCliCommand = (directory, releaseFileName, type, tag) => {
validateTagExists(tag);
validateSchemaType(type);

@@ -57,2 +80,3 @@

}
verifyTagExists(tag, 'Tag must be specified if schema type is gitlab-releaser');
release = getReleaseFromGitLabReleaser(data, tag);

@@ -59,0 +83,0 @@ }

@@ -7,4 +7,2 @@ 'use strict';

const schemaDirectory = 'schemas';
const schemaTypes = {

@@ -15,2 +13,9 @@ release: 'release',

const schemaDirectory = 'schemas';
const gitlabReleaserSchemaFile = 'gitlab-releaser.schema.json';
const releaseSchemaFile = 'release.schema.json';
const schemaIdBase = 'https://gitlab.com/gitlab-ci-utils/gitlab-releaser/-/raw/master/schemas';
const gitlabReleaserSchemaId = `${schemaIdBase}/${gitlabReleaserSchemaFile}`;
const releaseSchemaId = `${schemaIdBase}/${releaseSchemaFile}`;
const isValidSchemaType = (value) => {

@@ -20,5 +25,5 @@ return Object.values(schemaTypes).includes(value);

const validateDataAgainstSchema = (schemaFile, data) => {
const schema = JSON.parse(fs.readFileSync(path.join(__dirname, '..', schemaDirectory, schemaFile)));
const validate = new Ajv().compile(schema);
const validateDataAgainstSchema = (schemaFiles, schemaId, data) => {
const schemas = schemaFiles.map(schemaFile => JSON.parse(fs.readFileSync(path.join(__dirname, '..', schemaDirectory, schemaFile))));
const validate = new Ajv({ schemas }).getSchema(schemaId);
return validate(data);

@@ -28,9 +33,7 @@ };

const isValidGitLabReleaser = (data) => {
const gitlabReleaserSchemaFile = 'gitlab-releaser.schema.json';
return validateDataAgainstSchema(gitlabReleaserSchemaFile, data);
return validateDataAgainstSchema([gitlabReleaserSchemaFile, releaseSchemaFile], gitlabReleaserSchemaId, data);
};
const isValidRelease = (data) => {
const releaseSchemaFile = 'release.schema.json';
return validateDataAgainstSchema(releaseSchemaFile, data);
return validateDataAgainstSchema([releaseSchemaFile], releaseSchemaId, data);
};

@@ -37,0 +40,0 @@

{
"name": "gitlab-releaser",
"version": "1.0.4",
"version": "2.0.0",
"description": "Generate arguments for GitLab release-cli command",

@@ -24,6 +24,6 @@ "bin": "./bin/gitlab-releaser.js",

],
"author": "Aaron Goldenthal",
"author": "Aaron Goldenthal <npm@aarongoldenthal.com>",
"license": "MIT",
"engines": {
"node": "^10.13.0 || ^12.13.0 || >=14.0.0"
"node": "^12.20.0 || ^14.15.0 || >=16.0.0"
},

@@ -41,16 +41,16 @@ "files": [

"devDependencies": {
"@aarongoldenthal/eslint-config-standard": "^7.0.0",
"bin-tester": "^1.3.1",
"eslint": "^7.23.0",
"jest": "^26.6.3",
"jest-junit": "^12.0.0",
"@aarongoldenthal/eslint-config-standard": "^8.0.0",
"bin-tester": "^2.0.0",
"eslint": "^7.28.0",
"jest": "^27.0.4",
"jest-junit": "^12.1.0",
"markdownlint-cli": "^0.27.1"
},
"dependencies": {
"ajv": "^8.3.0",
"ci-logger": "^3.0.5",
"ajv": "^8.6.0",
"ci-logger": "^4.0.0",
"commander": "^7.2.0",
"gitlab-ci-env": "^3.7.0",
"releaselog": "^1.0.9"
"releaselog": "^2.0.0"
}
}

@@ -74,3 +74,3 @@ # GitLab Releaser

A tag must be specified to pull the appropriate release information. For example, tag `1.0.0` would result in the following equivalent `release.json` file.
A tag must be specified via the CLI to pull the appropriate release information. For example, tag `1.0.0` would result in the following equivalent `release.json` file.

@@ -109,3 +109,3 @@ ```json

The [`releaselog`](https://www.npmjs.com/package/releaselog) module is used to pull this data and has details on CHANGELOG formatting requirements. The data is retrieved by the tag specified via the CLI, if specified, otherwise the value of `CI_COMMIT_TAG` is used.
The [`releaselog`](https://www.npmjs.com/package/releaselog) module is used to pull this data and has details on CHANGELOG formatting requirements. The data is retrieved by the tag specified via the CLI, if specified, otherwise the value of `CI_COMMIT_TAG` is used. Either a tag or the default value must be specified via the CLI if the release used CHANGELOG data.

@@ -135,2 +135,4 @@ If either `name` or `description` specifies pulling data from the CHANGELOG, but that data cannot be found in the CHANGELOG, the job will report the error and fail.

### Command Line Usage
The `gitlab-releaser` command line interface is run as detailed below:

@@ -144,6 +146,11 @@

-s, --schema <schema> the schema type of the JSON input file (default: "gitlab-releaser")
-t, --tag <tag> the path to the output directory for HTML report files (default: "$CI_COMMIT_TAG")
-t, --tag <tag> the tag used to retrieve release data, required if schema type is gitlab-releaser or if
release pulls data from a CHANGELOG (default: "$CI_COMMIT_TAG")
-h, --help display help for command
```
If a tag or its default value are specified it will override any `tag_name` value found in the release file (of either type).
### GitLab CI Usage
The following is an example `.gitlab-ci.yml` file illustrating preparing and creating a release on every tag pipeline.

@@ -172,3 +179,3 @@

stage: release
dependencies:
needs:
- prepare_release

@@ -181,4 +188,6 @@ script:

The `prepare_release` job runs on a Node.js image and installs and runs `gitlab-releaser` to generate the shell script to prepare the release, saved as `.gitlab/release.sh`. For the example `release.json` file above, or the `gitlab-releaser.json` for tag `1.0.0`, the following shell script will be generated:
The process is split into two jobs to avoid having to create a container image that can run this Node.js application to prepare the release and has GitLab's release-cli application to create the release.
The `prepare_release` job uses a Node.js container image and installs and runs `gitlab-releaser` to generate the shell script to prepare the release, saved as `.gitlab/release.sh`. For the example `release.json` file above, or the `gitlab-releaser.json` for tag `1.0.0`, the following shell script will be generated:
```sh

@@ -189,2 +198,44 @@ #!/bin/sh

The `create_release` job then runs the script to create the release. Note this job requires the `registry.gitlab.com/gitlab-org/release-cli` image, which contains the `release-cli` executable.
The `create_release` job then runs the script to create the release using GitLab's release-cli container image (`registry.gitlab.com/gitlab-org/release-cli`), which contains the `release-cli` executable.
### GitLab CI Usage Without Release Files
The example below shows how to setup a GitLab `prepare_release` job template with a default release configuration defined in CI job (in the environment variable `$RELEASE`, which contains the minified configuration from a `gitlab-releaser.json` file), which will only be used if the project does not have a release file of either type (`release.json` or `gitlab-releaser.json`).
```yaml
# gitlab-releaser.gitlab-ci.yml
prepare_release:
image: node:lts-alpine
stage: pre-release
variables:
# Set default to create a release that pulls the name and description from
# the project CHANGELOG. The "$$$$CHANGELOG" syntax is needed to escape
# the "$" to avoid GitLab variable expansion and end up with "$$CHANGELOG".
RELEASE: '{"defaults":{"name":"$$$$CHANGELOG","description":"$$$$CHANGELOG"}}'
before_script:
- npm install -g gitlab-releaser
# If neither release file exists, create a file with the release from variable.
- |
if [ ! -f .gitlab/release.json ] && [ ! -f .gitlab/gitlab-releaser.json ]; then
mkdir -p .gitlab && echo $RELEASE > .gitlab/gitlab-releaser.json
fi
script:
- gitlab-releaser
rules:
- if: $CI_COMMIT_TAG
artifacts:
paths:
- '.gitlab/release.sh'
```
The default release configuration can also be overridden by including this template, and simply overriding the `$RELEASE` variable with the minified configuration from a `gitlab-releaser.json` file.
```yaml
include:
# Include from the appropriate location
- local: 'gitlab-releaser.gitlab-ci.yml'
prepare_release:
variables:
RELEASE: '{"defaults":{"name":"${CI_COMMIT_TAG}","description":"$$$$CHANGELOG"}}'
```

@@ -24,85 +24,5 @@ {

"release": {
"type": "object",
"properties": {
"name": {
"description": "The release name",
"type": "string"
},
"description": {
"description": "The description of the release (i.e. release notes), you can use Markdown",
"type": "string"
},
"tag_name": {
"description": "The tag the release will be created from (defaults to $CI_COMMIT_TAG)",
"type": "string"
},
"ref": {
"description": "If tag_name doesn’t exist, the release will be created from ref; it can be a commit SHA, another tag name, or a branch name (defaults to $CI_COMMIT_SHA)",
"type": "string"
},
"assets": {
"description": "Assets associated with a release",
"type": "object",
"properties": {
"links": {
"description": "List of asset links associated with a release",
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"description": "The name of the link",
"type": "string"
},
"url": {
"description": "The URL of the link",
"type": "string"
},
"type": {
"description": "The type of the link: other (default), runbook, image, package",
"enum": [
"other",
"runbook",
"image",
"package"
]
},
"filepath": {
"description": "Optional path for a Direct Asset link",
"type": "string"
}
},
"additionalProperties": false,
"required": [
"name",
"url"
]
},
"minItems": 1,
"maxItems": 100,
"uniqueItems": true
}
},
"additionalProperties": false,
"required": [
"links"
]
},
"milestones": {
"description": "List of the titles of each milestone the release is associated with (each milestone needs to exist)",
"type": "array",
"items": {
"type": "string"
},
"minItems": 1,
"uniqueItems": true
},
"released_at": {
"description": "The date when the release will be/was ready; defaults to the current time; expected in ISO 8601 format (2019-03-15T08:00:00Z)",
"type": "string"
}
},
"additionalProperties": false
"$ref": "release.schema.json#"
}
}
}

@@ -78,3 +78,3 @@ {

},
"minItems": 1,
"minItems": 0,
"uniqueItems": true

@@ -81,0 +81,0 @@ },

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc