From 8995378a79730c5a282106ac0f26c41637ca056d Mon Sep 17 00:00:00 2001 From: Michael Leu Date: Fri, 26 Nov 2021 15:10:24 +0100 Subject: [PATCH 1/5] feat: use npm when there is no yarn.lock --- .gitlab-ci.yml | 4 ++-- includes/before-script-js-pm.yml | 11 +++++++++ includes/before-script-yarn.yml | 6 ----- includes/docker-build.yml | 2 +- monorepo.yml | 2 +- node-kubernetes.yml | 38 ++++++++++++++++++++++++-------- 6 files changed, 44 insertions(+), 19 deletions(-) create mode 100644 includes/before-script-js-pm.yml delete mode 100644 includes/before-script-yarn.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0ef9a45..563dfb8 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,6 +1,6 @@ include: - /includes/cache.yml - - /includes/before-script-yarn.yml + - /includes/before-script-js-pm.yml - /includes/rules.yml - /includes/docker-build.yml - /semantic-release-for-gitlab-ci-includes.yml @@ -52,7 +52,7 @@ replacePipelineImageTag: test: extends: - - .before-script-yarn + - .before-script-js-pm script: - yarn test stage: test diff --git a/includes/before-script-js-pm.yml b/includes/before-script-js-pm.yml new file mode 100644 index 0000000..61a09ff --- /dev/null +++ b/includes/before-script-js-pm.yml @@ -0,0 +1,11 @@ +.before-script-js-pm: + extends: .cache-node-modules + before_script: + - cd $APP_PATH + - if [ -f ./.nvmrc ]; then source /root/.nvm/nvm.sh && nvm install <<< .nvmrc; fi + - | + if test -f package-lock.json && test ! -f yarn.lock; then + npm ci + else + yarn install --frozen-lockfile + fi diff --git a/includes/before-script-yarn.yml b/includes/before-script-yarn.yml deleted file mode 100644 index fb44409..0000000 --- a/includes/before-script-yarn.yml +++ /dev/null @@ -1,6 +0,0 @@ -.before-script-yarn: - extends: .cache-node-modules - before_script: - - cd $APP_PATH - - if [ -f ./.nvmrc ]; then source /root/.nvm/nvm.sh && nvm install <<< .nvmrc; fi - - yarn install --frozen-lockfile diff --git a/includes/docker-build.yml b/includes/docker-build.yml index efee71f..7146019 100644 --- a/includes/docker-build.yml +++ b/includes/docker-build.yml @@ -72,7 +72,7 @@ variables: .storybook-build: extends: - .rules-stoybook - - .before-script-yarn + - .before-script-js-pm stage: build needs: ["setup-build-info"] diff --git a/monorepo.yml b/monorepo.yml index 9d8ede5..9ff4228 100644 --- a/monorepo.yml +++ b/monorepo.yml @@ -1,5 +1,5 @@ include: - - /includes/before-script-yarn.yml + - /includes/before-script-js-pm.yml - /includes/env.yml - /includes/retry.yml - /includes/cache.yml diff --git a/node-kubernetes.yml b/node-kubernetes.yml index 73848ee..7e1ad75 100644 --- a/node-kubernetes.yml +++ b/node-kubernetes.yml @@ -13,11 +13,16 @@ docker-build: stage: test extends: - - .before-script-yarn + - .before-script-js-pm - .test-base script: - - yarn test + - | + if test -f package-lock.json && test ! -f yarn.lock; then + npm test + else + yarn test + fi test: extends: .test-node @@ -26,11 +31,16 @@ test: stage: test extends: - - .before-script-yarn + - .before-script-js-pm - .audit-base script: - - yarn audit + - | + if test -f package-lock.json && test ! -f yarn.lock; then + npm audit + else + yarn audit + fi audit: extends: .audit-node @@ -38,11 +48,16 @@ audit: .lint-node: stage: test extends: - - .before-script-yarn + - .before-script-js-pm - .lint-base script: - - yarn lint + - | + if test -f package-lock.json && test ! -f yarn.lock; then + npm lint + else + yarn lint + fi needs: [] lint: @@ -50,11 +65,16 @@ lint: .app-build-node: extends: - - .before-script-yarn + - .before-script-js-pm - .app-build-base - .cache-app-build-node-next script: - - yarn build + - | + if test -f package-lock.json && test ! -f yarn.lock; then + npm build + else + yarn build + fi artifacts: paths: @@ -71,7 +91,7 @@ app-build: extends: - .cache-verify-cypress script: - - !reference [.before-script-yarn, before_script] + - !reference [.before-script-js-pm, before_script] - yarn cypress install - CYPRESS_BASE_URL=$CI_ENVIRONMENT_URL yarn cypress:run --browser chrome --headless --record --key $CYPRESS_KEY artifacts: -- GitLab From 3bb082cd4f3cf213ea511c734f1ea8272a15516d Mon Sep 17 00:00:00 2001 From: Michael Leu Date: Mon, 29 Nov 2021 15:18:20 +0100 Subject: [PATCH 2/5] refactor(npm): use wrapper script --- dockerfiles/pipeline/scripts/yarn-or-npm | 11 ++++++++++ includes/before-script-js-pm.yml | 7 +----- node-kubernetes.yml | 28 ++++-------------------- 3 files changed, 16 insertions(+), 30 deletions(-) create mode 100755 dockerfiles/pipeline/scripts/yarn-or-npm diff --git a/dockerfiles/pipeline/scripts/yarn-or-npm b/dockerfiles/pipeline/scripts/yarn-or-npm new file mode 100755 index 0000000..3f6e2ec --- /dev/null +++ b/dockerfiles/pipeline/scripts/yarn-or-npm @@ -0,0 +1,11 @@ +#!/bin/bash + +if [ -f package-lock.json ] && [ ! -f yarn.lock ]; then + if [ "$1" == "install" ] && [ "$2" == "--frozen-lockfile" ]; then + npm ci + else + npm "$@" + fi +else + yarn "$@" +fi diff --git a/includes/before-script-js-pm.yml b/includes/before-script-js-pm.yml index 61a09ff..2879dd3 100644 --- a/includes/before-script-js-pm.yml +++ b/includes/before-script-js-pm.yml @@ -3,9 +3,4 @@ before_script: - cd $APP_PATH - if [ -f ./.nvmrc ]; then source /root/.nvm/nvm.sh && nvm install <<< .nvmrc; fi - - | - if test -f package-lock.json && test ! -f yarn.lock; then - npm ci - else - yarn install --frozen-lockfile - fi + - yarn-or-npm install --frozen-lockfile diff --git a/node-kubernetes.yml b/node-kubernetes.yml index 7e1ad75..f95610b 100644 --- a/node-kubernetes.yml +++ b/node-kubernetes.yml @@ -17,12 +17,7 @@ docker-build: - .test-base script: - - | - if test -f package-lock.json && test ! -f yarn.lock; then - npm test - else - yarn test - fi + - yarn-or-npm test test: extends: .test-node @@ -35,12 +30,7 @@ test: - .audit-base script: - - | - if test -f package-lock.json && test ! -f yarn.lock; then - npm audit - else - yarn audit - fi + - yarn-or-npm audit audit: extends: .audit-node @@ -52,12 +42,7 @@ audit: - .lint-base script: - - | - if test -f package-lock.json && test ! -f yarn.lock; then - npm lint - else - yarn lint - fi + - yarn-or-npm lint needs: [] lint: @@ -69,12 +54,7 @@ lint: - .app-build-base - .cache-app-build-node-next script: - - | - if test -f package-lock.json && test ! -f yarn.lock; then - npm build - else - yarn build - fi + - yarn-or-npm build artifacts: paths: -- GitLab From 01268231e5bedaf1e48fdecc752eda75b2220e30 Mon Sep 17 00:00:00 2001 From: Michael Leu Date: Mon, 29 Nov 2021 15:37:08 +0100 Subject: [PATCH 3/5] chore(ci): inline include for test job because it does not run with pipeline image --- .gitlab-ci.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 563dfb8..e20d934 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -51,8 +51,11 @@ replacePipelineImageTag: - git push "https://release-bot:${GL_TOKEN}@${CI_REPOSITORY_URL#*@}" "HEAD:${CI_COMMIT_REF_NAME}" test: - extends: - - .before-script-js-pm + extends: .cache-node-modules + before_script: + - cd $APP_PATH + - if [ -f ./.nvmrc ]; then source /root/.nvm/nvm.sh && nvm install <<< .nvmrc; fi + - yarn install --frozen-lockfile script: - yarn test stage: test -- GitLab From af0fc8b7d9aa826c1e6a3c2ed0b764ed46087b91 Mon Sep 17 00:00:00 2001 From: Gitlab Runner Date: Mon, 29 Nov 2021 14:48:28 +0000 Subject: [PATCH 4/5] adjust PIPELINE_IMAGE_TAG --- helm-chart.yml | 2 +- monorepo.yml | 2 +- panter-kubernetes-base.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/helm-chart.yml b/helm-chart.yml index 56b844c..d45cc61 100644 --- a/helm-chart.yml +++ b/helm-chart.yml @@ -11,7 +11,7 @@ image: variables: HELM_EXPERIMENTAL_OCI: 1 AUTO_RELEASE: "true" - PIPELINE_IMAGE_TAG: 7f8c96799c22ffda371e02932470779e1496dd92 + PIPELINE_IMAGE_TAG: 01268231e5bedaf1e48fdecc752eda75b2220e30 stages: - lint diff --git a/monorepo.yml b/monorepo.yml index 9ff4228..b1a6fb5 100644 --- a/monorepo.yml +++ b/monorepo.yml @@ -12,7 +12,7 @@ include: - /includes/open-mr.yml variables: - PIPELINE_IMAGE_TAG: 7f8c96799c22ffda371e02932470779e1496dd92 + PIPELINE_IMAGE_TAG: 01268231e5bedaf1e48fdecc752eda75b2220e30 image: git.panter.ch:5001/catladder/gitlab-ci/pipeline:$PIPELINE_IMAGE_TAG diff --git a/panter-kubernetes-base.yml b/panter-kubernetes-base.yml index 80602a6..816fedd 100644 --- a/panter-kubernetes-base.yml +++ b/panter-kubernetes-base.yml @@ -12,7 +12,7 @@ include: - /includes/open-mr.yml variables: - PIPELINE_IMAGE_TAG: 7f8c96799c22ffda371e02932470779e1496dd92 + PIPELINE_IMAGE_TAG: 01268231e5bedaf1e48fdecc752eda75b2220e30 CUSTOMER_NAME: panter APP_NAME: demo COMPONENT_NAME: web -- GitLab From 1f663a77840bf825123ed4a4125f2ad5fda0d518 Mon Sep 17 00:00:00 2001 From: Gitlab Runner Date: Mon, 29 Nov 2021 16:25:47 +0000 Subject: [PATCH 5/5] adjust PIPELINE_IMAGE_TAG --- helm-chart.yml | 2 +- monorepo.yml | 2 +- panter-kubernetes-base.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/helm-chart.yml b/helm-chart.yml index d45cc61..1448e02 100644 --- a/helm-chart.yml +++ b/helm-chart.yml @@ -11,7 +11,7 @@ image: variables: HELM_EXPERIMENTAL_OCI: 1 AUTO_RELEASE: "true" - PIPELINE_IMAGE_TAG: 01268231e5bedaf1e48fdecc752eda75b2220e30 + PIPELINE_IMAGE_TAG: b631bd90d9642cc779779c8e0438ad78731f9905 stages: - lint diff --git a/monorepo.yml b/monorepo.yml index b1a6fb5..918626b 100644 --- a/monorepo.yml +++ b/monorepo.yml @@ -12,7 +12,7 @@ include: - /includes/open-mr.yml variables: - PIPELINE_IMAGE_TAG: 01268231e5bedaf1e48fdecc752eda75b2220e30 + PIPELINE_IMAGE_TAG: b631bd90d9642cc779779c8e0438ad78731f9905 image: git.panter.ch:5001/catladder/gitlab-ci/pipeline:$PIPELINE_IMAGE_TAG diff --git a/panter-kubernetes-base.yml b/panter-kubernetes-base.yml index 816fedd..9132e62 100644 --- a/panter-kubernetes-base.yml +++ b/panter-kubernetes-base.yml @@ -12,7 +12,7 @@ include: - /includes/open-mr.yml variables: - PIPELINE_IMAGE_TAG: 01268231e5bedaf1e48fdecc752eda75b2220e30 + PIPELINE_IMAGE_TAG: b631bd90d9642cc779779c8e0438ad78731f9905 CUSTOMER_NAME: panter APP_NAME: demo COMPONENT_NAME: web -- GitLab