diff options
author | Marcel Amirault <mamirault@gitlab.com> | 2023-03-01 10:57:06 +0300 |
---|---|---|
committer | Marcel Amirault <mamirault@gitlab.com> | 2023-03-01 10:57:06 +0300 |
commit | 577314fc6e64dabad175eba34510580d6543babf (patch) | |
tree | e1f6390d37ae770a93583929a1ef2adcab1dc753 | |
parent | e9e07005979085ac93e0c47044f00b77a6b23722 (diff) |
Simplify pipeline configurationsimplify-pipeline-rules
Use pipeline name variable to simplify rules. Also,
remove rules that are no longer used, and reduce duplication.
-rw-r--r-- | .gitlab-ci.yml | 1 | ||||
-rw-r--r-- | .gitlab/ci/build-and-deploy.gitlab-ci.yml | 12 | ||||
-rw-r--r-- | .gitlab/ci/docker-images.gitlab-ci.yml | 42 | ||||
-rw-r--r-- | .gitlab/ci/rules.gitlab-ci.yml | 74 | ||||
-rw-r--r-- | .gitlab/ci/security.gitlab-ci.yml | 4 | ||||
-rw-r--r-- | .gitlab/ci/test.gitlab-ci.yml | 9 |
6 files changed, 42 insertions, 100 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index cb324826..b68726bd 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -52,7 +52,6 @@ workflow: - if: '$CI_PIPELINE_SOURCE == "schedule" && $PIPELINE_SCHEDULE_TIMING == "hourly"' variables: DOCS_PROJECT_PIPELINE_TYPE: "Hourly site deployment pipeline" - - if: '$CI_PIPELINE_SOURCE == "pipeline"' - if: '$CI_PIPELINE_SOURCE == "trigger"' variables: DOCS_PROJECT_PIPELINE_TYPE: "Review app pipeline" diff --git a/.gitlab/ci/build-and-deploy.gitlab-ci.yml b/.gitlab/ci/build-and-deploy.gitlab-ci.yml index 5028214c..2900c155 100644 --- a/.gitlab/ci/build-and-deploy.gitlab-ci.yml +++ b/.gitlab/ci/build-and-deploy.gitlab-ci.yml @@ -115,9 +115,7 @@ review: when: manual - if: '$CI_PROJECT_PATH !~ /^gitlab-org/' when: never - - if: '$CI_MERGE_REQUEST_ID' - - if: '$CI_PIPELINE_SOURCE == "pipeline" || $CI_PIPELINE_SOURCE == "trigger"' - - if: '$CI_COMMIT_BRANCH =~ /docs-preview/' # TODO: Remove once no projects create such branch + - if: '$CI_PIPELINE_SOURCE == "merge_request_event" || $DOCS_PROJECT_PIPELINE_TYPE == "Review app pipeline"' # # Stop the Review App @@ -143,11 +141,7 @@ review_stop: when: manual - if: '$CI_PROJECT_PATH !~ /^gitlab-org/' when: never - - if: '$CI_MERGE_REQUEST_ID || $CI_PIPELINE_SOURCE == "pipeline"|| $CI_PIPELINE_SOURCE == "trigger"' - allow_failure: true - when: manual - # TODO: Remove once no projects create such branch - - if: '$CI_COMMIT_BRANCH =~ /docs-preview/' + - if: '$CI_PIPELINE_SOURCE == "merge_request_event" || $DOCS_PROJECT_PIPELINE_TYPE == "Review app pipeline"' allow_failure: true when: manual @@ -161,7 +155,7 @@ delete_stopped_environments: before_script: [] dependencies: [] rules: - - if: $CI_PIPELINE_SOURCE == "schedule" && $PIPELINE_SCHEDULE_TIMING == "monthly" + - if: '$DOCS_PROJECT_PIPELINE_TYPE == "Monthly stopped environments cleanup pipeline"' stage: test script: - apk --update add curl jq diff --git a/.gitlab/ci/docker-images.gitlab-ci.yml b/.gitlab/ci/docker-images.gitlab-ci.yml index a04bfbaa..af0938b3 100644 --- a/.gitlab/ci/docker-images.gitlab-ci.yml +++ b/.gitlab/ci/docker-images.gitlab-ci.yml @@ -24,7 +24,7 @@ # image:gitlab-docs-base: extends: - - .rules_scheduled_manual + - .rules_docker_images - .docker_prepare stage: build-images variables: @@ -46,15 +46,12 @@ image:gitlab-docs-base: test:image:gitlab-docs-base: extends: - .docker_prepare + - .rules_docker_image_tests stage: test needs: [] variables: IMAGE_NAME: $CI_REGISTRY_IMAGE/base:alpine-$ALPINE_VERSION-ruby-$RUBY_VERSION-$CI_COMMIT_SHORT_SHA DOCKERFILE: dockerfiles/gitlab-docs-base.Dockerfile - rules: - - if: $CI_PIPELINE_SOURCE == "merge_request_event" - changes: - - $DOCKERFILE script: - docker build --build-arg ALPINE_VERSION=${ALPINE_VERSION} @@ -67,7 +64,7 @@ test:image:gitlab-docs-base: # image:docs-lint-markdown: extends: - - .rules_scheduled_manual + - .rules_docker_images - .docker_prepare stage: build-images variables: @@ -91,14 +88,11 @@ image:docs-lint-markdown: test:image:docs-lint-markdown: extends: - .docker_prepare + - .rules_docker_image_tests stage: test needs: [] variables: DOCKERFILE: dockerfiles/gitlab-docs-lint-markdown.Dockerfile - rules: - - if: $CI_PIPELINE_SOURCE == "merge_request_event" - changes: - - $DOCKERFILE script: - docker build --build-arg ALPINE_VERSION=${ALPINE_VERSION} @@ -112,7 +106,7 @@ test:image:docs-lint-markdown: # image:docs-lint-html: extends: - - .rules_scheduled_manual + - .rules_docker_images - .docker_prepare stage: build-images variables: @@ -134,14 +128,11 @@ image:docs-lint-html: test:image:docs-lint-html: extends: - .docker_prepare + - .rules_docker_image_tests stage: test needs: [] variables: DOCKERFILE: dockerfiles/gitlab-docs-lint-html.Dockerfile - rules: - - if: $CI_PIPELINE_SOURCE == "merge_request_event" - changes: - - $DOCKERFILE script: - docker build --build-arg RUBY_VERSION=${RUBY_VERSION} @@ -175,7 +166,7 @@ image:docs-single: - docker push $IMAGE_NAME # Only branches with versions like 10.4 rules: - - if: '$CI_COMMIT_BRANCH =~ /^\d{1,2}\.\d{1,2}$/' + - if: '$DOCS_PROJECT_PIPELINE_TYPE == "Stable branch pipeline"' # # Test the GitLab docs single version Docker image if changes made to its Dockerfile @@ -183,6 +174,7 @@ image:docs-single: test:image:docs-single: extends: - .docker_prepare + - .rules_docker_image_tests stage: test variables: GITLAB_VERSION: '15.9' @@ -190,10 +182,6 @@ test:image:docs-single: IMAGE_NAME: $CI_REGISTRY_IMAGE:$GITLAB_VERSION NANOC_ENV: test needs: [] - rules: - - if: $CI_PIPELINE_SOURCE == "merge_request_event" - changes: - - $DOCKERFILE script: - apk add --no-cache -U git - git fetch --all @@ -231,7 +219,7 @@ image:docs-single-lunrjs: - docker push $IMAGE_NAME # Only branches with versions like 10.4 rules: - - if: '$CI_COMMIT_BRANCH =~ /^\d{1,2}\.\d{1,2}$/' + - if: '$DOCS_PROJECT_PIPELINE_TYPE == "Stable branch pipeline"' # # Test the GitLab docs single version Docker image with lunr.js enabled @@ -240,6 +228,7 @@ image:docs-single-lunrjs: test:image:docs-single-lunrjs: extends: - .docker_prepare + - .rules_docker_image_tests stage: test variables: GITLAB_VERSION: '15.6' @@ -247,10 +236,6 @@ test:image:docs-single-lunrjs: DOCKERFILE: dockerfiles/single.Dockerfile NANOC_ENV: test needs: [] - rules: - - if: $CI_PIPELINE_SOURCE == "merge_request_event" - changes: - - $DOCKERFILE script: - apk add --no-cache -U make bash git - git fetch --all @@ -271,7 +256,7 @@ test:image:docs-single-lunrjs: # image:docs-latest: extends: - - .rules_scheduled_manual + - .rules_docker_images - .docker_prepare stage: build-images artifacts: {} @@ -293,15 +278,12 @@ image:docs-latest: test:image:docs-latest: extends: - .docker_prepare + - .rules_docker_image_tests stage: test variables: IMAGE_NAME: $CI_REGISTRY_IMAGE:latest DOCKERFILE: latest.Dockerfile needs: [] - rules: - - if: $CI_PIPELINE_SOURCE == "merge_request_event" - changes: - - $DOCKERFILE script: - docker build -t $IMAGE_NAME -f $DOCKERFILE . - docker run --rm $IMAGE_NAME ls -l /usr/share/nginx/html diff --git a/.gitlab/ci/rules.gitlab-ci.yml b/.gitlab/ci/rules.gitlab-ci.yml index c754074e..08fe1164 100644 --- a/.gitlab/ci/rules.gitlab-ci.yml +++ b/.gitlab/ci/rules.gitlab-ci.yml @@ -61,91 +61,65 @@ default: # # Rules to determine which pipelines jobs will run in. # -.rules_scheduled: +.rules_docker_images: rules: - - if: $CHORES_PIPELINE == "true" - when: never - - if: '$CI_PIPELINE_SOURCE != "schedule"' - when: never - - if: '$PIPELINE_SCHEDULE_TIMING == "weekly"' - - if: '$PIPELINE_SCHEDULE_TIMING == "hourly"' - when: manual - allow_failure: true - - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH' - when: manual - allow_failure: true - - if: '$CI_COMMIT_BRANCH == "main"' + - if: '$DOCS_PROJECT_PIPELINE_TYPE == "Build docker images pipeline"' when: manual allow_failure: true -.rules_scheduled_manual: +.rules_docker_image_tests: rules: - - if: $CHORES_PIPELINE == "true" - when: never - - if: '$CI_PIPELINE_SOURCE == "schedule"' - when: manual - allow_failure: true + - if: $CI_PIPELINE_SOURCE == "merge_request_event" + changes: + - $DOCKERFILE .rules_chores: rules: - - if: '$CI_PIPELINE_SOURCE == "schedule" && $CHORES_PIPELINE == "true"' + - if: '$DOCS_PROJECT_PIPELINE_TYPE == "Cleanup chores pipeline"' when: manual allow_failure: true .rules_site_tests: rules: - - if: $CHORES_PIPELINE == "true" - when: never - # Don't run site tests for review apps. - - if: '$CI_PIPELINE_SOURCE == "pipeline" || $CI_PIPELINE_SOURCE == "trigger"' - when: never - - if: '$CI_PIPELINE_SOURCE == "schedule"' - - if: '$CI_MERGE_REQUEST_ID' - - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH' - - if: '$CI_COMMIT_BRANCH =~ /^\d{1,2}\.\d{1,2}$/' - -.rules_global_nav_test: - rules: - - if: $CHORES_PIPELINE == "true" + - if: '$DOCS_PROJECT_PIPELINE_TYPE == "Cleanup chores pipeline"' when: never - - if: '$CI_PIPELINE_SOURCE == "pipeline" || $CI_PIPELINE_SOURCE == "trigger"' + - if: '$DOCS_PROJECT_PIPELINE_TYPE == "Review app pipeline"' when: never - if: '$CI_PIPELINE_SOURCE == "schedule"' - - if: '$CI_MERGE_REQUEST_ID' - - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH' - - if: '$CI_COMMIT_BRANCH =~ /^\d{1,2}\.\d{1,2}$/' + - if: '$CI_PIPELINE_SOURCE == "merge_request_event"' + - if: '$DOCS_PROJECT_PIPELINE_TYPE == "Default branch pipeline"' + - if: '$DOCS_PROJECT_PIPELINE_TYPE == "Stable branch pipeline"' .rules_prod: rules: - - if: $CHORES_PIPELINE == "true" + - if: '$DOCS_PROJECT_PIPELINE_TYPE == "Cleanup chores pipeline"' when: never # Don't deploy to production for trigerred pipelines (usually review apps) - - if: '$CI_PIPELINE_SOURCE == "pipeline" || $CI_PIPELINE_SOURCE == "trigger"' + - if: '$DOCS_PROJECT_PIPELINE_TYPE == "Review app pipeline"' when: never - - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH' - - if: '$CI_COMMIT_BRANCH =~ /^\d{1,2}\.\d{1,2}$/' + - if: '$DOCS_PROJECT_PIPELINE_TYPE == "Default branch pipeline"' + - if: '$DOCS_PROJECT_PIPELINE_TYPE == "Stable branch pipeline"' .rules_dev: rules: - - if: $CI_MERGE_REQUEST_ID && $CI_COMMIT_REF_NAME =~ /algolia/ + - if: $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_COMMIT_REF_NAME =~ /algolia/ variables: SEARCH_BACKEND: 'algolia' - - if: $CI_MERGE_REQUEST_ID && $CI_COMMIT_REF_NAME =~ /gps/ + - if: $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_COMMIT_REF_NAME =~ /gps/ variables: SEARCH_BACKEND: 'google' - - if: '$CI_MERGE_REQUEST_ID' - - if: '$CI_COMMIT_BRANCH =~ /docs-preview/' # TODO: Remove once no projects create such branch - - if: '$CI_PIPELINE_SOURCE == "schedule" && $CHORES_PIPELINE == "true"' + - if: '$CI_PIPELINE_SOURCE == "merge_request_event"' + - if: '$DOCS_PROJECT_PIPELINE_TYPE == "Cleanup chores pipeline"' .rules_upstream_review_app: rules: - - if: '$CI_PIPELINE_SOURCE == "pipeline" || $CI_PIPELINE_SOURCE == "trigger"' + - if: '$DOCS_PROJECT_PIPELINE_TYPE == "Review app pipeline"' .rules_pages: rules: - - if: $CHORES_PIPELINE == "true" + - if: '$DOCS_PROJECT_PIPELINE_TYPE == "Cleanup chores pipeline"' when: never # Don't deploy to production for trigerred pipelines (usually review apps) - - if: '$CI_PIPELINE_SOURCE == "pipeline"|| $CI_PIPELINE_SOURCE == "trigger"' + - if: '$DOCS_PROJECT_PIPELINE_TYPE == "Review app pipeline"' when: never - - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH' + - if: '$DOCS_PROJECT_PIPELINE_TYPE == "Default branch pipeline"' diff --git a/.gitlab/ci/security.gitlab-ci.yml b/.gitlab/ci/security.gitlab-ci.yml index e8ec2837..53b1f94e 100644 --- a/.gitlab/ci/security.gitlab-ci.yml +++ b/.gitlab/ci/security.gitlab-ci.yml @@ -59,7 +59,7 @@ secret_detection: rules: - if: $SECRET_DETECTION_DISABLED when: never - - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH - - if: $CI_PIPELINE_SOURCE == "merge_request_event" + - if: '$DOCS_PROJECT_PIPELINE_TYPE == "Default branch pipeline"' + - if: '$DOCS_PROJECT_PIPELINE_TYPE =~ /^MR pipeline.*/' script: - /analyzer run diff --git a/.gitlab/ci/test.gitlab-ci.yml b/.gitlab/ci/test.gitlab-ci.yml index cf238ca0..8b989a1b 100644 --- a/.gitlab/ci/test.gitlab-ci.yml +++ b/.gitlab/ci/test.gitlab-ci.yml @@ -8,7 +8,7 @@ test_global_nav_links: image: registry.gitlab.com/gitlab-org/gitlab-docs/lint-html:alpine-3.16-ruby-3.0.5-2a7e4d1c extends: - - .rules_global_nav_test + - .rules_site_tests - .bundle stage: test script: @@ -205,10 +205,3 @@ lint_dockerfiles: script: - apk add make - make hadolint-tests - -# -# eslint-sast scans html too, so run in security stage after html files are generated -# - -eslint-sast: - stage: security |