-
Notifications
You must be signed in to change notification settings - Fork 0
152 lines (134 loc) · 5.36 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
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:
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 'v0.6.x' or another branch to simulate a CI run on that branch
REFNAME=$GITHUB_REF_NAME
#REFNAME=v0.7.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 v0.7.x)"
echo "BASEBRANCH=$BASEBRANCH"
echo "BASEBRANCH=$BASEBRANCH" >> $GITHUB_ENV
PNPM_VERSION="$(jq -r '.engines.pnpm' package.json)"
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: wymp/devops/actions/setup-node-pnpm@v1
- 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