forked from OpenStackweb/summit-admin
-
Notifications
You must be signed in to change notification settings - Fork 4
87 lines (78 loc) · 2.73 KB
/
Copy pathdeploy-preview.yml
File metadata and controls
87 lines (78 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
name: Deploy Preview
on:
issue_comment:
types: [created]
jobs:
deploy:
if: |
github.event.issue.pull_request &&
github.event.comment.body == '/deploy-preview' &&
contains(fromJSON('["OWNER", "MEMBER", "COLLABORATOR"]'), github.event.comment.author_association)
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
issues: write
steps:
- name: React to /deploy-preview comment
uses: actions/github-script@v7
with:
script: |
github.rest.reactions.createForIssueComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: context.payload.comment.id,
content: 'eyes'
});
- name: Get PR head SHA
id: pr
uses: actions/github-script@v7
with:
script: |
const pr = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
});
const sameRepo =
pr.data.head.repo &&
pr.data.head.repo.full_name === `${context.repo.owner}/${context.repo.repo}`;
if (!sameRepo) {
core.setFailed('Refusing to deploy a preview for a fork-originating (or deleted-fork) PR.');
return;
}
core.setOutput('sha', pr.data.head.sha);
- uses: actions/checkout@v4
with:
ref: ${{ steps.pr.outputs.sha }}
- uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
cache: "yarn"
- name: Create .env
env:
ENV_FILE: ${{ secrets.ENV_FILE }}
run: printf '%s\n' "$ENV_FILE" > .env
- name: Install & Build
run: |
yarn install
yarn build
env:
CI: false
- name: Add SPA fallback redirect
run: echo "/* /index.html 200" > dist/_redirects
- name: Deploy to Netlify
id: netlify
uses: nwtgck/actions-netlify@4cbaf4c08f1a7bfa537d6113472ef4424e4eb654 # v3
with:
publish-dir: ./dist
github-token: ${{ secrets.GITHUB_TOKEN }}
deploy-message: "PR #${{ github.event.issue.number }}"
# Until FNid allows wildcards in its redirect URIs / JavaScript origins we
# can only have 1 deploy url and deploy 1 PR at a time.
# After that change each pr-<number>--show-admin-preview.netlify.app can complete the OAuth callback.
alias: pr-${{ github.event.issue.number }}
#alias: pr
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}