-
Notifications
You must be signed in to change notification settings - Fork 1
268 lines (223 loc) · 9.13 KB
/
ci.yaml
File metadata and controls
268 lines (223 loc) · 9.13 KB
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
name: CI
on:
push:
branches:
- main
- release-*
pull_request: {}
workflow_dispatch:
inputs:
version:
description: Package version (e.g. v0.1.0)
required: false
env:
NODE_VERSION: "24"
# These environment variables are important to the Crossplane CLI install.sh
# script. They determine what version it installs.
XP_CHANNEL: stable
XP_VERSION: current
# The OCI/Docker Repository to push our images to.
# By Default this points to Github Package Registry.
XPKG_REPO: ghcr.io/${{ github.repository_owner }}
# To push to Upbound marketplace.
#XPKG_REPO: xpkg.upbound.io/${{ github.repository_owner }}
# Names for the Configuration and corresponding Function Packages
XPKG_NAME: configuration-template-typescript
# The function package name. We can use the repo name.
XPKG_FN_NAME: ${{ github.event.repository.name }}
jobs:
# Compute the package version once and share it with all jobs that need it
version:
runs-on: &default-runner ubuntu-24.04
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- name: Checkout
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
with:
fetch-depth: 0
- name: Setup Node
uses: actions/setup-node@v6
with:
node-version: ${{env.NODE_VERSION}}
# If a version wasn't explicitly passed as a workflow_dispatch input we
# default to version $(npm pkg get version)-<git-commit-date>-<git-short-sha>, for example
# v0.1.1-20231101115142-1091066df799. This is a simple implementation of
# Go's pseudo-versions: https://go.dev/ref/mod#pseudo-versions.
- name: Compute Package Version
id: version
run: |
if [ -n "${{ inputs.version }}" ]; then
VERSION="${{ inputs.version }}"
else
VERSION="v$(npm pkg get version | tr -d '"')-$(date -d@$(git show -s --format=%ct) +%Y%m%d%H%M%S)-$(git rev-parse --short=12 HEAD)"
fi
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "Computed version: ${VERSION}"
lint:
runs-on: *default-runner
steps:
- name: Checkout
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
- name: Install
uses: actions/setup-node@v6
with:
node-version: ${{env.NODE_VERSION}}
- run: npm ci
- name: Lint
run: npm run lint
test:
runs-on: *default-runner
steps:
- name: Checkout
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
- name: Install
uses: actions/setup-node@v6
with:
node-version: ${{env.NODE_VERSION}}
- run: npm ci
- name: test
run: npm test
check-types:
runs-on: *default-runner
steps:
- name: Checkout
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
- name: Setup Node
uses: actions/setup-node@v6
with:
node-version: ${{env.NODE_VERSION}}
- run: npm ci
- name: Check Types
run: npm run check-types
# Build the OCI image for the configuration.
build-configuration-package:
runs-on: *default-runner
needs:
- version
- check-types
outputs:
configuration_xpkg: ${{ steps.save-configuration-package-name.outputs.configuration_xpkg }}
steps:
- name: Checkout
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
- name: Setup the Crossplane CLI
uses: crossplane-contrib/setup-crossplane-action@cb8aac3f1246b19f101e7f85fd0a38623b4d5ad3 #v0.1.1
with:
version: ${{env.XP_VERSION}}
- name: Build the Configuration Package
run: crossplane xpkg build --package-root="package-configuration" --examples-root="examples" -o ${{env.XPKG_NAME}}-${{needs.version.outputs.version}}.xpkg
- name: Save the Configuration package name
id: save-configuration-package-name
run: |
CONFIGURATION_XPKG=${{env.XPKG_NAME}}-${{needs.version.outputs.version}}.xpkg
echo "configuration_xpkg=${CONFIGURATION_XPKG}" >> $GITHUB_OUTPUT
echo "Configuration Package: ${CONFIGURATION_XPKG}"
- name: Upload Single-Platform Package
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6
with:
name: configuration-xpkg
path: ${{env.XPKG_NAME}}-${{needs.version.outputs.version}}.xpkg
if-no-files-found: error
retention-days: 1
# Build OCI images for the function
build-function-packages:
needs:
- version
- check-types
runs-on: *default-runner
strategy:
fail-fast: true
matrix:
arch:
- amd64
- arm64
steps:
- name: Setup QEMU
uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3
with:
platforms: all
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3
- name: Checkout
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
# We ask Docker to use GitHub Action's native caching support to speed up
# the build, per https://docs.docker.com/build/cache/backends/gha/.
- name: Build Runtime
id: image
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6
with:
context: .
platforms: linux/${{ matrix.arch }}
cache-from: type=gha
cache-to: type=gha,mode=max
target: image
outputs: type=docker,dest=${{env.XPKG_FN_NAME}}-runtime-${{ matrix.arch }}-${{needs.version.outputs.version}}.tar
- name: Setup the Crossplane CLI
uses: crossplane-contrib/setup-crossplane-action@cb8aac3f1246b19f101e7f85fd0a38623b4d5ad3 #v0.1.1
with:
version: ${{env.XP_VERSION}}
- name: Build Package
run: |
crossplane xpkg build --embed-runtime-image-tarball=${{env.XPKG_FN_NAME}}-runtime-${{ matrix.arch }}-${{needs.version.outputs.version}}.tar \
--package-root="package-function" \
-o ${{env.XPKG_FN_NAME}}-${{ matrix.arch }}-${{needs.version.outputs.version}}.xpkg
- name: Upload Single-Platform Package
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6
with:
name: function-package-${{ matrix.arch }}
path: ${{env.XPKG_FN_NAME}}-${{ matrix.arch }}-${{needs.version.outputs.version}}.xpkg
if-no-files-found: error
retention-days: 1
# This job downloads the single-platform packages built by the build job, and
# pushes them as a multi-platform package. We only push the package it the
# XPKG_ACCESS_ID and XPKG_TOKEN secrets were provided.
push:
permissions:
contents: read
packages: write
runs-on: *default-runner
needs:
- version
- lint
- test
- build-function-packages
- build-configuration-package
steps:
- name: Checkout
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
- name: Download Single-Platform Packages
uses: actions/download-artifact@v6
with:
path: .
merge-multiple: true
pattern: "!*.dockerbuild" # This gets uploaded by docker/build-push-action but must be skipped: https://github.com/actions/toolkit/pull/1874
- name: Setup the Crossplane CLI
uses: crossplane-contrib/setup-crossplane-action@cb8aac3f1246b19f101e7f85fd0a38623b4d5ad3 #v0.1.1
with:
version: ${{env.XP_VERSION}}
- name: Login to GitHub Container Registry
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef #v3.6.0
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push Multi-Platform Function Packages to Repository
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
run: |
FN_XPKG_FILES=$(echo "${{env.XPKG_FN_NAME}}"-*-${{needs.version.outputs.version}}.xpkg | tr ' ' ',')
if [ -z "${FN_XPKG_FILES}" ] || [ "${FN_XPKG_FILES}" = "${{env.XPKG_FN_NAME}}-*-${{needs.version.outputs.version}}.xpkg" ]; then
echo "Error: No xpkg files found matching pattern"
exit 1
fi
crossplane --verbose xpkg push --package-files ${FN_XPKG_FILES} ${XPKG_REPO@L}/${{env.XPKG_FN_NAME}}:${{needs.version.outputs.version}}
- name: Push Configuration Package to Repository
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
run: |
CONF_XPKG_FILE="${{env.XPKG_NAME}}-${{needs.version.outputs.version}}.xpkg"
if [ ! -f "${CONF_XPKG_FILE}" ]; then
echo "Error: Configuration package ${CONF_XPKG_FILE} not found"
exit 1
fi
crossplane --verbose xpkg push --package-files ${CONF_XPKG_FILE} ${XPKG_REPO@L}/${{env.XPKG_NAME}}:${{needs.version.outputs.version}}