CI(CircleCI): Halt building if a draft PR (#1214)

* Halt building if a draft PR
This commit is contained in:
Iain Sproat
2022-11-21 11:20:36 +00:00
committed by GitHub
parent 22278af8d1
commit c53688c67e
2 changed files with 41 additions and 1 deletions
+14 -1
View File
@@ -30,6 +30,8 @@ workflows:
filters: *filters-allow-all
- docker-build-server:
context: &build-context
- github-readonly-public-repos
filters: &filters-build
tags:
only: /.*/
@@ -38,35 +40,41 @@ workflows:
- get-version
- docker-build-frontend:
context: *build-context
filters: *filters-build
requires:
- get-version
- docker-build-webhooks:
context: *build-context
filters: *filters-build
requires:
- get-version
- test-server
- docker-build-file-imports:
context: *build-context
filters: *filters-build
requires:
- get-version
- test-server
- docker-build-previews:
context: *build-context
filters: *filters-build
requires:
- get-version
- test-server
- docker-build-test-container:
context: *build-context
filters: *filters-build
requires:
- get-version
- test-server
- docker-build-monitor-container:
context: *build-context
filters: *filters-build
requires:
- get-version
@@ -365,11 +373,16 @@ jobs:
- checkout
- attach_workspace:
at: /tmp/ci/workspace
- run:
name: determine if draft PR
command: |
echo "export IS_DRAFT_PR=$(.circleci/is_draft.sh)" >> workspace/env-vars
- run: cat workspace/env-vars >> $BASH_ENV
- run: echo "IS_DRAFT_PR=${IS_DRAFT_PR}"
- run:
name: 'Check if should proceed'
command: |
[[ "${CIRCLE_BRANCH}" != "main" && -z "${CIRCLE_PULL_REQUEST}" ]] && echo "Should not build, stopping" && circleci-agent step halt && exit 1
[[ "${CIRCLE_BRANCH}" != "main" && ("${IS_DRAFT_PR}" == "TRUE" || -z "${CIRCLE_PULL_REQUEST}") ]] && echo "Should not build, stopping" && circleci-agent step halt && exit 1
echo "proceeding"
- setup_remote_docker:
# a weird issue with yarn installing packages throwing EPERM errors
+27
View File
@@ -0,0 +1,27 @@
#!/usr/bin/env bash
# acknowledgements: https://github.com/vitalinfo/circleci-cancel-draft
set -euf -o pipefail
if [[ -z "$CIRCLE_PULL_REQUEST" ]]; then
echo "FALSE"
fi
PR_NUMBER="${CIRCLE_PULL_REQUEST//[!0-9]/}"
RESPONSE=$(curl --silent \
-H "Authorization: token ${GITHUB_TOKEN}" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/pulls/${PR_NUMBER}"
)
DRAFT=$(echo "${RESPONSE}" | jq ".draft")
DRAFT_LABEL=$(echo "${RESPONSE}" | jq ".labels | map(select(.name | test(\"Draft\"))) | .[]")
if [[ ${DRAFT} == 'true' || ${DRAFT_LABEL} ]]; then
echo "TRUE"
else
echo "FALSE"
fi
exit 0