chore(ci): use publish previews for pull request target (#171)
Also always checkout main for everything else
Luke Karrys committed
Aug 11, 2022 at 16:59 UTC
155df31fd677735a67cd96dc3138d7a34b761932
2 files changed
+19
-54
.github/workflows/publish.yml
+19
-5
@@ -4,6 +4,7 @@ on:
4
push:
5
branches:
6
- main
7
+ pull_request_target:
8
workflow_dispatch:
9
workflow_call:
10
@@ -12,10 +13,21 @@ jobs:
13
permissions:
14
contents: read
15
runs-on: ubuntu-latest
16
+
17
steps:
16
- # Check out the content (source branch)
17
- - name: Check out source
18
+ - name: Checkout PR
19
+ if: ${{ github.event_name == 'pull_request_target' }}
20
+ uses: actions/checkout@v3
21
+ with:
22
+ ref: ${{ github.event.pull_request.head.ref }}
23
+ repository: ${{ github.event.pull_request.head.repo.full_name }}
24
+
25
+ - name: Checkout
26
+ if: ${{ github.event_name != 'pull_request_target' }}
27
uses: actions/checkout@v3
28
+ with:
29
+ ref: main
30
+
31
- name: Setup Pages
32
uses: actions/configure-pages@v1
33
- name: Use Node.js
@@ -46,6 +58,8 @@ jobs:
58
runs-on: ubuntu-latest
59
needs: build-and-upload
60
steps:
49
- - name: Deploy to GitHub Pages
50
- id: deployment
51
- uses: actions/deploy-pages@v1
61
+ - name: Deploy to GitHub Pages
62
+ id: deployment
63
+ uses: paper-spa/deploy-pages@main
64
+ with:
65
+ preview: ${{ github.event_name == 'pull_request_target' }}
.github/workflows/stage-pull-request.yml
deleted
-49
@@ -1,49 +0,0 @@
1
-name: Stage Pull Request
2
-
3
-on:
4
- pull_request_target:
5
- types: [opened, synchronize, reopened, closed]
6
- workflow_dispatch:
7
- inputs:
8
- pr_number:
9
- description: 'Pull Request Number'
10
- required: true
11
-
12
-env:
13
- staging_repo: 'npm/docs-staging'
14
-
15
-jobs:
16
- stage_pr:
17
- runs-on: ubuntu-latest
18
- steps:
19
- - name: Dump GitHub context
20
- env:
21
- GITHUB_CONTEXT: ${{ toJSON(github) }}
22
- run: echo "$GITHUB_CONTEXT"
23
- - name: Identify pull request
24
- id: pull_request
25
- run: |
26
- NOTIFY="false"
27
-
28
- if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
29
- PR_NUMBER="${{ github.event.inputs.pr_number }}"
30
- elif [ "${{ github.event_name }}" = "pull_request_target" ]; then
31
- PR_NUMBER="${{ github.event.pull_request.number }}"
32
-
33
- if [ "${{github.event.action}}" = "opened" ]; then
34
- NOTIFY="true"
35
- fi
36
- fi
37
-
38
- if [ "$PR_NUMBER" = "" ]; then
39
- echo "::error::Unknown event type or unset pull request number"
40
- exit 1
41
- fi
42
-
43
- echo "Building pull request ${PR_NUMBER}"
44
-
45
- curl -f -X POST -u ":${{ secrets.DOCS_STAGING_DISPATCH_TOKEN }}" \
46
- -H "Accept: application/vnd.github.everest-preview+json" \
47
- -H "Content-Type: application/json" \
48
- --data "{ \"event_type\": \"publish_pr\", \"client_payload\": { \"pr_number\":\"$PR_NUMBER\", \"notify\":\"$NOTIFY\" } }" \
49
- https://api.github.com/repos/${{ env.staging_repo }}/dispatches