Skip to content

PREVIEW

PREVIEW #110

Workflow file for this run

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: Cache pnpm modules
uses: actions/cache@v2
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-
- name: Install dependencies
uses: pnpm/action-setup@v4
with:
run_install: true
# 构建
- name: Build
run: pnpm vitepress build --outDir _dist --base /
- 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 -->'