version 0.0.8 #5
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI | |
| on: | |
| push: | |
| tags: | |
| - "v*" | |
| env: | |
| PYTHON_VERSION: "3.11" | |
| HATCH_VERSION: "1.16.2" | |
| DOCKER_BUILDX_VERSION: "v0.30.1" | |
| XP_CHANNEL: stable | |
| XPKG: ghcr.io/${{ github.repository }} | |
| jobs: | |
| lint: | |
| runs-on: ubuntu-24.04 | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - uses: actions/setup-python@v6 | |
| with: | |
| python-version: ${{ env.PYTHON_VERSION }} | |
| - name: Install Hatch | |
| run: pipx install hatch==${{ env.HATCH_VERSION }} | |
| - name: Lint | |
| run: hatch fmt | |
| unit-test: | |
| runs-on: ubuntu-24.04 | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - uses: actions/setup-python@v6 | |
| with: | |
| python-version: ${{ env.PYTHON_VERSION }} | |
| - name: Install Hatch | |
| run: pipx install hatch==${{ env.HATCH_VERSION }} | |
| - name: Run unit tests | |
| run: hatch test --all --randomize | |
| # We want to build most packages for the amd64 and arm64 architectures. To | |
| # speed this up we build single-platform packages in parallel. We then upload | |
| # those packages to GitHub as a build artifact. The push job downloads those | |
| # artifacts and pushes them as a single multi-platform package. | |
| build: | |
| runs-on: ubuntu-24.04 | |
| needs: | |
| - lint | |
| - unit-test | |
| strategy: | |
| fail-fast: true | |
| matrix: | |
| arch: | |
| - amd64 | |
| - arm64 | |
| steps: | |
| - name: Setup QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| with: | |
| platforms: all | |
| - name: Setup Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| with: | |
| version: ${{ env.DOCKER_BUILDX_VERSION }} | |
| install: true | |
| - name: Checkout | |
| uses: actions/checkout@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@v6 | |
| with: | |
| context: . | |
| platforms: linux/${{ matrix.arch }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| target: image | |
| build-args: | |
| PYTHON_VERSION=${{ env.PYTHON_VERSION }} | |
| outputs: type=docker,dest=runtime-${{ matrix.arch }}.tar | |
| - name: Install Crossplane CLI | |
| run: curl -sL "https://raw.githubusercontent.com/crossplane/crossplane/main/install.sh" | sh | |
| - name: Print Crossplane client version | |
| run: ./crossplane version --client | |
| - name: Build Package | |
| run: ./crossplane xpkg build --package-file=${{ matrix.arch }}.xpkg --package-root=package/ --embed-runtime-image-tarball=runtime-${{ matrix.arch }}.tar | |
| - name: Upload Single-Platform Package | |
| uses: actions/upload-artifact@v6 | |
| with: | |
| name: package-${{ matrix.arch }} | |
| path: "*.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. | |
| push: | |
| if: ${{ github.event_name != 'pull_request' }} | |
| runs-on: ubuntu-24.04 | |
| needs: | |
| - build | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| - name: Download Single-Platform Packages | |
| uses: actions/download-artifact@v7 | |
| with: | |
| # See https://github.com/docker/build-push-action/blob/263435/README.md#summaries | |
| pattern: "!*.dockerbuild" | |
| path: . | |
| merge-multiple: true | |
| - name: Install Crossplane CLI | |
| run: curl -sL "https://raw.githubusercontent.com/crossplane/crossplane/main/install.sh" | sh | |
| - name: Print Crossplane client version | |
| run: ./crossplane version --client | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.repository_owner }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Read version from Python package | |
| id: read_version | |
| run: | | |
| PY_VERSION=$(python -c 'from function.__version__ import __version__; print(__version__)') | |
| echo "PY_VERSION=$PY_VERSION" >> $GITHUB_ENV | |
| echo "Python package version: $PY_VERSION" | |
| - name: Check tag matches package version | |
| run: | | |
| TAG_VERSION=${GITHUB_REF#refs/tags/} | |
| echo "Git tag: $TAG_VERSION" | |
| if [ "$TAG_VERSION" != "v$PY_VERSION" ]; then | |
| echo "ERROR: Git tag ($TAG_VERSION) does not match function/__version__.py ($PY_VERSION)" | |
| exit 1 | |
| fi | |
| echo "XPKG_VERSION=$TAG_VERSION" >> $GITHUB_ENV | |
| echo "✅ Tag matches function/__version__.py" | |
| - name: Push Multi-Platform Package to GitHub Container Registry | |
| run: "./crossplane --verbose xpkg push --package-files $(echo *.xpkg|tr ' ' ,) ${{ env.XPKG }}:${{ env.XPKG_VERSION }}" |