Skip to content

Commit

Permalink
Include lagoon log URL in GH deployments.
Browse files Browse the repository at this point in the history
  • Loading branch information
rasben committed Oct 3, 2024
1 parent 1b5ad49 commit fbd530d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
17 changes: 13 additions & 4 deletions .lagoon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,21 @@ tasks:
command: |
GH_DEPLOYMENT=$(curl -L -X POST -H "Authorization: Bearer $GH_DEPLOYMENT_TOKEN" \
https://api.github.com/repos/danskernesdigitalebibliotek/dpl-cms/deployments \
-d "{\"ref\":\"$LAGOON_PR_HEAD_BRANCH\", \"environment\":\"$LAGOON_PR_HEAD_BRANCH\", \
-d "{\"ref\":\"$LAGOON_PR_HEAD_BRANCH\", \"environment\":\"$LAGOON_ENVIRONMENT\", \
\"description\":\"Triggered by Lagoon\", \"transient_environment\": true, \
\"auto_merge\": false, \"required_contexts\": []}")
echo "$GH_DEPLOYMENT"
GH_DEPLOYMENT_ID=$(echo "$GH_DEPLOYMENT" | grep -m 1 '"id":' | sed -E 's/.*"id": ([0-9]+),.*/\1/')
echo "Created GH deployment with ID '$GH_DEPLOYMENT_ID'"
echo "$GH_DEPLOYMENT_ID" > /tmp/gh_deployment_id
# The only way to keep a value between tasks, is saving it in a
# file. Environment variables are killed between tasks, apart from
# the global ones.
echo "$GH_DEPLOYMENT_ID" > /tmp/GH_DEPLOYMENT_ID
LAGOON_DEPLOYS_LOG_URL=$(echo "https://ui.lagoon.dplplat01.dpl.reload.dk/projects/$LAGOON_PROJECT/dpl-cms-$LAGOON_ENVIRONMENT/deployments")
echo "$LAGOON_DEPLOYS_URL" > /tmp/LAGOON_DEPLOYS_LOG_URL
service: cli
- run:
name: If drupal is not installed
Expand Down Expand Up @@ -122,15 +128,18 @@ tasks:
DRUPAL_URL=$(drush browse)
# Read the deployment ID from the file
GH_DEPLOYMENT_ID=$(cat /tmp/gh_deployment_id)
GH_DEPLOYMENT_ID=$(cat /tmp/GH_DEPLOYMENT_ID)
LAGOON_DEPLOYS_LOG_URL=$(cat /tmp/LAGOON_DEPLOYS_LOG_URL)
echo "Setting GH deployment status '$GH_DEPLOYMENT_ID': '$DEPLOYMENT_STATUS'"
# Setting the deployment status, on the GH deployment created earlier.
curl -L \
-X POST \
-H "Authorization: Bearer $GH_DEPLOYMENT_TOKEN" \
https://api.github.com/repos/danskernesdigitalebibliotek/dpl-cms/deployments/$GH_DEPLOYMENT_ID/statuses \
-d "{\"environment\":\"$LAGOON_PR_HEAD_BRANCH\",\"state\":\"$DEPLOYMENT_STATUS\", \"target_url\":\"$DRUPAL_URL\"}"
-d "{\"environment\":\"$LAGOON_ENVIRONMENT\",\"state\":\"$DEPLOYMENT_STATUS\", \
\"environment_url\":\"$DRUPAL_URL\", \"log_url\":\"$LAGOON_DEPLOYS_LOG_URL\"}"
service: cli

environments:
Expand Down
3 changes: 2 additions & 1 deletion dev-scripts/lagoon-error-handling.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
error_handler() {
DEPLOYMENT_STATUS="failure"
GH_DEPLOYMENT_ID=$(cat /tmp/gh_deployment_id)
LAGOON_DEPLOYS_LOG_URL=$(cat /tmp/LAGOON_DEPLOYS_LOG_URL)
echo "Setting GH deployment status '$GH_DEPLOYMENT_ID': '$DEPLOYMENT_STATUS'"

curl -L \
-X POST \
-H "Authorization: Bearer $GH_DEPLOYMENT_TOKEN" \
https://api.github.com/repos/danskernesdigitalebibliotek/dpl-cms/deployments/"$GH_DEPLOYMENT_ID"/statuses \
-d "{\"environment\":\"$LAGOON_PR_HEAD_BRANCH\",\"state\":\"$DEPLOYMENT_STATUS\"}"
-d "{\"environment\":\"$LAGOON_ENVIRONMENT\",\"log_url\":\"$LAGOON_DEPLOYS_LOG_URL\",\"state\":\"$DEPLOYMENT_STATUS\"}"

# As we've gotten rid of set -e in lagoon.yml, it is very important to exit
# here, otherwise, lagoon will think a faulty deploy has succeeded.
Expand Down

0 comments on commit fbd530d

Please sign in to comment.