From b70c4a744f9792244f0ba8096bed5b5afbe70d29 Mon Sep 17 00:00:00 2001 From: Amir Zarrinkafsh Date: Mon, 9 Mar 2020 12:32:07 +1100 Subject: [PATCH] [Buildkite] Ignore unnecessary CI steps for docs/* only based commits (#690) * [Buildkite] Ignore build and deploy steps for [DOCS] only based commits * [Buildkite] Convert static pipelines into dynamic pipelines * [Buildkite] Convert dynamic pipeline steps into heredocs * [Buildkite] Fix indentation for aurpackages.sh * [Buildkite] Rename docs bypass env variable * [Buildkite] Fix automatic retries in integration tests --- .buildkite/{deployment.yml => deployment.sh} | 21 ++++++++---- .buildkite/pipeline.sh | 29 ++++++++++++++++ .buildkite/pipeline.yml | 16 --------- .buildkite/steps/aurpackages.sh | 36 +++++++++++--------- .buildkite/steps/buildimages.sh | 28 +++++++-------- .buildkite/steps/deployimages.sh | 18 +++++----- .buildkite/steps/e2etests.sh | 33 ++++++++++-------- 7 files changed, 105 insertions(+), 76 deletions(-) rename .buildkite/{deployment.yml => deployment.sh} (64%) mode change 100644 => 100755 create mode 100755 .buildkite/pipeline.sh delete mode 100644 .buildkite/pipeline.yml diff --git a/.buildkite/deployment.yml b/.buildkite/deployment.sh old mode 100644 new mode 100755 similarity index 64% rename from .buildkite/deployment.yml rename to .buildkite/deployment.sh index 1f15b6fec..5c86d00d2 --- a/.buildkite/deployment.yml +++ b/.buildkite/deployment.sh @@ -1,15 +1,23 @@ +#!/bin/bash +set -u + +cat << EOF +env: + CI_DOCS_BYPASS: $(git diff --name-only `git merge-base --fork-point master` | sed -rn '/^docs\/.*/!{q1}' && echo true || echo false) + steps: - label: ":docker: Image Deployments" command: ".buildkite/steps/deployimages.sh | buildkite-agent pipeline upload" concurrency: 1 concurrency_group: "deployments" - if: build.branch == "master" + if: build.branch == "master" && build.env("CI_DOCS_BYPASS") != "true" - label: ":docker: Image Deployments" command: ".buildkite/steps/deployimages.sh | buildkite-agent pipeline upload" - if: build.branch != "master" + if: build.branch != "master" && build.env("CI_DOCS_BYPASS") != "true" - - wait + - wait: + if: build.env("CI_DOCS_BYPASS") != "true" - label: ":docker: Deploy Manifests" command: "authelia-scripts docker push-manifest" @@ -17,13 +25,13 @@ steps: concurrency_group: "deployments" env: DOCKER_CLI_EXPERIMENTAL: "enabled" - if: build.branch == "master" + if: build.branch == "master" && build.env("CI_DOCS_BYPASS") != "true" - label: ":docker: Deploy Manifests" command: "authelia-scripts docker push-manifest" env: DOCKER_CLI_EXPERIMENTAL: "enabled" - if: build.branch != "master" + if: build.branch != "master" && build.env("CI_DOCS_BYPASS") != "true" - label: ":github: Deploy Artifacts" command: "ghartifacts.sh" @@ -38,7 +46,7 @@ steps: - label: ":linux: Deploy AUR" command: ".buildkite/steps/aurpackages.sh | buildkite-agent pipeline upload" depends_on: ~ - if: build.tag != null || build.branch == "master" + if: build.tag != null || build.branch == "master" && build.env("CI_DOCS_BYPASS") != "true" - label: ":book: Deploy Documentation" command: "syncdoc.sh" @@ -46,3 +54,4 @@ steps: agents: upload: "fast" if: build.branch == "master" +EOF \ No newline at end of file diff --git a/.buildkite/pipeline.sh b/.buildkite/pipeline.sh new file mode 100755 index 000000000..8ec5b705c --- /dev/null +++ b/.buildkite/pipeline.sh @@ -0,0 +1,29 @@ +#!/bin/bash +set -u + +cat << EOF +env: + CI_DOCS_BYPASS: $(git diff --name-only `git merge-base --fork-point master` | sed -rn '/^docs\/.*/!{q1}' && echo true || echo false) + +steps: + - label: ":hammer_and_wrench: Unit Test" + command: "authelia-scripts --log-level debug ci" + if: build.env("CI_DOCS_BYPASS") != "true" + + - wait: + if: build.env("CI_DOCS_BYPASS") != "true" + + - label: ":docker: Image Builds" + command: ".buildkite/steps/buildimages.sh | buildkite-agent pipeline upload" + depends_on: ~ + if: build.env("CI_DOCS_BYPASS") != "true" + + - wait: + if: build.env("CI_DOCS_BYPASS") != "true" + + - label: ":chrome: Integration Tests" + command: ".buildkite/steps/e2etests.sh | buildkite-agent pipeline upload" + depends_on: + - "build-docker-amd64" + if: build.env("CI_DOCS_BYPASS") != "true" +EOF \ No newline at end of file diff --git a/.buildkite/pipeline.yml b/.buildkite/pipeline.yml deleted file mode 100644 index 96e83009e..000000000 --- a/.buildkite/pipeline.yml +++ /dev/null @@ -1,16 +0,0 @@ -steps: - - label: ":hammer_and_wrench: Unit Test" - command: "authelia-scripts --log-level debug ci" - - - wait - - - label: ":docker: Image Builds" - command: ".buildkite/steps/buildimages.sh | buildkite-agent pipeline upload" - depends_on: ~ - - - wait - - - label: ":chrome: Integration Tests" - command: ".buildkite/steps/e2etests.sh | buildkite-agent pipeline upload" - depends_on: - - "build-docker-amd64" \ No newline at end of file diff --git a/.buildkite/steps/aurpackages.sh b/.buildkite/steps/aurpackages.sh index d9c8663eb..cd2dbf348 100755 --- a/.buildkite/steps/aurpackages.sh +++ b/.buildkite/steps/aurpackages.sh @@ -1,20 +1,24 @@ #!/bin/bash set -eu -for AUR_PACKAGE in authelia authelia-bin authelia-git; -do - echo " - label: \":linux: Deploy AUR Package [${AUR_PACKAGE}]\"" - echo " commands:" - echo " - \"aurhelper.sh\"" - echo " agents:" - echo " upload: \"fast\"" - echo " env:" - echo " "PACKAGE: ${AUR_PACKAGE}"" - if [[ "${AUR_PACKAGE}" != "authelia-git" ]]; then - echo " depends_on:" - echo " - \"artifacts\"" - echo " if: build.tag != null" - else - echo " if: build.branch == \"master\"" - fi +for AUR_PACKAGE in authelia authelia-bin authelia-git; do +cat << EOF + - label: ":linux: Deploy AUR Package [${AUR_PACKAGE}]" + command: "aurhelper.sh" + agents: + upload: "fast" + env: + PACKAGE: "${AUR_PACKAGE}" +EOF +if [[ "${AUR_PACKAGE}" != "authelia-git" ]]; then +cat << EOF + depends_on: + - "artifacts" + if: build.tag != null +EOF +else +cat << EOF + if: build.branch == "master" +EOF +fi done \ No newline at end of file diff --git a/.buildkite/steps/buildimages.sh b/.buildkite/steps/buildimages.sh index 91b4e21a3..334c56a95 100755 --- a/.buildkite/steps/buildimages.sh +++ b/.buildkite/steps/buildimages.sh @@ -1,18 +1,18 @@ #!/bin/bash set -eu -for BUILD_ARCH in amd64 arm32v7 arm64v8; -do - echo " - label: \":docker: Build Image [${BUILD_ARCH}]\"" - echo " commands:" - echo " - \"authelia-scripts docker build --arch=${BUILD_ARCH}\"" - echo " agents:" - echo " build: \"true\"" - echo " artifact_paths:" - echo " - \"authelia-image-${BUILD_ARCH}.tar.zst\"" - echo " - \"authelia-linux-${BUILD_ARCH}.tar.gz\"" - echo " - \"authelia-linux-${BUILD_ARCH}.tar.gz.sha256\"" - echo " env:" - echo " "ARCH: ${BUILD_ARCH}"" - echo " key: \"build-docker-${BUILD_ARCH}\"" +for BUILD_ARCH in amd64 arm32v7 arm64v8; do +cat << EOF + - label: ":docker: Build Image [${BUILD_ARCH}]" + command: "authelia-scripts docker build --arch=${BUILD_ARCH}" + agents: + build: "true" + artifact_paths: + - "authelia-image-${BUILD_ARCH}.tar.zst" + - "authelia-linux-${BUILD_ARCH}.tar.gz" + - "authelia-linux-${BUILD_ARCH}.tar.gz.sha256" + env: + ARCH: "${BUILD_ARCH}" + key: "build-docker-${BUILD_ARCH}" +EOF done \ No newline at end of file diff --git a/.buildkite/steps/deployimages.sh b/.buildkite/steps/deployimages.sh index 857c2c3e6..cf5178720 100755 --- a/.buildkite/steps/deployimages.sh +++ b/.buildkite/steps/deployimages.sh @@ -1,13 +1,13 @@ #!/bin/bash set -eu -for BUILD_ARCH in amd64 arm32v7 arm64v8; -do - echo " - commands:" - echo " - \"authelia-scripts docker push-image --arch=${BUILD_ARCH}\"" - echo " label: \":docker: Deploy Image [${BUILD_ARCH}]\"" - echo " agents:" - echo " upload: \"fast\"" - echo " env:" - echo " "ARCH: ${BUILD_ARCH}"" +for BUILD_ARCH in amd64 arm32v7 arm64v8; do +cat << EOF + - label: ":docker: Deploy Image [${BUILD_ARCH}]" + command: "authelia-scripts docker push-image --arch=${BUILD_ARCH}" + agents: + upload: "fast" + env: + ARCH: "${BUILD_ARCH}" +EOF done \ No newline at end of file diff --git a/.buildkite/steps/e2etests.sh b/.buildkite/steps/e2etests.sh index 14c5f6953..25c263621 100755 --- a/.buildkite/steps/e2etests.sh +++ b/.buildkite/steps/e2etests.sh @@ -1,19 +1,22 @@ #!/bin/bash set -eu -for SUITE_NAME in $(authelia-scripts suites list); -do - echo " - label: \":selenium: ${SUITE_NAME} Suite\"" - echo " commands:" - echo " - \"authelia-scripts --log-level debug suites test ${SUITE_NAME} --headless\"" - echo " retry:" - echo " "automatic: true"" - if [[ "${SUITE_NAME}" != "Kubernetes" ]]; - then - echo " agents:" - echo " "suite: all"" - else - echo " agents:" - echo " "suite: kubernetes"" - fi +for SUITE_NAME in $(authelia-scripts suites list); do +cat << EOF + - label: ":selenium: ${SUITE_NAME} Suite" + command: "authelia-scripts --log-level debug suites test ${SUITE_NAME} --headless" + retry: + automatic: true +EOF +if [[ "${SUITE_NAME}" != "Kubernetes" ]]; then +cat << EOF + agents: + suite: "all" +EOF +else +cat << EOF + agents: + suite: "kubernetes" +EOF +fi done \ No newline at end of file