-
Notifications
You must be signed in to change notification settings - Fork 0
144 lines (122 loc) · 3.94 KB
/
build-n-publish.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
---
name: Build and Deploy
on:
workflow_dispatch:
inputs:
deploy-backend:
description: "Deploy Backend"
default: false
type: boolean
update-data:
description: "Update Data"
default: false
type: boolean
push:
branches:
- main
jobs:
setup:
name: Deploy Setup
runs-on: ubuntu-latest
outputs:
frontend-changed: ${{ steps.changes.outputs.frontend-changed }}
data-changed: ${{ steps.changes.outputs.data-changed }}
backend-changed: ${{ steps.changes.outputs.backend-changed }}
steps:
- name: Checkout
uses: actions/[email protected]
with:
fetch-depth: 0
- name: Detect Changes
id: changes
run: |
echo "## Deploy" >> $GITHUB_STEP_SUMMARY
echo "| project | deploying |" >> $GITHUB_STEP_SUMMARY
echo "| ------- | --------- |" >> $GITHUB_STEP_SUMMARY
monorepo_projects=( frontend backend data )
for i in "${monorepo_projects[@]}"
do
DIFF=$(git diff --name-only HEAD~1 -- $i/* | wc -l | xargs)
if [[ "$DIFF" != "0" ]]; then
echo "$i-changed=true" >> $GITHUB_OUTPUT
echo "| $i | :heavy_check_mark: |" >> $GITHUB_STEP_SUMMARY
else
echo "$i-changed=false" >> $GITHUB_OUTPUT
echo "| $i ||" >> $GITHUB_STEP_SUMMARY
fi
done
build-frontend:
name: Build Frontend
if: ${{ needs.setup.outputs.frontend-changed == 'true' || inputs.deploy-frontend }}
needs: [setup]
runs-on: ubuntu-latest
steps:
- name: Install Task
uses: arduino/[email protected]
with:
version: 3.x
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Checkout
uses: actions/[email protected]
- name: Set up Node
uses: actions/[email protected]
with:
cache: 'npm'
cache-dependency-path: 'frontend/package-lock.json'
node-version: '20'
- name: Install Dependencies
working-directory: frontend
run: npm ci
- name: Build Frontend
run: task build:frontend
build-n-deploy-data:
name: Build Data
if: ${{ needs.setup.outputs.data-changed == 'true' || inputs.update-data }}
needs: [setup]
runs-on: ubuntu-latest
steps:
- name: Install Task
uses: arduino/[email protected]
with:
version: 3.x
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Checkout
uses: actions/[email protected]
- name: Build data
run: task build:data
- name: Publish posts to R2
uses: cloudflare/[email protected]
with:
apiToken: ${{ secrets.CF_API_KEY }}
accountId: ${{ secrets.CF_ACCOUNT }}
command: r2 object put flinnlab-blog/posts.json --file ./dist/posts.json
- name: Publish RSS Feed to R2
uses: cloudflare/[email protected]
with:
apiToken: ${{ secrets.CF_API_KEY }}
accountId: ${{ secrets.CF_ACCOUNT }}
command: r2 object put flinnlab-blog/rss.xml --file ./dist/rss.xml
deploy-backend:
name: Deploy Backend
if: ${{ needs.setup.outputs.backend-changed == 'true' || inputs.deploy-backend }}
needs: [setup]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/[email protected]
- name: Set up Node
uses: actions/[email protected]
with:
cache: 'npm'
cache-dependency-path: 'backend/package-lock.json'
node-version: '18'
- name: Install Dependencies
working-directory: backend
run: npm ci
- name: Deploy Backend
uses: cloudflare/[email protected]
with:
apiToken: ${{ secrets.CF_API_KEY }}
accountId: ${{ secrets.CF_ACCOUNT }}
workingDirectory: backend
command: deploy --env production