Merge pull request #798 from goplus/dev #6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Release | |
on: | |
push: | |
branches: | |
- main | |
workflow_dispatch: | |
jobs: | |
deploy-spx-backend: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Determine GOPLUS_DEPLOY_GIT_REF | |
run: | | |
GOPLUS_DEPLOY_GIT_REF=${GITHUB_SHA} | |
if [ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" ]; then | |
GOPLUS_DEPLOY_GIT_REF=main | |
fi | |
echo "GOPLUS_DEPLOY_GIT_REF=${GOPLUS_DEPLOY_GIT_REF}" >> ${GITHUB_ENV} | |
- name: Deploy | |
env: | |
GOPLUS_DEPLOY_TOKEN: ${{ secrets.GOPLUS_DEPLOY_TOKEN }} | |
run: | | |
HTTP_RESPONSE=$(curl -fsSL -X POST https://deploy.goplus.org/qpass-deploy-pkg \ | |
-H "Authorization: Bearer ${GOPLUS_DEPLOY_TOKEN}" \ | |
-H "Content-Type: application/json; charset=utf-8" \ | |
-d '{"business": "goPlus", "app_name": "builder", "git_tag": "'"${GOPLUS_DEPLOY_GIT_REF}"'"}') | |
echo "Deploy response: $HTTP_RESPONSE" | |
GOPLUS_DEPLOY_ID=$(echo ${HTTP_RESPONSE} | jq -r '.content.deploy.deployId') | |
echo "GOPLUS_DEPLOY_ID=${GOPLUS_DEPLOY_ID}" >> ${GITHUB_ENV} | |
- name: Poll deployment status | |
env: | |
GOPLUS_DEPLOY_TOKEN: ${{ secrets.GOPLUS_DEPLOY_TOKEN }} | |
run: | | |
DEADLINE=$((SECONDS+3600)) # 1 hour timeout | |
while [[ ${SECONDS} -lt ${DEADLINE} ]]; do | |
HTTP_RESPONSE=$(curl -fsSL https://deploy.goplus.org/qpass-deploy-pkg/${GOPLUS_DEPLOY_ID} \ | |
-H "Authorization: Bearer ${GOPLUS_DEPLOY_TOKEN}") | |
GOPLUS_DEPLOY_STATUS=$(echo ${HTTP_RESPONSE} | jq -r '.content.deploy_data.status') | |
if [[ "${GOPLUS_DEPLOY_STATUS}" == "成功" ]]; then | |
exit 0 | |
elif [[ "${GOPLUS_DEPLOY_STATUS}" == "失败" ]]; then | |
echo "Deployment failed!" | |
exit 1 | |
fi | |
sleep 60 # 1 minute polling interval | |
done | |
echo "Deployment polling timed out!" | |
exit 1 |