element-plus/.github/workflows/preview-deploy.yml

81 lines
2.8 KiB
YAML
Raw Normal View History

# This workflow runs on target, so there is no need to worry about secrets
name: Website Preview Deploy
on:
workflow_run:
workflows: ['Website Preview']
types: [completed]
jobs:
# Build successfully, start deployment
on-success:
name: Build successfully
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: Download pr number
uses: dawidd6/action-download-artifact@v2
with:
workflow: ${{ github.event.workflow_run.workflow_id }}
name: pr
- name: Output pr number
id: pr
run: echo "::set-output name=id::$(<pr.txt)"
- name: Download artifact
uses: dawidd6/action-download-artifact@v2
with:
workflow: ${{ github.event.workflow_run.workflow_id }}
workflow_conclusion: success
name: website
- name: Deploy Site
run: |
export DEPLOY_DOMAIN=https://preview-${PULL_REQUEST_NUMBER}-element-plus.surge.sh
echo "Deploy to $DEPLOY_DOMAIN"
npx surge --project ./ --domain $DEPLOY_DOMAIN --token $SURGE_TOKEN
env:
SURGE_TOKEN: ${{ secrets.SURGE_TOKEN }}
PULL_REQUEST_NUMBER: ${{ steps.pr.outputs.id }}
- name: Deploy has succeeded
if: ${{ success() }}
run: |
export DEPLOY_DOMAIN=https://preview-${PULL_REQUEST_NUMBER}-element-plus.surge.sh
curl -X POST ${BOT_URL} -H 'Content-Type:application/json' --data-raw '{"botAction":"Preview", "pr":'${PULL_REQUEST_NUMBER}', "url":"'${DEPLOY_DOMAIN}'"}'
env:
BOT_URL: ${{ secrets.BOT_URL }}
PULL_REQUEST_NUMBER: ${{ steps.pr.outputs.id }}
- name: Deploy has failed
if: ${{ failure() }}
run: |
curl -X POST ${BOT_URL} -H 'Content-Type:application/json' --data-raw '{"status":"error", "botAction":"Preview", "pr":'${PULL_REQUEST_NUMBER}'}'
env:
BOT_URL: ${{ secrets.BOT_URL }}
PULL_REQUEST_NUMBER: ${{ steps.pr.outputs.id }}
# Build failed, update comment
on-failure:
name: Build failed
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
steps:
- name: Download pr number
uses: dawidd6/action-download-artifact@v2
with:
workflow: ${{ github.event.workflow_run.workflow_id }}
name: pr
- name: Output pr number
id: pr
run: echo "::set-output name=id::$(<pr.txt)"
- name: Update comment
run: |
curl -X POST ${BOT_URL} -H 'Content-Type:application/json' --data-raw '{"status":"error", "botAction":"Preview", "pr":'${PULL_REQUEST_NUMBER}'}'
env:
BOT_URL: ${{ secrets.BOT_URL }}
PULL_REQUEST_NUMBER: ${{ steps.pr.outputs.id }}