Skip to content

Commit f23058b

Browse files
authored
ci: escape pull request branch tag before creating releases to test (#38)
1 parent 9e6bc44 commit f23058b

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

.circleci/config.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,8 @@ jobs:
267267
# - PR builds pass the branch name in as release_ref, so massage it if it is missing a semver prefix.
268268
echo "Branch (PR) build detected, sanitizing release tag..."
269269
LAST_SEMVER_TAG=$(git describe --tags --match 'v*.*.*' --abbrev=0 | cut -d"-" -f1)
270-
RELEASE_REF="${LAST_SEMVER_TAG}-<< parameters.release_ref >>"
270+
BRANCH_NAME=$(echo "<< parameters.release_ref >>" | sed 's/\//-/g')
271+
RELEASE_REF="${LAST_SEMVER_TAG}-${BRANCH_NAME}"
271272
fi
272273
echo "Will use RELEASE_REF=${RELEASE_REF}"
273274
echo "export RELEASE_REF=${RELEASE_REF}" >> $BASH_ENV
@@ -386,18 +387,24 @@ jobs:
386387
command: |
387388
# TODO: once CircleCI updates its pipeline-invocation API, move off of Cheng's personal CircleCI access token, which is saved to both of the slackapi CircleCI "contexts" as an env var:
388389
# https://app.circleci.com/settings/organization/github/slackapi/contexts
390+
if [[ -z "$CIRCLE_BRANCH" || "$CIRCLE_BRANCH" == pull/* ]]; then
391+
BRANCH_NAME="main"
392+
echo "Performing the standard end-to-end test suite for changes of a forked branch"
393+
else
394+
BRANCH_NAME="$CIRCLE_BRANCH"
395+
fi
389396
TEST_JOB_WORKFLOW_ID=$(curl --location --request POST 'https://circleci.com/api/v2/project/gh/slackapi/platform-devxp-test/pipeline' \
390397
--header 'Content-Type: application/json' \
391398
-u "${CCHEN_CIRCLECI_PERSONAL_TOKEN}:" \
392-
--data "{\"branch\":\"${CIRCLE_BRANCH}\",\"parameters\":{\"slack_cli_build_tag\":\"${RELEASE_REF}\"}}" | jq '.id')
399+
--data "{\"branch\":\"${BRANCH_NAME}\",\"parameters\":{\"slack_cli_build_tag\":\"${RELEASE_REF}\"}}" | jq '.id')
393400
if [ $TEST_JOB_WORKFLOW_ID = "null" ]; then
394401
echo "Performing the standard test suite found on the \"main\" branch of the end-to-end tests"
395402
TEST_JOB_WORKFLOW_ID=$(curl --location --request POST 'https://circleci.com/api/v2/project/gh/slackapi/platform-devxp-test/pipeline' \
396403
--header 'Content-Type: application/json' \
397404
-u "${CCHEN_CIRCLECI_PERSONAL_TOKEN}:" \
398405
--data "{\"branch\":\"main\",\"parameters\":{\"slack_cli_build_tag\":\"${RELEASE_REF}\"}}" | jq '.id')
399406
else
400-
echo "Performing the changed tests on the \"$CIRCLE_BRANCH\" branch of the end-to-end tests"
407+
echo "Performing the changed tests on the \"$BRANCH_NAME\" branch of the end-to-end tests"
401408
fi
402409
if [ $TEST_JOB_WORKFLOW_ID = "null" ]; then
403410
echo "Failed to start the testing workflow"

0 commit comments

Comments
 (0)