-
Notifications
You must be signed in to change notification settings - Fork 3
143 lines (135 loc) · 4.41 KB
/
monorepo-deploy.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
name: Monorepo Deploy Pipeline
on:
pull_request:
push:
branches:
- main
schedule:
# Scheduled build so pipeline failures are noticed quicker.
- cron: "30 4 * * 1,3,5,0"
jobs:
prepare:
name: "Prepare (Find Projects, Warm dependency caches)"
runs-on: ubuntu-latest
outputs:
projects: ${{ steps.find-projects.outputs.projects }}
steps:
- uses: actions/checkout@main
with:
fetch-depth: 10
- uses: pnpm/action-setup@v4
name: Install pnpm
with:
version: 8
run_install: false
- uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
cache: "pnpm"
- name: Install Dependencies
run: |
rm services/personal-website/package.json
pnpm install --ignore-scripts --prod=false
- id: find-projects
name: Find affected projects
run: |
lerna_args=()
lerna_args+=('--all')
lerna_args+=('--loglevel silent')
lerna_args+=('--ignore @alexwilson/personal-website')
# Lerna attempts to find any changed packages since the last update...
if [[ $(pnpx lerna list ${lerna_args[@]} --since $MAIN_BRANCH | head -c1 | wc -c) -ne 0 ]]; then
# If there are some, and this isn't a scheduled build, we prefer to test
# and deploy only the updated packages.
# Scheduled builds always update & deploy everything.
if [ $GITHUB_EVENT_NAME != 'schedule' ]; then
lerna_args+=("--since $MAIN_BRANCH")
fi
fi
# Finally - we're ready to output as JSON for JQ to consume
lerna_args+=('--json')
echo "Github Event: $GITHUB_EVENT_NAME"
echo "$ pnpx lerna list ${lerna_args[@]}"
echo "$ jq ${jq_args[@]}"
echo "$ echo projects=$( \
pnpx lerna list ${lerna_args[@]} \
| jq -rjc -n '.include |= inputs' \
) >> \$GITHUB_OUTPUT"
echo "projects=$( \
pnpx lerna list ${lerna_args[@]} \
| jq -rjc -n '.include |= inputs' \
)" >> $GITHUB_OUTPUT
env:
MAIN_BRANCH: "main"
# Fetch dependencies and build Gatsby
test:
needs: [prepare]
name: Test ${{ matrix.name }}
runs-on: ubuntu-latest
env:
NODE_ENV: ${{ secrets.NODE_ENV }}
strategy:
matrix: ${{ fromJson(needs.prepare.outputs.projects) }}
steps:
- name: Checkout
uses: actions/checkout@main
with:
fetch-depth: 1
- uses: pnpm/action-setup@v4
name: Install pnpm
with:
version: 8
run_install: false
- uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
cache: "pnpm"
- name: Install Dependencies
run: |
rm services/personal-website/package.json
pnpm install --ignore-scripts --prod=false
- name: Test
run: pnpx lerna run test --scope ${{ matrix.name }}
tests-passed:
name: Tests Passed
needs: [test]
runs-on: ubuntu-latest
steps:
- run: echo "👍"
deploy:
strategy:
matrix: ${{ fromJson(needs.prepare.outputs.projects) }}
name: Deploy ${{ matrix.name }}
needs: [prepare, tests-passed]
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request'
env:
NODE_ENV: ${{ secrets.NODE_ENV }}
steps:
- name: Checkout
uses: actions/checkout@main
with:
fetch-depth: 1
- uses: pnpm/action-setup@v4
name: Install pnpm
with:
version: 8
run_install: false
- uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
cache: "pnpm"
- name: Install Dependencies
run: |
rm services/personal-website/package.json
pnpm install --ignore-scripts --prod=false
- name: Deploy
run: pnpx lerna run deploy --scope ${{ matrix.name }}
env:
CI: true
CF_ZONE_ID: ${{ secrets.CF_ZONE_ID }}
CF_ACCOUNT_ID: ${{ secrets.CF_ACCOUNT_ID }}
CF_API_TOKEN: ${{ secrets.CF_API_TOKEN }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: "eu-west-1"