Skip to content

Instantly share code, notes, and snippets.

@ryanshoover
Created October 5, 2023 21:14
Show Gist options
  • Save ryanshoover/cf2c28b2ff5278b61fc65f68dcdb8407 to your computer and use it in GitHub Desktop.
Save ryanshoover/cf2c28b2ff5278b61fc65f68dcdb8407 to your computer and use it in GitHub Desktop.
Deploying to feature branches & dev
...
echo "Ready to deploy to Pantheon"
if [[ $CI_BRANCH != $DEFAULT_BRANCH ]]
then
echo "Pushing to a multidev environment."
ENV_EXISTS=$(terminus env:list "$TERMINUS_SITE" --field=id | grep "^$TERMINUS_ENV$" || true)
if [[ $ENV_EXISTS ]]
then
echo "Multidev environment already exists. Pushing to it."
# Push to the multidev environment if it exists
terminus -n build:env:push "$TERMINUS_SITE.$TERMINUS_ENV" --yes
else
echo "Multidev environment does not exist. Creating it."
# Create a new multidev environment (or push to an existing one)
terminus -n build:env:create "$TERMINUS_SITE.dev" "$TERMINUS_ENV" --yes
fi
else
echo "Pushing to the dev environment."
# Push to the dev environment
terminus -n build:env:push "$TERMINUS_SITE.dev" --yes
fi
....
name: Build, deploy and test
on: push
...
env:
...
CI_BRANCH: ${{ github.ref_name }}
...
jobs:
configure_env_vars:
...
steps:
...
- name: setup-environment-vars
run: |
if [ "$CI_BRANCH" != "master" ]; then
export PR_NUMBER=`curl -u "${GITHUB_OWNER}:${GITHUB_TOKEN}" \
-H "Accept: application/vnd.github.groot-preview+json" \
"https://api.github.com/repos/${CI_PROJECT_NAME}/commits/${COMMIT_SHA}/pulls" | \
python3 -c "import sys, json; print(json.load(sys.stdin)[0]['number'])"`
export CI_PULL_REQUEST=`curl -u "${GITHUB_OWNER}:${GITHUB_TOKEN}" \
-H "Accept: application/vnd.github.groot-preview+json" \
"https://api.github.com/repos/${CI_PROJECT_NAME}/commits/${COMMIT_SHA}/pulls" | \
python3 -c "import sys, json; print(json.load(sys.stdin)[0]['html_url'])"`
export TERMINUS_ENV="${CI_BRANCH:0:11}"
else
export CI_BRANCH="master"
export TERMINUS_ENV="dev"
fi
export CI_PROJECT_REPONAME=`curl -u "${GITHUB_OWNER}:${GITHUB_TOKEN}" \
-H "Accept: application/vnd.github.groot-preview+json" \
"https://api.github.com/repos/${CI_PROJECT_NAME}/commits/${COMMIT_SHA}/pulls" | \
python3 -c "import sys, json; print(json.load(sys.stdin)[0]['base']['repo']['name'])"`
export CI_PROJECT_USERNAME=$GITHUB_REPOSITORY_OWNER
/build-tools-ci/scripts/set-environment
echo "export TERMINUS_ENV='$TERMINUS_ENV'" >> $BASH_ENV
GITHUB_WORKFLOW_URL=https://github.com/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID
echo "export CI_BUILD_URL='${GITHUB_WORKFLOW_URL}'" >> $BASH_ENV
echo "export CI_NODE_INDEX=0" >> $BASH_ENV
echo "export CI_REPOSITORY_URL='https://github.com/${GITHUB_REPOSITORY}'" >> $BASH_ENV
echo "export ARTIFACTS_DIR_URL='${GITHUB_WORKFLOW_URL}/#artifacts'" >> $BASH_ENV
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment