-
Notifications
You must be signed in to change notification settings - Fork 199
162 lines (150 loc) · 5.48 KB
/
build.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: Validate successful build
#
# This workflow validates that the commit in question can be built successfully
# in several environments:
#
# Systems: Ubuntu, MacOS, // Windows
# Node: 20
#
# After the build is successful, the compiled assets are uploaded as an artifact
# to the workflow run. This allows us to download the compiled assets and use
# them in other workflows.
#
# Note: we need to skip the nx cache b/c it does not contain the compiled assets
#
on:
workflow_dispatch:
inputs:
system:
required: false
default: "macos-latest"
node-version:
required: false
default: "20"
experimental:
required: false
default: "false"
ref:
description: "The branch or tag to checkout"
required: false
workflow_call:
inputs:
system:
required: false
type: string
default: "macos-latest"
node-version:
required: false
type: string
default: "20"
experimental:
required: false
type: boolean
default: false
ref:
description: "The branch or tag to checkout"
required: false
type: string
default: ${{ github.head_ref }}
outputs:
artifact-id:
value: ${{ jobs.build.outputs.artifact-id }}
permissions:
contents: read
pull-requests: write
jobs:
# ---------- Validate build for various environments ---------- #
build:
strategy:
fail-fast: false
matrix:
system:
- ${{ inputs.system }}
node-version:
- ${{ inputs.node-version }}
experimental:
- ${{ inputs.experimental }}
runs-on: ${{ matrix.system }}
continue-on-error: ${{ matrix.experimental }}
timeout-minutes: 10
outputs:
artifact-id: ${{ steps.upload.outputs.artifact-id }}
name: Build
steps:
- name: Set the cache key for builds
id: derive-key
shell: bash
run: |
BRANCH=${{ inputs.ref || github.head_ref }}
BRANCH=${BRANCH//\//_}
echo "key=${{ matrix.system }}-node${{ matrix.node-version }}-compiled-assets-${BRANCH}" >> "$GITHUB_OUTPUT"
- name: Check out code
uses: actions/checkout@v4
with:
ref: ${{ inputs.ref || github.head_ref }}
fetch-depth: 0
- name: Use Node LTS version
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: yarn
- name: Enable Corepack
run: corepack enable
## --- YARN CACHE --- ##
- name: Check for cached dependencies
continue-on-error: true
id: cache-dependencies
uses: actions/cache@v4
with:
path: |
.cache/yarn
node_modules
key: ${{ matrix.system }}-node${{ matrix.node-version }}-${{ hashFiles('yarn.lock') }}
## --- INSTALL --- ##
# If statement isn't needed here b/c yarn will leverage the cache if it exists
- name: Install dependencies
shell: bash
run: yarn install --immutable
## --- BUILD --- ##
- name: Build components & ui-icons
shell: bash
run: yarn ci
## --- UPLOAD (only ubuntu-latest at the moment) --- ##
- name: Upload compiled assets & NX performance profile
continue-on-error: true
id: upload
if: ${{ matrix.system == 'ubuntu-latest' }}
uses: actions/upload-artifact@v4
with:
path: |
${{ github.workspace }}/components/*/dist/**
${{ github.workspace }}/tokens/dist/**
${{ github.workspace }}/ui-icons/dist/**
${{ github.workspace }}/profile.json
name: ${{ steps.derive-key.outputs.key }}
# this is important, it lets us catch if the build failed silently
# by alterting us that no compiled assets were generated
if-no-files-found: error
retention-days: 5
overwrite: true
# This step will evaluate the repo status and report the change
# If there are changes, capture the changes and upload them as an artifact
- name: Check if there are changes
shell: bash
run: |
if [[ -z $(git status --porcelain) ]]; then
echo "No changes detected"
exit 0
else
echo "Changes detected"
git status
git add .
git diff > changes.diff
exit 1
fi
- name: Upload changes
if: ${{ failure() }}
uses: actions/upload-artifact@v4
with:
path: changes.diff
name: changes.diff