11name : CI
22
3- # on:
4- # push:
5- # branches:
6- # - main
7- # - release-*
8- # pull_request: {}
9- # workflow_dispatch:
10- # inputs:
11- # version:
12- # description: Package version (e.g. v0.1.0)
13- # required: false
3+ on :
4+ push :
5+ branches :
6+ - main
7+ - release-*
8+ tags :
9+ - v*
10+ pull_request : {}
1411
1512env :
16- # Common versions
17- PYTHON_VERSION : ' 3.11'
18- HATCH_VERSION : ' 1.12.0'
19- DOCKER_BUILDX_VERSION : ' v0.24.0'
13+ PYTHON_VERSION : " 3.11"
14+ HATCH_VERSION : " 1.16.2"
15+ DOCKER_BUILDX_VERSION : " v0.30.1"
2016
21- # These environment variables are important to the Crossplane CLI install.sh
22- # script. They determine what version it installs.
2317 XP_CHANNEL : stable
24- XP_VERSION : v1.20.0
25-
26- # The package to push, without a version tag. The default matches GitHub. For
27- # example xpkg.crossplane.io/crossplane/function-template-go. Note that
28- # xpkg.crossplane.io is just an alias for ghcr.io, so we upload to ghcr.io but
29- # this'll be pulled from xpkg.crossplane.io.
30- XPKG : ghcr.io/${{ github.repository}}
18+ # XP_VERSION: v2.1.3 # the latest stable Crossplane CLI will be used
3119
32- # The package version to push. The default is 0.0.0-gitsha.
33- XPKG_VERSION : ${{ inputs.version }}
20+ XPKG : xpkg.crossplane.io/${{ github.repository }}
3421
3522jobs :
3623 lint :
3724 runs-on : ubuntu-24.04
3825 steps :
39- - name : Checkout
40- uses : actions/checkout@v6
26+ - uses : actions/checkout@v6
4127
42- - name : Setup Python
43- uses : actions/setup-python@v6
28+ - uses : actions/setup-python@v6
4429 with :
4530 python-version : ${{ env.PYTHON_VERSION }}
4631
47- - name : Setup Hatch
32+ - name : Install Hatch
4833 run : pipx install hatch==${{ env.HATCH_VERSION }}
4934
5035 - name : Lint
@@ -53,32 +38,30 @@ jobs:
5338 unit-test :
5439 runs-on : ubuntu-24.04
5540 steps :
56- - name : Checkout
57- uses : actions/checkout@v6
41+ - uses : actions/checkout@v6
5842
59- - name : Setup Python
60- uses : actions/setup-python@v6
43+ - uses : actions/setup-python@v6
6144 with :
6245 python-version : ${{ env.PYTHON_VERSION }}
6346
64- - name : Setup Hatch
47+ - name : Install Hatch
6548 run : pipx install hatch==${{ env.HATCH_VERSION }}
6649
67- - name : Run Unit Tests
50+ - name : Run unit tests
6851 run : hatch test --all --randomize
6952
70- # We want to build most packages for the amd64 and arm64 architectures. To
71- # speed this up we build single-platform packages in parallel. We then upload
72- # those packages to GitHub as a build artifact. The push job downloads those
73- # artifacts and pushes them as a single multi-platform package.
7453 build :
7554 runs-on : ubuntu-24.04
55+ needs :
56+ - lint
57+ - unit-test
7658 strategy :
7759 fail-fast : true
7860 matrix :
7961 arch :
8062 - amd64
8163 - arm64
64+
8265 steps :
8366 - name : Setup QEMU
8467 uses : docker/setup-qemu-action@v3
@@ -91,59 +74,68 @@ jobs:
9174 version : ${{ env.DOCKER_BUILDX_VERSION }}
9275 install : true
9376
94- - name : Checkout
95- uses : actions/checkout@v6
77+ - uses : actions/checkout@v6
78+
79+ - uses : actions/setup-python@v6
80+ with :
81+ python-version : ${{ env.PYTHON_VERSION }}
82+
83+ - name : Read version from Python package
84+ run : |
85+ echo "XPKG_VERSION=v$(python -c 'from function.__version__ import __version__; print(__version__)')" >> $GITHUB_ENV
9686
97- # We ask Docker to use GitHub Action's native caching support to speed up
98- # the build, per https://docs.docker.com/build/cache/backends/gha/.
99- - name : Build Runtime
100- id : image
87+ - name : Build runtime image
10188 uses : docker/build-push-action@v6
10289 with :
10390 context : .
10491 platforms : linux/${{ matrix.arch }}
92+ target : image
10593 cache-from : type=gha
10694 cache-to : type=gha,mode=max
107- target : image
10895 build-args :
10996 PYTHON_VERSION=${{ env.PYTHON_VERSION }}
11097 outputs : type=docker,dest=runtime-${{ matrix.arch }}.tar
111-
112- - name : Setup the Crossplane CLI
113- run : " curl -sL https://raw.githubusercontent.com/crossplane/crossplane/master/install.sh | sh"
114-
115- - name : Build Package
116- run : ./crossplane xpkg build --package-file=${{ matrix.arch }}.xpkg --package-root=package/ --embed-runtime-image-tarball=runtime-${{ matrix.arch }}.tar
117-
118- - name : Upload Single-Platform Package
98+
99+ - name : Install Crossplane CLI
100+ run : |
101+ curl -sL https://raw.githubusercontent.com/crossplane/crossplane/master/install.sh | sh
102+
103+ - name : Build xpkg
104+ run : |
105+ ./crossplane xpkg build \
106+ --package-root=package \
107+ --package-file=${{ matrix.arch }}.xpkg \
108+ --embed-runtime-image-tarball=runtime-${{ matrix.arch }}.tar
109+
110+ - name : Upload package artifact
119111 uses : actions/upload-artifact@v6
120112 with :
121113 name : package-${{ matrix.arch }}
122114 path : " *.xpkg"
123- if-no-files-found : error
124115 retention-days : 1
125116
126- # This job downloads the single-platform packages built by the build job, and
127- # pushes them as a multi-platform package.
128117 push :
129- if : ${{ github.event_name != 'pull_request' }}
118+ if : github.event_name != 'pull_request'
130119 runs-on : ubuntu-24.04
131120 needs :
132121 - build
122+
133123 steps :
134- - name : Checkout
135- uses : actions/checkout@v6
124+ - uses : actions/checkout@v6
136125
137- - name : Download Single-Platform Packages
126+ - name : Download artifacts
138127 uses : actions/download-artifact@v7
139128 with :
140- # See https://github.com/docker/build-push-action/blob/263435/README.md#summaries
141- pattern : " !*.dockerbuild"
142129 path : .
143130 merge-multiple : true
144131
145- - name : Setup the Crossplane CLI
146- run : " curl -sL https://raw.githubusercontent.com/crossplane/crossplane/master/install.sh | sh"
132+ - name : Install Crossplane CLI
133+ run : |
134+ curl -sL https://raw.githubusercontent.com/crossplane/crossplane/master/install.sh | sh
135+
136+ - name : Read version from Python package
137+ run : |
138+ echo "XPKG_VERSION=v$(python -c 'from function.__version__ import __version__; print(__version__)')" >> $GITHUB_ENV
147139
148140 - name : Login to GitHub Container Registry
149141 uses : docker/login-action@v3
@@ -152,13 +144,8 @@ jobs:
152144 username : ${{ github.repository_owner }}
153145 password : ${{ secrets.GITHUB_TOKEN }}
154146
155- # If a version wasn't explicitly passed as a workflow_dispatch input we
156- # default to version v0.0.0-<git-commit-date>-<git-short-sha>, for example
157- # v0.0.0-20231101115142-1091066df799. This is a simple implementation of
158- # Go's pseudo-versions: https://go.dev/ref/mod#pseudo-versions.
159- - name : Set Default Multi-Platform Package Version
160- if : env.XPKG_VERSION == ''
161- run : echo "XPKG_VERSION=v0.0.0-$(date -d@$(git show -s --format=%ct) +%Y%m%d%H%M%S)-$(git rev-parse --short=12 HEAD)" >> $GITHUB_ENV
162-
163- - name : Push Multi-Platform Package to GitHub Container Registry
164- run : " ./crossplane --verbose xpkg push --package-files $(echo *.xpkg|tr ' ' ,) ${{ env.XPKG }}:${{ env.XPKG_VERSION }}"
147+ - name : Push multi-arch xpkg
148+ run : |
149+ ./crossplane --verbose xpkg push \
150+ --package-files $(echo *.xpkg | tr ' ' ,) \
151+ ${{ env.XPKG }}:${{ env.XPKG_VERSION }}
0 commit comments