ci test, no tag #13
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: | |
| branches: | |
| - main | |
| - release-* | |
| tags: | |
| - "v*" | |
| pull_request: {} | |
| workflow_dispatch: {} | |
| env: | |
| PYTHON_VERSION: "3.11" | |
| HATCH_VERSION: "1.16.2" | |
| DOCKER_BUILDX_VERSION: "v0.30.1" | |
| XP_CHANNEL: stable | |
| XPKG: xpkg.crossplane.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 | |
| build: | |
| runs-on: ubuntu-24.04 | |
| needs: | |
| - lint | |
| - unit-test | |
| strategy: | |
| fail-fast: true | |
| matrix: | |
| arch: | |
| - amd64 | |
| - arm64 | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - uses: actions/setup-python@v6 | |
| with: | |
| python-version: ${{ env.PYTHON_VERSION }} | |
| - name: Read version from Python package | |
| run: | | |
| echo "XPKG_VERSION=v$(python -c 'from function.__version__ import __version__; print(__version__)')" >> $GITHUB_ENV | |
| - 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 }} | |
| driver: docker-container | |
| - name: Build runtime image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| platforms: linux/${{ matrix.arch }} | |
| target: image | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| 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 xpkg | |
| run: | | |
| ./crossplane xpkg build \ | |
| --package-root=package \ | |
| --package-file=${{ matrix.arch }}.xpkg \ | |
| --embed-runtime-image-tarball=runtime-${{ matrix.arch }}.tar | |
| - name: Upload artifact | |
| uses: actions/upload-artifact@v6 | |
| with: | |
| name: artifact-${{ matrix.arch }} | |
| path: | | |
| runtime-${{ matrix.arch }}.tar | |
| *.xpkg | |
| retention-days: 1 | |
| dry-run-pr: | |
| if: github.event_name == 'pull_request' | |
| runs-on: ubuntu-24.04 | |
| needs: | |
| - build | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Download artifacts | |
| uses: actions/download-artifact@v7 | |
| with: | |
| 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: List built artifacts | |
| run: | | |
| echo "Artifacts built for PR:" | |
| ls -lh *.xpkg runtime-*.tar || echo "No artifacts found" | |
| push: | |
| runs-on: ubuntu-24.04 | |
| needs: | |
| - build | |
| if: startsWith(github.ref, 'refs/tags/v') | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Download artifacts | |
| uses: actions/download-artifact@v7 | |
| with: | |
| 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: 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 "✅ Tag matches function/__version__.py" | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.repository_owner }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Push multi-arch xpkg | |
| run: | | |
| ./crossplane --verbose xpkg push \ | |
| --package-files $(echo *.xpkg | tr ' ' ,) \ | |
| ${{ env.XPKG }}:${{ env.XPKG_VERSION }} |