PREVIEW #134
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 | |
on: | |
workflow_call: | |
secrets: | |
SURGE_TOKEN: | |
required: true | |
workflow_run: | |
workflows: ['TEST_BUILD'] | |
types: | |
- completed | |
jobs: | |
preview-success: | |
runs-on: ubuntu-latest | |
if: > | |
github.event.workflow_run.event == 'pull_request' && | |
github.event.workflow_run.conclusion == 'success' | |
steps: | |
- uses: actions/checkout@main | |
with: | |
repository: kongying-tavern/docs | |
- name: download pr artifact | |
uses: dawidd6/action-download-artifact@v6 | |
with: | |
workflow: ${{ github.event.workflow_run.workflow_id }} | |
run_id: ${{ github.event.workflow_run.id }} | |
name: pr | |
- name: save PR id | |
id: pr | |
run: echo "::set-output name=id::$(<pr-id.txt)" | |
- name: download _site artifact | |
uses: dawidd6/action-download-artifact@v6 | |
with: | |
workflow: ${{ github.event.workflow_run.workflow_id }} | |
run_id: ${{ github.event.workflow_run.id }} | |
name: _site | |
- run: | | |
unzip -o _site.zip | |
- name: Upload surge service and generate preview URL | |
id: deploy | |
run: | | |
repository=${{github.repository}} | |
project_name=${repository#*/} | |
export DEPLOY_DOMAIN=https://kongying-tavern-preview-pr${{ steps.pr.outputs.id }}-$project_name.surge.sh | |
npx surge --project ./dist --domain $DEPLOY_DOMAIN --token ${{ secrets.SURGE_TOKEN }} | |
echo the preview URL is $DEPLOY_DOMAIN | |
echo "::set-output name=url::$DEPLOY_DOMAIN" | |
- name: update status comment | |
uses: actions-cool/[email protected] | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
body: | | |
<a href="${{steps.deploy.outputs.url}}"><img alt="成功" src="https://assets.yuanshen.site/images/privew_is_ready_v1.png"></a> | |
${{ env.DIFFER_INFO }} | |
<!-- [工作流地址](${{github.server_url}}/${{github.repository}}/actions/runs/${{github.run_id}}) --> | |
<!-- AUTO_PREVIEW_HOOK --> | |
number: ${{ steps.pr.outputs.id }} | |
body-include: '<!-- AUTO_PREVIEW_HOOK -->' | |
- run: | | |
rm -rf _site/ | |
- name: The job failed | |
if: ${{ failure() }} | |
uses: actions-cool/[email protected] | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
body: | | |
[<img alt="失败" src="https://assets.yuanshen.site/images/privew_failed_v1.png">](${{github.server_url}}/${{github.repository}}/actions/runs/${{github.run_id}}) | |
<!-- AUTO_PREVIEW_HOOK --> | |
number: ${{ steps.pr.outputs.id }} | |
body-include: '<!-- AUTO_PREVIEW_HOOK -->' | |
preview-failed: | |
runs-on: ubuntu-latest | |
if: > | |
github.event.workflow_run.event == 'pull_request' && | |
github.event.workflow_run.conclusion == 'failure' | |
steps: | |
- name: download pr artifact | |
uses: dawidd6/action-download-artifact@v6 | |
with: | |
workflow: ${{ github.event.workflow_run.workflow_id }} | |
run_id: ${{ github.event.workflow_run.id }} | |
name: pr | |
- name: save PR id | |
id: pr | |
run: echo "::set-output name=id::$(<pr-id.txt)" | |
- name: The job failed | |
uses: actions-cool/[email protected] | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
body: | | |
[<img alt="失败" src="https://assets.yuanshen.site/images/privew_failed_v1.png">](${{github.server_url}}/${{github.repository}}/actions/runs/${{github.run_id}}) | |
<!-- AUTO_PREVIEW_HOOK --> | |
number: ${{ steps.pr.outputs.id }} | |
body-include: '<!-- AUTO_PREVIEW_HOOK -->' |