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