Preview Deploy #890
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: Preview Deploy | |
on: | |
workflow_run: | |
workflows: [Preview Build] | |
types: | |
- completed | |
permissions: | |
contents: read | |
jobs: | |
deploy-site: | |
permissions: | |
actions: read # for dawidd6/action-download-artifact to query and download artifacts | |
issues: write # for actions-cool/maintain-one-comment to modify or create issue comments | |
pull-requests: write # for actions-cool/maintain-one-comment to modify or create PR comments | |
name: deploy preview | |
runs-on: ubuntu-latest | |
if: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' }} | |
steps: | |
# get PR id first | |
- name: Download pr artifact | |
uses: dawidd6/action-download-artifact@v2 | |
with: | |
workflow: ${{ github.event.workflow_run.workflow_id }} | |
run_id: ${{ github.event.workflow_run.id }} | |
name: pr | |
# save PR id to output | |
- name: Save PR id | |
id: pr | |
run: echo "::set-output name=id::$(<pr-id.txt)" | |
- name: Download site artifact | |
uses: dawidd6/action-download-artifact@v2 | |
with: | |
workflow: ${{ github.event.workflow_run.workflow_id }} | |
run_id: ${{ github.event.workflow_run.id }} | |
name: site | |
- name: Upload surge service | |
id: deploy | |
run: | | |
export DEPLOY_DOMAIN=https://preview-${{ steps.pr.outputs.id }}-oceanbase-design.surge.sh | |
npx surge --project ./ --domain $DEPLOY_DOMAIN --token ${{ secrets.SURGE_TOKEN }} | |
- name: Update status comment | |
uses: actions-cool/maintain-one-comment@v3 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
body: | | |
<a href="https://preview-${{ steps.pr.outputs.id }}-oceanbase-design.surge.sh" target="_blank"> | |
<img width="360" src="https://mdn.alipayobjects.com/huamei_n8rchn/afts/img/A*biIGSYhvfOQAAAAAAAAAAAAADvSFAQ/original"> | |
</a> | |
<!-- AUTO_PREVIEW_HOOK --> | |
body-include: '<!-- AUTO_PREVIEW_HOOK -->' | |
number: ${{ steps.pr.outputs.id }} | |
- name: The job has failed | |
if: ${{ failure() }} | |
uses: actions-cool/maintain-one-comment@v3 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
body: | | |
😭 Preview Deploy failed. | |
<img width="300" src="https://user-images.githubusercontent.com/507615/90250824-4e066700-de6f-11ea-8230-600ecc3d6a6b.png"> | |
<!-- AUTO_PREVIEW_HOOK --> | |
body-include: '<!-- AUTO_PREVIEW_HOOK -->' | |
number: ${{ steps.pr.outputs.id }} | |
build-site-failed: | |
permissions: | |
actions: read # for dawidd6/action-download-artifact to query and download artifacts | |
issues: write # for actions-cool/maintain-one-comment to modify or create issue comments | |
pull-requests: write # for actions-cool/maintain-one-comment to modify or create PR comments | |
name: build preview failed | |
runs-on: ubuntu-latest | |
if: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'failure' }} | |
steps: | |
# get PR id first | |
- name: Download pr artifact | |
uses: dawidd6/action-download-artifact@v2 | |
with: | |
workflow: ${{ github.event.workflow_run.workflow_id }} | |
run_id: ${{ github.event.workflow_run.id }} | |
name: pr | |
# Save PR id to output | |
- name: Save PR id | |
id: pr | |
run: echo "::set-output name=id::$(<pr-id.txt)" | |
- name: The job has failed | |
uses: actions-cool/maintain-one-comment@v3 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
body: | | |
<img width="534" src="https://user-images.githubusercontent.com/5378891/75333447-1e63a280-58c1-11ea-975d-235367fd1522.png"> | |
<!-- AUTO_PREVIEW_HOOK --> | |
body-include: '<!-- AUTO_PREVIEW_HOOK -->' | |
number: ${{ steps.pr.outputs.id }} |