ci: setup command dispatcher (#1759)
This commit is contained in:
parent
c033c68daa
commit
6e31dc0005
|
@ -0,0 +1,21 @@
|
|||
name: Command
|
||||
|
||||
on:
|
||||
issue_comment:
|
||||
types: [created]
|
||||
|
||||
jobs:
|
||||
dispatch:
|
||||
name: Dispatch
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Dispatch website preview
|
||||
uses: peter-evans/slash-command-dispatch@v3
|
||||
with:
|
||||
token: ${{ secrets.COMMAND_DISPATCH_TOKEN }}
|
||||
issue-type: pull-request
|
||||
dispatch-type: workflow
|
||||
commands: website-preview
|
||||
static-args: |
|
||||
pull-request-number=${{ github.event.issue.number }}
|
|
@ -1,8 +1,13 @@
|
|||
name: Website Preview
|
||||
|
||||
on:
|
||||
issue_comment:
|
||||
types: [created]
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
pull-request-number:
|
||||
description: "Pull request number from where the command was triggered"
|
||||
required: true
|
||||
type: string
|
||||
|
||||
pull_request_target:
|
||||
types: [closed]
|
||||
branches: [main]
|
||||
|
@ -18,28 +23,15 @@ env:
|
|||
|
||||
jobs:
|
||||
deploy:
|
||||
if: >
|
||||
github.event.issue.pull_request
|
||||
&& (
|
||||
github.event.comment.author_association == 'OWNER'
|
||||
|| github.event.comment.author_association == 'MEMBER'
|
||||
)
|
||||
&& startsWith(github.event.comment.body, '/deploy-website')
|
||||
if: github.event_name == 'workflow_dispatch'
|
||||
name: Deploy
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Notify deployment triggered
|
||||
uses: peter-evans/create-or-update-comment@v2
|
||||
with:
|
||||
issue-number: ${{ github.event.issue.number }}
|
||||
comment-id: ${{ github.event.comment.id }}
|
||||
reactions: "+1"
|
||||
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Checkout pull request
|
||||
run: hub pr checkout ${{ github.event.issue.number }}
|
||||
run: hub pr checkout ${{ github.event.inputs.pull-request-number }}
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
|
@ -53,7 +45,7 @@ jobs:
|
|||
- uses: actions/cache@v3
|
||||
with:
|
||||
path: website/.docusaurus
|
||||
key: docusaurus-main-pr-${{ github.event.issue.number }}
|
||||
key: docusaurus-main-pr-${{ github.event.inputs.pull-request-number }}
|
||||
restore-keys: |
|
||||
docusaurus-main-
|
||||
|
||||
|
@ -66,7 +58,7 @@ jobs:
|
|||
run: yarn build
|
||||
env:
|
||||
URL: ${{ env.PREVIEW_URL }}
|
||||
BASE_URL: ${{ env.PREVIEW_BASE_URL }}pr-${{ github.event.issue.number }}/
|
||||
BASE_URL: ${{ env.PREVIEW_BASE_URL }}pr-${{ github.event.inputs.pull-request-number }}/
|
||||
|
||||
- name: Deploy
|
||||
uses: peaceiris/actions-gh-pages@v3
|
||||
|
@ -74,33 +66,33 @@ jobs:
|
|||
external_repository: ${{ env.PREVIEW_EXTERNAL_REPOSITORY }}
|
||||
deploy_key: ${{ secrets.PREVIEW_DEPLOY_KEY }}
|
||||
publish_dir: website/build
|
||||
destination_dir: pr-${{ github.event.issue.number }}
|
||||
full_commit_message: "deploy: pr-${{ github.event.issue.number }}"
|
||||
destination_dir: pr-${{ github.event.inputs.pull-request-number }}
|
||||
full_commit_message: "deploy pr-${{ github.event.inputs.pull-request-number }}"
|
||||
keep_files: true
|
||||
|
||||
- name: Notify deployment succeeded
|
||||
if: ${{ success() }}
|
||||
uses: peter-evans/create-or-update-comment@v2
|
||||
with:
|
||||
issue-number: ${{ github.event.issue.number }}
|
||||
issue-number: ${{ github.event.inputs.pull-request-number }}
|
||||
body: |
|
||||
**:rocket: Preview deployment succeeded!**
|
||||
|
||||
Preview: ${{ env.PREVIEW_URL }}${{ env.PREVIEW_BASE_URL }}pr-${{ github.event.issue.number }}/
|
||||
Preview: ${{ env.PREVIEW_URL }}${{ env.PREVIEW_BASE_URL }}pr-${{ github.event.inputs.pull-request-number }}/
|
||||
Workflow: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
|
||||
|
||||
- name: Notify deployment failed
|
||||
if: ${{ failure() }}
|
||||
uses: peter-evans/create-or-update-comment@v2
|
||||
with:
|
||||
issue-number: ${{ github.event.issue.number }}
|
||||
issue-number: ${{ github.event.inputs.pull-request-number }}
|
||||
body: |
|
||||
**:boom: Preview deployment failed!**
|
||||
|
||||
Workflow: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
|
||||
|
||||
clean:
|
||||
if: github.event.action == 'closed'
|
||||
if: github.event_name == 'pull_request_target' && github.event.action == 'closed'
|
||||
name: Clean
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
|
@ -110,15 +102,9 @@ jobs:
|
|||
repository: ${{ env.PREVIEW_EXTERNAL_REPOSITORY }}
|
||||
ssh-key: ${{ secrets.PREVIEW_DEPLOY_KEY }}
|
||||
|
||||
- name: Clean preview
|
||||
run: |
|
||||
git config --local user.name 'github-actions[bot]'
|
||||
git config --local user.email 'github-actions[bot]@users.noreply.github.com'
|
||||
- name: Remove files
|
||||
run: rm -fR pr-${{ github.event.pull_request.number }}
|
||||
|
||||
rm -fR pr-${{ github.event.pull_request.number }}
|
||||
|
||||
if ! git diff-index --quiet HEAD --; then
|
||||
git add .
|
||||
git commit -m "clean: pr-${{ github.event.pull_request.number }}"
|
||||
git push
|
||||
fi
|
||||
- uses: endbug/add-and-commit@v9
|
||||
with:
|
||||
message: "clean pr-${{ github.event.pull_request.number }}"
|
Loading…
Reference in New Issue