From 7aa3e7f93cdaede0735413499e73a4e0900d0712 Mon Sep 17 00:00:00 2001 From: Matt Clarkson Date: Wed, 11 Sep 2024 11:35:44 +0100 Subject: [PATCH 01/15] chore: run `prettier` on YAML files --- .gitlab-ci.yml | 2 +- templates/semantic-release.yml | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index aae0473..5a6228a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -5,4 +5,4 @@ include: image: node:lts semantic-release: - extends: .semantic-release \ No newline at end of file + extends: .semantic-release diff --git a/templates/semantic-release.yml b/templates/semantic-release.yml index 90d8dcb..b4ef4bc 100644 --- a/templates/semantic-release.yml +++ b/templates/semantic-release.yml @@ -2,16 +2,14 @@ spec: inputs: stage: default: .post - image: + image: --- - .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}' - .semantic-release: stage: $[[inputs.stage]] image: $[[inputs.image]] @@ -27,4 +25,4 @@ spec: - npm ci --prefer-offline - !reference [.semantic-release-fragment, authentication] script: - - npx semantic-release \ No newline at end of file + - npx semantic-release -- GitLab From 1d95b3250279ea14c15bb0846e3196cbbf8301e5 Mon Sep 17 00:00:00 2001 From: Matt Clarkson Date: Wed, 11 Sep 2024 11:28:17 +0100 Subject: [PATCH 02/15] fix: use `node:lts` as default image --- .gitlab-ci.yml | 1 - README.md | 6 ++---- templates/semantic-release.yml | 2 ++ 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 5a6228a..d88eb21 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -2,7 +2,6 @@ include: - component: "${CI_SERVER_HOST}/${CI_PROJECT_PATH}/semantic-release@${CI_COMMIT_SHA}" inputs: stage: test - image: node:lts semantic-release: extends: .semantic-release diff --git a/README.md b/README.md index 0fd24db..cf42f0b 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,6 @@ semantic-release: > [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 @@ -55,10 +54,9 @@ semantic-release: [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 b4ef4bc..48847b2 100644 --- a/templates/semantic-release.yml +++ b/templates/semantic-release.yml @@ -3,6 +3,8 @@ spec: stage: default: .post image: + default: "node:lts" + description: "Open container image to use for execution of the `.semantic-release` template." --- .semantic-release-fragment: authentication: -- GitLab From 87b8a2e4a8ed799d556eb848ec19558758126da6 Mon Sep 17 00:00:00 2001 From: Matt Clarkson Date: Wed, 11 Sep 2024 13:08:26 +0100 Subject: [PATCH 03/15] docs: add description for `stage` input --- templates/semantic-release.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/templates/semantic-release.yml b/templates/semantic-release.yml index 48847b2..7bbc6dd 100644 --- a/templates/semantic-release.yml +++ b/templates/semantic-release.yml @@ -2,6 +2,7 @@ spec: inputs: stage: default: .post + description: "The stage that the `.sematic-release` template will run under." image: default: "node:lts" description: "Open container image to use for execution of the `.semantic-release` template." -- GitLab From ed081a7ae4693f889d30c0695e94eafb3b750376 Mon Sep 17 00:00:00 2001 From: Matt Clarkson Date: Wed, 11 Sep 2024 11:29:35 +0100 Subject: [PATCH 04/15] ci: use `deploy` stage rather than `test` _Technically_, we are dogfooding the template and testing it. However, the result of the job on protected branches is that it deploys the component. --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d88eb21..7abafd5 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,7 +1,7 @@ include: - component: "${CI_SERVER_HOST}/${CI_PROJECT_PATH}/semantic-release@${CI_COMMIT_SHA}" inputs: - stage: test + stage: deploy semantic-release: extends: .semantic-release -- GitLab From 03bb8a4449ab07bdcfe9360bda07188d6361c13b Mon Sep 17 00:00:00 2001 From: Matt Clarkson Date: Wed, 11 Sep 2024 11:31:43 +0100 Subject: [PATCH 05/15] fix: provide unique cache key We should cache _per-project_ and use a unique key. Using a simple key such as `node`: - The cache will be shared across _all_ projects using the component - The cache will just slowly grow - It would be possible to use modules install by other projects - Conflict with any other cache specified as `node` --- templates/semantic-release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/semantic-release.yml b/templates/semantic-release.yml index 7bbc6dd..2af3afa 100644 --- a/templates/semantic-release.yml +++ b/templates/semantic-release.yml @@ -17,7 +17,7 @@ spec: stage: $[[inputs.stage]] image: $[[inputs.image]] cache: - key: node + key: "${CI_PROJECT_ID}-ci-component-semantic-release" paths: - node_modules - .cache/npm -- GitLab From 13e4e127185207b2241afeaed4a9e907fceb2fa6 Mon Sep 17 00:00:00 2001 From: Matt Clarkson Date: Wed, 11 Sep 2024 11:32:31 +0100 Subject: [PATCH 06/15] feat: provide more fragments for inclusion --- templates/semantic-release.yml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/templates/semantic-release.yml b/templates/semantic-release.yml index 2af3afa..fc63f9a 100644 --- a/templates/semantic-release.yml +++ b/templates/semantic-release.yml @@ -12,6 +12,12 @@ spec: - 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]] @@ -24,8 +30,8 @@ spec: variables: GIT_STRATEGY: clone 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 + - !reference [.semantic-release-fragment, run] -- GitLab From 86c54a6272a073734bf1dc3e40c7b95ffdd46b7d Mon Sep 17 00:00:00 2001 From: Matt Clarkson Date: Wed, 11 Sep 2024 11:34:24 +0100 Subject: [PATCH 07/15] fix: remove `clone` strategy It should be entirely up to the user to decide the strategy. The default of `fetch` is significantly faster for large projects. A default of `clone` will be a regression for those projects. The only time a full clone is needed is if one has deleted a tag and the remote CI has cached that tag in the fetch. This is easy to fix by switching over the CI settings to clone for a single run or adding a `GIT_STRATEGY` CI variable for a short period to clean out the cache. --- templates/semantic-release.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/templates/semantic-release.yml b/templates/semantic-release.yml index fc63f9a..10d35b2 100644 --- a/templates/semantic-release.yml +++ b/templates/semantic-release.yml @@ -27,8 +27,6 @@ spec: paths: - node_modules - .cache/npm - variables: - GIT_STRATEGY: clone before_script: - !reference [.semantic-release-fragment, authentication] - !reference [.semantic-release-fragment, config] -- GitLab From 19a8c26b4c3ec10df5933432e90cbed56820e282 Mon Sep 17 00:00:00 2001 From: Matt Clarkson Date: Wed, 11 Sep 2024 11:40:59 +0100 Subject: [PATCH 08/15] fix: add `NPM_TOKEN` default of `${CI_JOB_TOKEN}` This is recommended upstream to use the scoped `CI_JOB_TOKEN`. However, we must allow the user to override `NPM_TOKEN` because there are times where the `CI_JOB_TOKEN` does not have the correct permissions. --- templates/semantic-release.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/templates/semantic-release.yml b/templates/semantic-release.yml index 10d35b2..99e2849 100644 --- a/templates/semantic-release.yml +++ b/templates/semantic-release.yml @@ -22,6 +22,8 @@ spec: .semantic-release: stage: $[[inputs.stage]] image: $[[inputs.image]] + variables: + NPM_TOKEN: "${CI_JOB_TOKEN}" cache: key: "${CI_PROJECT_ID}-ci-component-semantic-release" paths: -- GitLab From 5f3f221c7993e71a29bf13db8a0b9a3bb14e4f8a Mon Sep 17 00:00:00 2001 From: Matt Clarkson Date: Wed, 11 Sep 2024 11:47:36 +0100 Subject: [PATCH 09/15] feat: use `package-lock.json` as cache invalidator --- templates/semantic-release.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/templates/semantic-release.yml b/templates/semantic-release.yml index 99e2849..611b326 100644 --- a/templates/semantic-release.yml +++ b/templates/semantic-release.yml @@ -25,7 +25,10 @@ spec: variables: NPM_TOKEN: "${CI_JOB_TOKEN}" cache: - key: "${CI_PROJECT_ID}-ci-component-semantic-release" + key: + prefix: "${CI_PROJECT_ID}-ci-component-semantic-release" + files: + - "package-lock.json" paths: - node_modules - .cache/npm -- GitLab From e0eaf186e5601e1842a78c7f4bf294ca2db0d3ae Mon Sep 17 00:00:00 2001 From: Matt Clarkson Date: Wed, 11 Sep 2024 11:50:17 +0100 Subject: [PATCH 10/15] feat: remove cache project ID prefix The cache is hashed on the `package-lock.json`. It is safe to share the cache across the whole instance as if the hash matches, we are guaranteed to have installed the same modules. --- templates/semantic-release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/semantic-release.yml b/templates/semantic-release.yml index 611b326..fc549fa 100644 --- a/templates/semantic-release.yml +++ b/templates/semantic-release.yml @@ -26,7 +26,7 @@ spec: NPM_TOKEN: "${CI_JOB_TOKEN}" cache: key: - prefix: "${CI_PROJECT_ID}-ci-component-semantic-release" + prefix: "ci-component-semantic-release" files: - "package-lock.json" paths: -- GitLab From 70501c2adab5933dc82b25d7dc71471eab62374f Mon Sep 17 00:00:00 2001 From: Matt Clarkson Date: Wed, 11 Sep 2024 11:59:47 +0100 Subject: [PATCH 11/15] feat: split up cache Invalidate `node_modules` when the lockfile changes. Keep the `npm` cache around separately to speed up installs. --- templates/semantic-release.yml | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/templates/semantic-release.yml b/templates/semantic-release.yml index fc549fa..1f6ccda 100644 --- a/templates/semantic-release.yml +++ b/templates/semantic-release.yml @@ -25,13 +25,15 @@ spec: variables: NPM_TOKEN: "${CI_JOB_TOKEN}" cache: - key: - prefix: "ci-component-semantic-release" - files: - - "package-lock.json" - paths: - - node_modules - - .cache/npm + - 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: - !reference [.semantic-release-fragment, authentication] - !reference [.semantic-release-fragment, config] -- GitLab From da1bce15b1e0e61220e516d7a5d8b69ba969a84f Mon Sep 17 00:00:00 2001 From: Matt Clarkson Date: Wed, 11 Sep 2024 11:51:32 +0100 Subject: [PATCH 12/15] docs(readme): split up overview section Move links to the end of the document. --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index cf42f0b..756912f 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 @@ -52,6 +52,7 @@ semantic-release: - npm config set -- "${CI_API_V4_URL#https?}/packages/npm/:_authToken" '\${NPM_JOB_TOKEN}' ``` +[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 -- GitLab From 764b3ad2bc8dbc6f5ef1c7f4798d7413283eb1e8 Mon Sep 17 00:00:00 2001 From: Matt Clarkson Date: Wed, 11 Sep 2024 11:51:58 +0100 Subject: [PATCH 13/15] docs(readme): remove purpose section Already described in the overview. --- README.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/README.md b/README.md index 756912f..7f0a8ef 100644 --- a/README.md +++ b/README.md @@ -20,10 +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 -- GitLab From fa4bdedda72ed2feeb04485d5353e57bdb75e8ff Mon Sep 17 00:00:00 2001 From: Matt Clarkson Date: Wed, 11 Sep 2024 11:52:42 +0100 Subject: [PATCH 14/15] docs(readme): add documentation for cache/auth --- README.md | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 7f0a8ef..f5090a8 100644 --- a/README.md +++ b/README.md @@ -30,23 +30,15 @@ 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 -- GitLab From 4cdb86461dc902ba9c6a8e2698526229df870720 Mon Sep 17 00:00:00 2001 From: Matt Clarkson Date: Fri, 13 Sep 2024 13:07:33 +0100 Subject: [PATCH 15/15] feat: split `image` up into `image` and `tag` BREAKING CHANGE: `image` is now the image name, the `tag` input defines the image tag --- templates/semantic-release.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/templates/semantic-release.yml b/templates/semantic-release.yml index 1f6ccda..53f93bb 100644 --- a/templates/semantic-release.yml +++ b/templates/semantic-release.yml @@ -4,8 +4,11 @@ spec: default: .post description: "The stage that the `.sematic-release` template will run under." image: - default: "node:lts" + 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: @@ -21,7 +24,7 @@ spec: .semantic-release: stage: $[[inputs.stage]] - image: $[[inputs.image]] + image: "$[[inputs.image]]:$[[inputs.tag]]" variables: NPM_TOKEN: "${CI_JOB_TOKEN}" cache: -- GitLab