Skip to content
This repository was archived by the owner on Dec 10, 2025. It is now read-only.

Commit 11135f4

Browse files
author
Patrick J. McNerthney
committed
Add github workflow to publish xpkg
1 parent 7180334 commit 11135f4

1 file changed

Lines changed: 179 additions & 0 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
name: CI
2+
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
14+
15+
env:
16+
# Common versions
17+
PYTHON_VERSION: '3.12.11' # TODO: Used?
18+
DOCKER_BUILDX_VERSION: 'v0.26.1'
19+
20+
# These environment variables are important to the Crossplane CLI install.sh
21+
# script. They determine what version it installs.
22+
XP_CHANNEL: stable
23+
XP_VERSION: current
24+
25+
# This CI job will automatically push new builds to xpkg.upbound.io if the
26+
# XPKG_ACCESS_ID and XPKG_TOKEN secrets are set in the GitHub respository (or
27+
# organization) settings. Create a token at https://accounts.upbound.io.
28+
# XPKG_ACCESS_ID: ${{ secrets.XPKG_ACCESS_ID }}
29+
30+
# The package to push, without a version tag. The default matches GitHub. For
31+
# example xpkg.upbound.io/crossplane/function-template-go.
32+
# XPKG: xpkg.upbound.io/${{ github.repository}}
33+
CROSSPLANE_REGORG: ghcr.io/${{ github.repository}}
34+
35+
# The package version to push. The default is 0.0.0-gitsha.
36+
XPKG_VERSION: ${{ inputs.version }}
37+
38+
jobs:
39+
# lint:
40+
# runs-on: ubuntu-24.04
41+
# steps:
42+
# - name: Checkout
43+
# uses: actions/checkout@v4
44+
45+
# - name: Setup Python
46+
# uses: actions/setup-python@v5
47+
# with:
48+
# python-version: ${{ env.PYTHON_VERSION }}
49+
50+
# - name: Setup Hatch
51+
# run: pipx install hatch==1.7.0
52+
53+
# - name: Lint
54+
# run: hatch run lint:check
55+
56+
# unit-test:
57+
# runs-on: ubuntu-24.04
58+
# steps:
59+
# - name: Checkout
60+
# uses: actions/checkout@v4
61+
62+
# - name: Setup Python
63+
# uses: actions/setup-python@v5
64+
# with:
65+
# python-version: ${{ env.PYTHON_VERSION }}
66+
67+
# - name: Setup Hatch
68+
# run: pipx install hatch==1.7.0
69+
70+
# - name: Run Unit Tests
71+
# run: hatch run test:unit
72+
73+
# We want to build most packages for the amd64 and arm64 architectures. To
74+
# speed this up we build single-platform packages in parallel. We then upload
75+
# those packages to GitHub as a build artifact. The push job downloads those
76+
# artifacts and pushes them as a single multi-platform package.
77+
build:
78+
runs-on: ubuntu-24.04
79+
strategy:
80+
fail-fast: true
81+
matrix:
82+
arch:
83+
- amd64
84+
- arm64
85+
steps:
86+
- name: Setup QEMU
87+
uses: docker/setup-qemu-action@v3
88+
with:
89+
platforms: all
90+
91+
- name: Setup Docker Buildx
92+
uses: docker/setup-buildx-action@v3
93+
with:
94+
version: ${{ env.DOCKER_BUILDX_VERSION }}
95+
install: true
96+
97+
- name: Checkout
98+
uses: actions/checkout@v4
99+
100+
# We ask Docker to use GitHub Action's native caching support to speed up
101+
# the build, per https://docs.docker.com/build/cache/backends/gha/.
102+
- name: Build Runtime
103+
id: image
104+
uses: docker/build-push-action@v6
105+
with:
106+
context: .
107+
platforms: linux/${{ matrix.arch }}
108+
cache-from: type=gha
109+
cache-to: type=gha,mode=max
110+
target: image
111+
build-args:
112+
PYTHON_VERSION=${{ env.PYTHON_VERSION }}
113+
outputs: type=docker,dest=runtime-${{ matrix.arch }}.tar
114+
115+
- name: Setup the Crossplane CLI
116+
run: "curl -sL https://raw.githubusercontent.com/crossplane/crossplane/master/install.sh | sh"
117+
118+
- name: Build Package
119+
run: ./crossplane xpkg build --package-file=${{ matrix.arch }}.xpkg --package-root=package/ --embed-runtime-image-tarball=runtime-${{ matrix.arch }}.tar
120+
121+
- name: Upload Single-Platform Package
122+
uses: actions/upload-artifact@v4
123+
with:
124+
name: package-${{ matrix.arch }}
125+
path: "*.xpkg"
126+
if-no-files-found: error
127+
retention-days: 1
128+
129+
# This job downloads the single-platform packages built by the build job, and
130+
# pushes them as a multi-platform package. We only push the package it the
131+
# XPKG_ACCESS_ID and XPKG_TOKEN secrets were provided.
132+
push:
133+
runs-on: ubuntu-24.04
134+
needs:
135+
- build
136+
steps:
137+
- name: Checkout
138+
uses: actions/checkout@v4
139+
140+
- name: Download Single-Platform Packages
141+
uses: actions/download-artifact@v4
142+
with:
143+
# See https://github.com/docker/build-push-action/blob/263435/README.md#summaries
144+
pattern: "!*.dockerbuild"
145+
path: .
146+
merge-multiple: true
147+
148+
- name: Setup the Crossplane CLI
149+
run: "curl -sL https://raw.githubusercontent.com/crossplane/crossplane/master/install.sh | sh"
150+
151+
# - name: Login to Upbound
152+
# uses: docker/login-action@v3
153+
# if: env.XPKG_ACCESS_ID != ''
154+
# with:
155+
# registry: xpkg.upbound.io
156+
# username: ${{ secrets.XPKG_ACCESS_ID }}
157+
# password: ${{ secrets.XPKG_TOKEN }}
158+
159+
# If a version wasn't explicitly passed as a workflow_dispatch input we
160+
# default to version v0.0.0-<git-commit-date>-<git-short-sha>, for example
161+
# v0.0.0-20231101115142-1091066df799. This is a simple implementation of
162+
# Go's pseudo-versions: https://go.dev/ref/mod#pseudo-versions.
163+
# - name: Set Default Multi-Platform Package Version
164+
# if: env.XPKG_VERSION == ''
165+
# 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
166+
167+
# - name: Push Multi-Platform Package to Upbound
168+
# if: env.XPKG_ACCESS_ID != ''
169+
# run: "./crossplane --verbose xpkg push --package-files $(echo *.xpkg|tr ' ' ,) ${{ env.XPKG }}:${{ env.XPKG_VERSION }}"
170+
171+
- name: Login to GHCR
172+
uses: docker/login-action@v3
173+
with:
174+
registry: ghcr.io
175+
username: ${{ github.repository_owner }}
176+
password: ${{ secrets.GITHUB_TOKEN }}
177+
178+
- name: Push Multi-Platform Package to GHCR
179+
run: "./crossplane --verbose xpkg push --package-files $(echo *.xpkg|tr ' ' ,) ${{ env.CROSSPLANE_REGORG }}:${{ env.XPKG_VERSION }}"

0 commit comments

Comments
 (0)