From 6aef65b456917fe58078acfb789904f132b916e3 Mon Sep 17 00:00:00 2001 From: Xuan Hu Date: Fri, 17 May 2024 15:53:52 +0800 Subject: [PATCH 1/6] ci: integrate semantic release in GitLab CI/CD --- .gitlab/workflows/ci.yml | 14 ++++++++++++++ .gitlab/workflows/release.yml | 32 +++++--------------------------- package.json | 10 +++++++++- 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/.gitlab/workflows/ci.yml b/.gitlab/workflows/ci.yml index 29ac5f6f..1de00fb8 100644 --- a/.gitlab/workflows/ci.yml +++ b/.gitlab/workflows/ci.yml @@ -43,3 +43,17 @@ consistency: - git status --porcelain - test -z "$(git status --porcelain)" stage: ci +semantic-release: + image: + name: node:20.13.1 + interruptible: true + rules: + - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_PIPELINE_SOURCE == "push" && $CI_PROJECT_NAMESPACE == "huxuan8528" && $CI_PROJECT_NAME == "ss-python" + script: + - > + npx + -p @semantic-release/gitlab@13 + -p conventional-changelog-conventionalcommits@7 + -p semantic-release@23 + semantic-release + stage: release diff --git a/.gitlab/workflows/release.yml b/.gitlab/workflows/release.yml index e1d5e92c..6ddc9d9e 100644 --- a/.gitlab/workflows/release.yml +++ b/.gitlab/workflows/release.yml @@ -2,8 +2,6 @@ pages-build: artifacts: paths: - public - - docs/changelog.md - - release-notes.md cache: paths: - .venv @@ -17,26 +15,22 @@ pages-build: script: - make dev-doc - make doc - - make release-notes > release-notes.md stage: release -release-publish: - image: registry.gitlab.com/gitlab-org/release-cli:v0.18.0@sha256:696013aea0f2a20482800ce3a77341f840d7c7ec17bd78bd555e0bd6c00e4f11 +pages: + artifacts: + paths: + - public needs: - pages-build - release: - description: release-notes.md - tag_name: $CI_COMMIT_TAG rules: - if: $CI_COMMIT_TAG =~ /^v?(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-?(a|b|rc)(0|[1-9][0-9]*)?)?$/ script: - - echo "Running the release job." + - echo "Running the pages job." stage: release variables: GIT_STRATEGY: none container-publish: image: docker:26.1.2@sha256:c890c327e515cdccd14e593fb5450e4375e791ab0520795948134cb87b45aaa7 - needs: - - release-publish parallel: matrix: - PYTHON_VERSION: @@ -82,24 +76,8 @@ container-publish: PYTHON_VERSION: ${PYTHON_VERSION} SOURCE_DATE_EPOCH: 0 package-publish: - needs: - - release-publish rules: - if: $CI_COMMIT_TAG =~ /^v?(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-?(a|b|rc)(0|[1-9][0-9]*)?)?$/ script: - make publish stage: release -pages: - artifacts: - paths: - - public - needs: - - pages-build - - release-publish - rules: - - if: $CI_COMMIT_TAG =~ /^v?(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-?(a|b|rc)(0|[1-9][0-9]*)?)?$/ - script: - - echo "Running the pages job." - stage: release - variables: - GIT_STRATEGY: none diff --git a/package.json b/package.json index 71a24212..b5553fd3 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,9 @@ ] }, "release": { + "branches": [ + "xuan.hu/gitlab-semantic-release" + ], "plugins": [ [ "@semantic-release/commit-analyzer", @@ -118,7 +121,12 @@ } } ], - "@semantic-release/github" + [ + "@semantic-release/gitlab", + { + "gitlabUrl": "https://gitlab.com" + } + ] ], "preset": "conventionalcommits" } From 793e2fab0cb3aedb501305b009c750be99b7314c Mon Sep 17 00:00:00 2001 From: Xuan Hu Date: Fri, 17 May 2024 15:59:02 +0800 Subject: [PATCH 2/6] chore: allow failure for concistency --- .gitlab/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitlab/workflows/ci.yml b/.gitlab/workflows/ci.yml index 1de00fb8..962a52c8 100644 --- a/.gitlab/workflows/ci.yml +++ b/.gitlab/workflows/ci.yml @@ -33,6 +33,7 @@ consistency: interruptible: true rules: - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_PIPELINE_SOURCE == "push" + allow_failure: true - if: $CI_PIPELINE_SOURCE == 'merge_request_event' script: - git config --global user.name gitlab-ci From a51170cfd3d56781b757bafffd957e6c89e31e05 Mon Sep 17 00:00:00 2001 From: Xuan Hu Date: Fri, 17 May 2024 16:31:33 +0800 Subject: [PATCH 3/6] revert some test hack --- .gitlab/workflows/ci.yml | 3 +-- package.json | 3 --- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/.gitlab/workflows/ci.yml b/.gitlab/workflows/ci.yml index 962a52c8..7b92aef9 100644 --- a/.gitlab/workflows/ci.yml +++ b/.gitlab/workflows/ci.yml @@ -33,7 +33,6 @@ consistency: interruptible: true rules: - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_PIPELINE_SOURCE == "push" - allow_failure: true - if: $CI_PIPELINE_SOURCE == 'merge_request_event' script: - git config --global user.name gitlab-ci @@ -49,7 +48,7 @@ semantic-release: name: node:20.13.1 interruptible: true rules: - - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_PIPELINE_SOURCE == "push" && $CI_PROJECT_NAMESPACE == "huxuan8528" && $CI_PROJECT_NAME == "ss-python" + - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_PIPELINE_SOURCE == "push" && $CI_PROJECT_NAMESPACE == "serious-scaffold" && $CI_PROJECT_NAME == "ss-python" script: - > npx diff --git a/package.json b/package.json index b5553fd3..20158e63 100644 --- a/package.json +++ b/package.json @@ -5,9 +5,6 @@ ] }, "release": { - "branches": [ - "xuan.hu/gitlab-semantic-release" - ], "plugins": [ [ "@semantic-release/commit-analyzer", From 19ef1dfa2a44ef21fc271068249656405d7328df Mon Sep 17 00:00:00 2001 From: Xuan Hu Date: Fri, 17 May 2024 16:47:24 +0800 Subject: [PATCH 4/6] revert hack in package json --- package.json | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/package.json b/package.json index 20158e63..71a24212 100644 --- a/package.json +++ b/package.json @@ -118,12 +118,7 @@ } } ], - [ - "@semantic-release/gitlab", - { - "gitlabUrl": "https://gitlab.com" - } - ] + "@semantic-release/github" ], "preset": "conventionalcommits" } From f9d2ce498121b0da90e8217bcc9bfc49419e46c0 Mon Sep 17 00:00:00 2001 From: Xuan Hu Date: Fri, 17 May 2024 16:51:21 +0800 Subject: [PATCH 5/6] update template --- .../workflows/ci.yml.jinja | 14 ++++++++ .../workflows/release.yml.jinja | 32 +++---------------- template/{package.json => package.json.jinja} | 11 +++++++ 3 files changed, 30 insertions(+), 27 deletions(-) rename template/{package.json => package.json.jinja} (92%) diff --git a/template/[% if repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/ci.yml.jinja b/template/[% if repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/ci.yml.jinja index f8e5ef16..7bd924c7 100644 --- a/template/[% if repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/ci.yml.jinja +++ b/template/[% if repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/ci.yml.jinja @@ -56,3 +56,17 @@ consistency: - test -z "$(git status --porcelain)" stage: ci [%- endif %] +semantic-release: + image: + name: node:20.13.1 + interruptible: true + rules: + - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_PIPELINE_SOURCE == "push" && $CI_PROJECT_NAMESPACE == "serious-scaffold" && $CI_PROJECT_NAME == "ss-python" + script: + - > + npx + -p @semantic-release/gitlab@13 + -p conventional-changelog-conventionalcommits@7 + -p semantic-release@23 + semantic-release + stage: release diff --git a/template/[% if repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/release.yml.jinja b/template/[% if repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/release.yml.jinja index 8fa77153..0c451e57 100644 --- a/template/[% if repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/release.yml.jinja +++ b/template/[% if repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/release.yml.jinja @@ -3,8 +3,6 @@ pages-build: artifacts: paths: - public - - docs/changelog.md - - release-notes.md cache: paths: - .venv @@ -18,26 +16,22 @@ pages-build: script: - make dev-doc - make doc - - make release-notes > release-notes.md stage: release -release-publish: - image: registry.gitlab.com/gitlab-org/release-cli:v0.18.0@sha256:696013aea0f2a20482800ce3a77341f840d7c7ec17bd78bd555e0bd6c00e4f11 +pages: + artifacts: + paths: + - public needs: - pages-build - release: - description: release-notes.md - tag_name: $CI_COMMIT_TAG rules: - if: $CI_COMMIT_TAG =~ /^v?(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-?(a|b|rc)(0|[1-9][0-9]*)?)?$/ script: - - echo "Running the release job." + - echo "Running the pages job." stage: release variables: GIT_STRATEGY: none container-publish: image: docker:26.1.2@sha256:c890c327e515cdccd14e593fb5450e4375e791ab0520795948134cb87b45aaa7 - needs: - - release-publish parallel: matrix: - PYTHON_VERSION: @@ -93,24 +87,8 @@ container-publish: PYTHON_VERSION: ${PYTHON_VERSION} SOURCE_DATE_EPOCH: 0 package-publish: - needs: - - release-publish rules: - if: $CI_COMMIT_TAG =~ /^v?(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-?(a|b|rc)(0|[1-9][0-9]*)?)?$/ script: - make publish stage: release -pages: - artifacts: - paths: - - public - needs: - - pages-build - - release-publish - rules: - - if: $CI_COMMIT_TAG =~ /^v?(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-?(a|b|rc)(0|[1-9][0-9]*)?)?$/ - script: - - echo "Running the pages job." - stage: release - variables: - GIT_STRATEGY: none diff --git a/template/package.json b/template/package.json.jinja similarity index 92% rename from template/package.json rename to template/package.json.jinja index 71a24212..ce0ba734 100644 --- a/template/package.json +++ b/template/package.json.jinja @@ -118,7 +118,18 @@ } } ], +[%- if repo_platform == 'github' %] "@semantic-release/github" +[%- elif repo_platform == 'gitlab' %] + "@semantic-release/gitlab" +[%- elif repo_platform == 'gitlab-self-managed' %] + [ + "@semantic-release/gitlab", + { + "gitlabUrl": "https://{{ repo_host }}" + } + ] +[%- endif %] ], "preset": "conventionalcommits" } From bd3e79d7515fd515a11b20f8406f464c8bbb6739 Mon Sep 17 00:00:00 2001 From: Xuan Hu Date: Fri, 17 May 2024 16:52:48 +0800 Subject: [PATCH 6/6] minor --- .../workflows/ci.yml.jinja | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/template/[% if repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/ci.yml.jinja b/template/[% if repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/ci.yml.jinja index 7bd924c7..7d55494c 100644 --- a/template/[% if repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/ci.yml.jinja +++ b/template/[% if repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/ci.yml.jinja @@ -61,7 +61,7 @@ semantic-release: name: node:20.13.1 interruptible: true rules: - - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_PIPELINE_SOURCE == "push" && $CI_PROJECT_NAMESPACE == "serious-scaffold" && $CI_PROJECT_NAME == "ss-python" + - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_PIPELINE_SOURCE == "push" && $CI_PROJECT_NAMESPACE == "{{ repo_namespace }}" && $CI_PROJECT_NAME == "{{ repo_name }}" script: - > npx