-
Notifications
You must be signed in to change notification settings - Fork 0
201 lines (174 loc) · 7.02 KB
/
ci.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
name: CI
on:
# We use a `vX.Y` branch naming convention for our "main" branches, so we'll target pushes against those (including
# merged PRs)
push:
branches:
- v*
- ci-test*
# Additionally, we'll target PR updates so that CI runs against open PRs
pull_request:
types:
- opened
- synchronize
- reopened
# Finally, we'll allow the workflow to be triggered manually
workflow_dispatch:
# Only one run at a time per ref
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true
jobs:
##
## PREPARE
##
get-deploy-env:
runs-on: ubuntu-latest
# Necessary for nrwl/nx-set-shas
permissions:
contents: 'read'
actions: 'read'
outputs:
node-version: ${{ steps.initial-vars.outputs.NODE_VERSION }}
pnpm-version: ${{ steps.initial-vars.outputs.PNPM_VERSION }}
affected-shas-base: ${{ steps.get-affected-sha-spread.outputs.base }}
affected-shas-head: ${{ steps.get-affected-sha-spread.outputs.head }}
pnpmFilter: ${{ steps.get-pnpm-params.outputs.pnpmFilter }}
pnpmIgnorePattern: ${{ steps.get-pnpm-params.outputs.pnpmIgnorePattern }}
allAppsJson: ${{ steps.get-all-pkgs.outputs.allAppsJson }}
allLibsJson: ${{ steps.get-all-pkgs.outputs.allLibsJson }}
affectedAppsJson: ${{ steps.get-affected-pkgs.outputs.affectedAppsJson }}
affectedLibsJson: ${{ steps.get-affected-pkgs.outputs.affectedLibsJson }}
deployable: ${{ steps.is-deployable.outputs.deployable }}
steps:
- name: Check out repo
uses: actions/checkout@v4
with:
fetch-depth: 0
# Output some initial variables that we'll need later
- name: Initial Vars
id: initial-vars
run: |
# Replace this with 'v1.x' or another branch to simulate a CI run on that branch
REFNAME=$GITHUB_REF_NAME
REFNAME=v1.x
echo "REFNAME=$REFNAME"
echo "REFNAME=$REFNAME" >> $GITHUB_ENV
# TODO: Implement more complex handling of default branch
BASEBRANCH="$(echo "$REFNAME" | grep -q '^v[0-9]+]\.' && echo $REFNAME || echo v1.x)"
echo "BASEBRANCH=$BASEBRANCH"
echo "BASEBRANCH=$BASEBRANCH" >> $GITHUB_ENV
NODE_VERSION="$(./scripts/.internal/getEngineVersion.js node)"
echo "NODE_VERSION=$NODE_VERSION"
echo "NODE_VERSION=$NODE_VERSION" >> $GITHUB_OUTPUT
PNPM_VERSION="$(./scripts/.internal/getEngineVersion.js pnpm)"
echo "PNPM_VERSION=$PNPM_VERSION"
echo "PNPM_VERSION=$PNPM_VERSION" >> $GITHUB_OUTPUT
# Output some info for debugging purposes
- name: Output Versions for Debugging
run: |
echo effective branch: $REFNAME
echo "git: $(git --version)"
echo "jq: $(jq --version)"
echo "docker: $(docker --version 2>/dev/null)"
# Install pnpm (we don't need the whole node setup and all the deps, so we're just doing a simple pnpm install here)
- name: Install pnpm
run: npm i -g pnpm@${{ steps.initial-vars.outputs.PNPM_VERSION }}
# This is what allows us not to have to run our linting and testing against all of our code
- name: Determine the spread of affected commits
id: get-affected-sha-spread
uses: nrwl/nx-set-shas@v4
with:
main-branch-name: ${{ env.BASEBRANCH }}
# Use our current info to get a pnpm filter and ignore pattern to use in future commands, as well as a list of
# affected apps and libs
- name: Get pnpm params
id: get-pnpm-params
run: ./.github/workflows/get-pnpm-params.sh
- name: Get list of all packages from the repo
id: get-all-pkgs
run: ./.github/workflows/get-all-pkgs.sh
- name: Get lists of affected libs and apps
id: get-affected-pkgs
run: ./.github/workflows/get-affected-pkgs.sh
env:
hasTopLevelChanges: ${{ steps.get-pnpm-params.outputs.hasTopLevelChanges }}
pnpmFilter: ${{ steps.get-pnpm-params.outputs.pnpmFilter }}
pnpmIgnorePattern: ${{ steps.get-pnpm-params.outputs.pnpmIgnorePattern }}
allAppsJson: ${{ steps.get-all-pkgs.outputs.allAppsJson }}
allLibsJson: ${{ steps.get-all-pkgs.outputs.allLibsJson }}
# Finally, determine whether the current branch is deployable
- name: Determine whether the current branch is deployable
id: is-deployable
run: |
deployable="$(echo "$REFNAME" | grep -Eq '^v[0-9]+\..+$' && [ '${{ steps.get-affected-pkgs.outputs.affectedAppsJson }}' != '[]' ] && echo "true" || echo "false")"
echo "deployable=$deployable"
echo "deployable=$deployable" >> $GITHUB_OUTPUT
##
## Run linting/typechecks/tests
##
check:
needs: [get-deploy-env]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-env
- name: ESLint Cache
uses: actions/cache@v3
with:
key: eslint-cache-${{ hashFiles('libs/**/*', 'apps/**/*', 'pnpm-lock.yaml') }}
restore-keys: |
eslint-cache-
path: |
./apps/*/node_modules/.cache/eslint-cache
./libs/*/node_modules/.cache/eslint-cache
- name: Jest Cache
uses: actions/cache@v3
with:
key: jest-cache-${{ env.BRANCH }}
restore-keys: |
jest-cache-
path: |
/tmp/jest_*
- name: Lint, Typecheck and Test
run: |
pnpm \
--parallel \
--filter="${{ needs.get-deploy-env.outputs.pnpmFilter }}" \
--changed-files-ignore-pattern="${{ needs.get-deploy-env.outputs.pnpmIgnorePattern }}" \
check
##
## Pre-Seed Docker Cache
##
# TODO: Figure out how to set up efficient docker layer caching so we can run
##
## Build and deploy services
##
build-and-deploy:
name: Build and Deploy ${{ matrix.service }}
needs: [get-deploy-env, check]
if: "!cancelled() && !failure() && needs.get-deploy-env.outputs.deployable == 'true'"
runs-on: ubuntu-latest
strategy:
matrix:
service: ${{ fromJson(needs.get-deploy-env.outputs.affectedAppsJson) }}
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-env
# TODO: Figure out how to set up pnpm cache for building docker containers
# - name: PNPM Cache for Docker
# uses: actions/cache@v3
# with:
# path: .pnpm-store
# key: ${{ runner.os }}-pnpm-store-${{ hashFiles('./pnpm-lock.yaml') }}
# restore-keys: |
# ${{ runner.os }}-pnpm-store-
# - name: Inject pnpm cache into Docker
# uses: reproducible-containers/[email protected]
# with:
# cache-source: .pnpm-store
# cache-target: /monorepo/.pnpm-store
- name: Build Container for ${{ matrix.service }}
run: pnpm --sequence --filter "${{ matrix.service }}" docker:build
# TODO: Deployment is highly dependent on your actual setup. Deferring on this for now.
# - name: Deploy