-
Notifications
You must be signed in to change notification settings - Fork 32
162 lines (158 loc) · 5.83 KB
/
deploy-preview-to-firebase-hosting.yml
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
name: Deploy Preview to Firebase Hosting
on:
pull_request:
branches:
- master
types:
- opened
- synchronize
env:
NODE_VERSION: 20
PREVIEW_EXPIRES: 7d
WORKING_DIRECTORY: "2024"
jobs:
build:
runs-on: ubuntu-latest
steps:
# https://github.com/actions/checkout
- uses: actions/checkout@v4
# https://github.com/actions/setup-node
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: npm
cache-dependency-path: ${{ env.WORKING_DIRECTORY }}/package-lock.json
- name: npm ci
run: npm ci --production
working-directory: ${{ env.WORKING_DIRECTORY }}
- name: npm run build
run: npm run build
working-directory: ${{ env.WORKING_DIRECTORY }}
# https://github.com/actions/upload-artifact
- uses: actions/upload-artifact@v4
with:
name: public_${{ github.sha }}
path: ${{ env.WORKING_DIRECTORY }}/public/*
retention-days: 1
lint:
runs-on: ubuntu-latest
needs:
- build
steps:
# https://github.com/actions/checkout
- uses: actions/checkout@v4
# https://github.com/actions/setup-node
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: npm
cache-dependency-path: ${{ env.WORKING_DIRECTORY }}/package-lock.json
# https://github.com/actions/download-artifact
- uses: actions/download-artifact@v4
with:
name: public_${{ github.sha }}
path: ${{ env.WORKING_DIRECTORY }}/public
- name: npm ci
run: npm ci
working-directory: ${{ env.WORKING_DIRECTORY }}
- name: npm run lint
run: npm run lint
working-directory: ${{ env.WORKING_DIRECTORY }}
deploy:
runs-on: ubuntu-latest
needs:
- lint
steps:
# https://github.com/actions/checkout
- uses: actions/checkout@v4
# https://github.com/actions/setup-node
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: npm
cache-dependency-path: ${{ env.WORKING_DIRECTORY }}/package-lock.json
# https://github.com/actions/download-artifact
- uses: actions/download-artifact@v4
with:
name: public_${{ github.sha }}
path: ${{ env.WORKING_DIRECTORY }}/public
# https://github.com/google-github-actions/auth
- uses: google-github-actions/auth@v2
with:
create_credentials_file: true
credentials_json: ${{ secrets.GOOGLE_CREDENTIALS }}
- name: npm install
run: npm install -g firebase-tools@$(node -p -e "require('./${{ env.WORKING_DIRECTORY }}/package.json').devDependencies['firebase-tools']")
- name: firebase hosting:channel:create
run: |
channel=$(echo ${{ github.head_ref }} | tr _ -)
firebase hosting:channel:create ${channel}
continue-on-error: true
working-directory: ${{ env.WORKING_DIRECTORY }}
- name: firebase hosting:channel:open
id: firebase_hosting_channel_open
run: |
channel=$(echo ${{ github.head_ref }} | tr _ -)
url=$(firebase hosting:channel:open ${channel} | awk '{ print $3 }')
echo "url=${url}" >> ${GITHUB_OUTPUT}
working-directory: ${{ env.WORKING_DIRECTORY }}
- name: sed
env:
URL: ${{ steps.firebase_hosting_channel_open.outputs.url }}
run: sed -i -e "s|https://ntt-developers.github.io/ntt-tech-conference/${{ env.WORKING_DIRECTORY }}|${URL}|g" public/index.html
working-directory: ${{ env.WORKING_DIRECTORY }}
- name: firebase hosting:channel:deploy
run: |
channel=$(echo ${{ github.head_ref }} | tr _ -)
firebase hosting:channel:deploy -e ${{ env.PREVIEW_EXPIRES }} ${channel}
working-directory: ${{ env.WORKING_DIRECTORY }}
notify:
runs-on: ubuntu-latest
needs:
- deploy
steps:
# https://github.com/actions/checkout
- uses: actions/checkout@v4
# https://github.com/actions/setup-node
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: npm
cache-dependency-path: ${{ env.WORKING_DIRECTORY }}/package-lock.json
# https://github.com/google-github-actions/auth
- uses: google-github-actions/auth@v2
with:
create_credentials_file: true
credentials_json: ${{ secrets.GOOGLE_CREDENTIALS }}
- name: npm install
run: npm install -g firebase-tools@$(node -p -e "require('./package.json').devDependencies['firebase-tools']")
- name: firebase hosting:channel:open
id: firebase_hosting_channel_open
run: |
channel=$(echo ${{ github.head_ref }} | tr _ -)
url=$(firebase hosting:channel:open ${channel} | awk '{ print $3 }')
echo "url=${url}" >> ${GITHUB_OUTPUT}
working-directory: ${{ env.WORKING_DIRECTORY }}
# https://github.com/actions/github-script
- uses: actions/github-script@v7
env:
URL: ${{ steps.firebase_hosting_channel_open.outputs.url }}
with:
script: |
const body = `Preview: ${process.env.URL}`
const options = github.rest.issues.listComments.endpoint.merge({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number
})
const comments = await github.paginate(options)
const comment = comments.find(c => c.body == body)
if (comment) {
return
}
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: body
})