Skip to content

Commit

Permalink
Add Github Deploy Notifications.
Browse files Browse the repository at this point in the history
  • Loading branch information
tpendragon committed Jun 15, 2024
1 parent 958cc53 commit 55b8e82
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion bin/deploy
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,21 @@
ENV=$1
BRANCH_NAME="${BRANCH:-main}"
REPOSITORY="${REPO:-dpul-collections}"
JOB_NAME="${JOBNAME:-dpulc}"
if [[ -z ${ENV} ]];
then
echo "Missing Environment. Command: BRANCH=main ./bin/deploy staging"
exit
fi
# Notify Github of Starting Deploy, Deploy, Notify Github of Ending Deploy
ssh -qtt [email protected] << EOF
DEPLOY_ID=\$(curl -X POST -H "Accept: application/vnd.github+json-H" -H "Content-Type: application/x-www-form-urlencoded" -H "Authorization: Bearer \$GITHUB_TOKEN" --data "{\"ref\":\"${BRANCH_NAME}\",\"description\":\"Deploy from Nomad script\", \"auto_merge\": false, \"environment\": \"${ENV}\", \"required_contexts\": [] }" "https://api.github.com/repos/pulibrary/${REPOSITORY}/deployments" | jq .id)
curl -s -X POST -H "Accept: application/vnd.github+json-H" -H "Content-Type: application/x-www-form-urlencoded" -H "Authorization: Bearer \$GITHUB_TOKEN" --data "{\"environment\":\"${ENV}\",\"state\":\"in_progress\",\"log_url\": \"https://nomad.lib.princeton.edu/ui/jobs/${JOB_NAME}-${ENV}\", \"description\":\"Deployment finished successfully.\"}" "https://api.github.com/repos/pulibrary/${REPOSITORY}/deployments/\$DEPLOY_ID/statuses"
clear
curl -s "https://raw.githubusercontent.com/pulibrary/${REPOSITORY}/${BRANCH_NAME}/config/deploy/${ENV}.hcl" | nomad job run -var "branch_or_sha=sha-$(git ls-remote https://github.com/pulibrary/${REPOSITORY}.git ${BRANCH_NAME} | awk '{ print substr($1,1,7) }')" - && logout
curl -s "https://raw.githubusercontent.com/pulibrary/${REPOSITORY}/${BRANCH_NAME}/config/deploy/${ENV}.hcl" | nomad job run -var "branch_or_sha=sha-$(git ls-remote https://github.com/pulibrary/${REPOSITORY}.git ${BRANCH_NAME} | awk '{ print substr($1,1,7) }')" -
curl -s -X POST -H "Accept: application/vnd.github+json-H" -H "Content-Type: application/x-www-form-urlencoded" -H "Authorization: Bearer \$GITHUB_TOKEN" --data "{\"environment\":\"${ENV}\",\"state\":\"success\",\"log_url\": \"https://nomad.lib.princeton.edu/ui/jobs/${JOB_NAME}-${ENV}\", \"description\":\"Deployment finished successfully.\"}" "https://api.github.com/repos/pulibrary/${REPOSITORY}/deployments/\$DEPLOY_ID/statuses" && logout
EOF

0 comments on commit 55b8e82

Please sign in to comment.