diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index aae0473ef0a51ca2e8327c982ce320a527b273c8..7abafd5a016ab5e348dfa8a434f69abb4c2a7f59 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,8 +1,7 @@ include: - component: "${CI_SERVER_HOST}/${CI_PROJECT_PATH}/semantic-release@${CI_COMMIT_SHA}" inputs: - stage: test - image: node:lts + stage: deploy semantic-release: - extends: .semantic-release \ No newline at end of file + extends: .semantic-release diff --git a/README.md b/README.md index 0fd24dbbc400274e5d9da79f34efeaba6918f4dd..f5090a81aa19f467f4b385cea01f8f05776bde45 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,9 @@ ## Overview -The `semantic-release` component automates the entire packge release workflow, including determining the next version number, generating release notes, and publishing the package. It strictly follows the [Semantic Versioning] specification and communicates the impact of changes to consumers. +The `semantic-release` component automates the entire package release workflow, including determining the next version number, generating release notes, and publishing the package. -[Semantic Versioning]: https://semver.org +It strictly follows the [Semantic Versioning] specification and communicates the impact of changes to consumers. ## Getting Started @@ -20,11 +20,6 @@ semantic-release: extends: .semantic-release ``` -## Purpose - -> [semantic-release][semantic-release] automates the entire package release workflow, including determining the next version number, generating the release notes, and publishing the package. - - ## Usage ### Configuration @@ -35,30 +30,22 @@ to deploy; `semantic-release` has many open-source [plugins][plugins] that imple `npm install --package-lock-only` will need to be ran locally to generate the `package-lock.json` file for the installed tools. -### Recipes +### Cache -#### NPM +The cache is setup to invalidate when the `package-lock.json` changes. -When using the `@semantic-release/npm` plugin, publishing to GitLab Package Registry can be configured with the NPM -configuration: +## Authentication -```yaml -semantic-release: - extends: .semantic-release - variables: - NPM_TOKEN: "${CI_JOB_TOKEN}" - before_script: - - npm config set -- "@${CI_PROJECT_ROOT_NAMESPACE}:registry" - "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/npm/" - - npm config set -- "${CI_API_V4_URL#https?}/packages/npm/:_authToken" '\${NPM_JOB_TOKEN}' -``` +By default, the component sets up the NPM configuration to use the `NPM_TOKEN` environment variable. This defaults to `${CI_JOB_TOKEN}`. +The `NPM_TOKEN` can be customised in cases where the `CI_JOB_TOKEN` does not have the correct permissions. + +[Semantic Versioning]: https://semver.org [semantic-release]: https://github.com/semantic-release/semantic-release [plugins]: https://github.com/semantic-release -[configuration]: - https://github.com/semantic-release/semantic-release/blob/master/docs/usage/configuration.md#configuration +[configuration]: https://github.com/semantic-release/semantic-release/blob/master/docs/usage/configuration.md#configuration [conventional-commits]: https://www.conventionalcommits.org/ [semantic-versioning]: http://semver.org/ [oci]: oci.md [releaserc]: ../.releaserc.yaml -[image]: https://docs.gitlab.com/ee/ci/yaml/#image \ No newline at end of file +[image]: https://docs.gitlab.com/ee/ci/yaml/#image diff --git a/templates/semantic-release.yml b/templates/semantic-release.yml index 90d8dcbacbbd87ff8acb89e817288d0fd7d4f8a6..53f93bb417d8bf686aced230984e624cdcec7d6a 100644 --- a/templates/semantic-release.yml +++ b/templates/semantic-release.yml @@ -2,29 +2,44 @@ spec: inputs: stage: default: .post - image: + description: "The stage that the `.sematic-release` template will run under." + image: + default: "node" + description: "Open container image to use for execution of the `.semantic-release` template." + tag: + default: "lts" + description: "Open container image tag to use for execution of the `.semantic-release` template." --- - .semantic-release-fragment: authentication: - npm config set -- "@${CI_PROJECT_ROOT_NAMESPACE}:registry" "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/npm/" - npm config set -- "${CI_API_V4_URL#https?}/packages/npm/:_authToken" '\${NPM_JOB_TOKEN}' - + config: + - npm config --location project set cache "${CI_PROJECT_DIR}/.cache/npm" + install: + - npm ci --prefer-offline + run: + - npx semantic-release .semantic-release: stage: $[[inputs.stage]] - image: $[[inputs.image]] - cache: - key: node - paths: - - node_modules - - .cache/npm + image: "$[[inputs.image]]:$[[inputs.tag]]" variables: - GIT_STRATEGY: clone + NPM_TOKEN: "${CI_JOB_TOKEN}" + cache: + - key: + prefix: "package-lock.json+node_modules" + files: + - "package-lock.json" + paths: + - node_modules + - key: "${CI_PROJECT_ID}-cache-npm" + paths: + - .cache/npm before_script: - - npm config --location project set cache "${CI_PROJECT_DIR}/.cache/npm" - - npm ci --prefer-offline - !reference [.semantic-release-fragment, authentication] + - !reference [.semantic-release-fragment, config] + - !reference [.semantic-release-fragment, install] script: - - npx semantic-release \ No newline at end of file + - !reference [.semantic-release-fragment, run]