Skip to content

Commit 454ce8b

Browse files
committed
two ci files
1 parent d1cf5ca commit 454ce8b

2 files changed

Lines changed: 164 additions & 117 deletions

File tree

.github/workflows/ci-with-bnp.yaml

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
name: CI-with-BnP
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
8+
permissions:
9+
contents: read
10+
packages: write
11+
12+
env:
13+
PYTHON_VERSION: "3.11"
14+
HATCH_VERSION: "1.16.2"
15+
DOCKER_BUILDX_VERSION: "v0.30.1"
16+
XP_CHANNEL: stable
17+
XPKG: ghcr.io/${{ github.repository }}
18+
19+
jobs:
20+
lint:
21+
runs-on: ubuntu-24.04
22+
steps:
23+
- uses: actions/checkout@v6
24+
- uses: actions/setup-python@v6
25+
with:
26+
python-version: ${{ env.PYTHON_VERSION }}
27+
- name: Install Hatch
28+
run: pipx install hatch==${{ env.HATCH_VERSION }}
29+
- name: Lint
30+
run: hatch fmt
31+
32+
unit-test:
33+
runs-on: ubuntu-24.04
34+
steps:
35+
- uses: actions/checkout@v6
36+
- uses: actions/setup-python@v6
37+
with:
38+
python-version: ${{ env.PYTHON_VERSION }}
39+
- name: Install Hatch
40+
run: pipx install hatch==${{ env.HATCH_VERSION }}
41+
- name: Run unit tests
42+
run: hatch test --all --randomize
43+
44+
45+
# We want to build most packages for the amd64 and arm64 architectures. To
46+
# speed this up we build single-platform packages in parallel. We then upload
47+
# those packages to GitHub as a build artifact. The push job downloads those
48+
# artifacts and pushes them as a single multi-platform package.
49+
build:
50+
runs-on: ubuntu-24.04
51+
needs:
52+
- lint
53+
- unit-test
54+
strategy:
55+
fail-fast: true
56+
matrix:
57+
arch:
58+
- amd64
59+
- arm64
60+
steps:
61+
- name: Setup QEMU
62+
uses: docker/setup-qemu-action@v3
63+
with:
64+
platforms: all
65+
66+
- name: Setup Docker Buildx
67+
uses: docker/setup-buildx-action@v3
68+
with:
69+
version: ${{ env.DOCKER_BUILDX_VERSION }}
70+
# install: true
71+
72+
- name: Checkout
73+
uses: actions/checkout@v6
74+
75+
# We ask Docker to use GitHub Action's native caching support to speed up
76+
# the build, per https://docs.docker.com/build/cache/backends/gha/.
77+
- name: Build Runtime
78+
id: image
79+
uses: docker/build-push-action@v6
80+
with:
81+
context: .
82+
platforms: linux/${{ matrix.arch }}
83+
cache-from: type=gha
84+
cache-to: type=gha,mode=max
85+
target: image
86+
build-args:
87+
PYTHON_VERSION=${{ env.PYTHON_VERSION }}
88+
outputs: type=docker,dest=runtime-${{ matrix.arch }}.tar
89+
90+
- name: Install Crossplane CLI
91+
run: curl -sL "https://raw.githubusercontent.com/crossplane/crossplane/main/install.sh" | sh
92+
93+
- name: Print Crossplane client version
94+
run: ./crossplane version --client
95+
96+
- name: Build Package
97+
run: ./crossplane xpkg build --package-file=${{ matrix.arch }}.xpkg --package-root=package/ --embed-runtime-image-tarball=runtime-${{ matrix.arch }}.tar
98+
99+
- name: Upload Single-Platform Package
100+
uses: actions/upload-artifact@v6
101+
with:
102+
name: package-${{ matrix.arch }}
103+
path: "*.xpkg"
104+
if-no-files-found: error
105+
retention-days: 1
106+
107+
108+
# This job downloads the single-platform packages built by the build job, and
109+
# pushes them as a multi-platform package.
110+
push:
111+
if: ${{ github.event_name != 'pull_request' }}
112+
runs-on: ubuntu-24.04
113+
needs:
114+
- build
115+
steps:
116+
- name: Checkout
117+
uses: actions/checkout@v6
118+
119+
- name: Download Single-Platform Packages
120+
uses: actions/download-artifact@v7
121+
with:
122+
pattern: "!*.dockerbuild"
123+
path: .
124+
merge-multiple: true
125+
126+
- name: Install Crossplane CLI
127+
run: curl -sL "https://raw.githubusercontent.com/crossplane/crossplane/main/install.sh" | sh
128+
129+
- name: Print Crossplane client version
130+
run: ./crossplane version --client
131+
132+
- name: Login to GitHub Container Registry
133+
uses: docker/login-action@v3
134+
with:
135+
registry: ghcr.io
136+
username: ${{ github.repository_owner }}
137+
password: ${{ secrets.GITHUB_TOKEN }}
138+
139+
- name: Read version from Python package
140+
id: read_version
141+
run: |
142+
PY_VERSION=$(python -c 'from function.__version__ import __version__; print(__version__)')
143+
echo "PY_VERSION=$PY_VERSION" >> $GITHUB_ENV
144+
echo "Python package version: $PY_VERSION"
145+
146+
- name: Check tag matches package version
147+
run: |
148+
TAG_VERSION=${GITHUB_REF#refs/tags/}
149+
echo "Git tag: $TAG_VERSION"
150+
if [ "$TAG_VERSION" != "v$PY_VERSION" ]; then
151+
echo "ERROR: Git tag ($TAG_VERSION) does not match function/__version__.py ($PY_VERSION)"
152+
exit 1
153+
fi
154+
echo "XPKG_VERSION=$TAG_VERSION" >> $GITHUB_ENV
155+
echo "✅ Tag matches function/__version__.py"
156+
157+
- name: Push Multi-Platform Package to GitHub Container Registry
158+
run: "./crossplane --verbose xpkg push --package-files $(echo *.xpkg|tr ' ' ,) ${{ env.XPKG }}:${{ env.XPKG_VERSION }}"

.github/workflows/ci.yaml

Lines changed: 6 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@ name: CI
22

33
on:
44
push:
5-
tags:
5+
branches:
6+
- main
7+
- release-*
8+
tags-ignore:
69
- "v*"
10+
pull_request: {}
11+
workflow_dispatch: {}
712

813
permissions:
914
contents: read
@@ -40,119 +45,3 @@ jobs:
4045
run: pipx install hatch==${{ env.HATCH_VERSION }}
4146
- name: Run unit tests
4247
run: hatch test --all --randomize
43-
44-
45-
# We want to build most packages for the amd64 and arm64 architectures. To
46-
# speed this up we build single-platform packages in parallel. We then upload
47-
# those packages to GitHub as a build artifact. The push job downloads those
48-
# artifacts and pushes them as a single multi-platform package.
49-
build:
50-
runs-on: ubuntu-24.04
51-
needs:
52-
- lint
53-
- unit-test
54-
strategy:
55-
fail-fast: true
56-
matrix:
57-
arch:
58-
- amd64
59-
- arm64
60-
steps:
61-
- name: Setup QEMU
62-
uses: docker/setup-qemu-action@v3
63-
with:
64-
platforms: all
65-
66-
- name: Setup Docker Buildx
67-
uses: docker/setup-buildx-action@v3
68-
with:
69-
version: ${{ env.DOCKER_BUILDX_VERSION }}
70-
# install: true
71-
72-
- name: Checkout
73-
uses: actions/checkout@v6
74-
75-
# We ask Docker to use GitHub Action's native caching support to speed up
76-
# the build, per https://docs.docker.com/build/cache/backends/gha/.
77-
- name: Build Runtime
78-
id: image
79-
uses: docker/build-push-action@v6
80-
with:
81-
context: .
82-
platforms: linux/${{ matrix.arch }}
83-
cache-from: type=gha
84-
cache-to: type=gha,mode=max
85-
target: image
86-
build-args:
87-
PYTHON_VERSION=${{ env.PYTHON_VERSION }}
88-
outputs: type=docker,dest=runtime-${{ matrix.arch }}.tar
89-
90-
- name: Install Crossplane CLI
91-
run: curl -sL "https://raw.githubusercontent.com/crossplane/crossplane/main/install.sh" | sh
92-
93-
- name: Print Crossplane client version
94-
run: ./crossplane version --client
95-
96-
- name: Build Package
97-
run: ./crossplane xpkg build --package-file=${{ matrix.arch }}.xpkg --package-root=package/ --embed-runtime-image-tarball=runtime-${{ matrix.arch }}.tar
98-
99-
- name: Upload Single-Platform Package
100-
uses: actions/upload-artifact@v6
101-
with:
102-
name: package-${{ matrix.arch }}
103-
path: "*.xpkg"
104-
if-no-files-found: error
105-
retention-days: 1
106-
107-
108-
# This job downloads the single-platform packages built by the build job, and
109-
# pushes them as a multi-platform package.
110-
push:
111-
if: ${{ github.event_name != 'pull_request' }}
112-
runs-on: ubuntu-24.04
113-
needs:
114-
- build
115-
steps:
116-
- name: Checkout
117-
uses: actions/checkout@v6
118-
119-
- name: Download Single-Platform Packages
120-
uses: actions/download-artifact@v7
121-
with:
122-
pattern: "!*.dockerbuild"
123-
path: .
124-
merge-multiple: true
125-
126-
- name: Install Crossplane CLI
127-
run: curl -sL "https://raw.githubusercontent.com/crossplane/crossplane/main/install.sh" | sh
128-
129-
- name: Print Crossplane client version
130-
run: ./crossplane version --client
131-
132-
- name: Login to GitHub Container Registry
133-
uses: docker/login-action@v3
134-
with:
135-
registry: ghcr.io
136-
username: ${{ github.repository_owner }}
137-
password: ${{ secrets.GITHUB_TOKEN }}
138-
139-
- name: Read version from Python package
140-
id: read_version
141-
run: |
142-
PY_VERSION=$(python -c 'from function.__version__ import __version__; print(__version__)')
143-
echo "PY_VERSION=$PY_VERSION" >> $GITHUB_ENV
144-
echo "Python package version: $PY_VERSION"
145-
146-
- name: Check tag matches package version
147-
run: |
148-
TAG_VERSION=${GITHUB_REF#refs/tags/}
149-
echo "Git tag: $TAG_VERSION"
150-
if [ "$TAG_VERSION" != "v$PY_VERSION" ]; then
151-
echo "ERROR: Git tag ($TAG_VERSION) does not match function/__version__.py ($PY_VERSION)"
152-
exit 1
153-
fi
154-
echo "XPKG_VERSION=$TAG_VERSION" >> $GITHUB_ENV
155-
echo "✅ Tag matches function/__version__.py"
156-
157-
- name: Push Multi-Platform Package to GitHub Container Registry
158-
run: "./crossplane --verbose xpkg push --package-files $(echo *.xpkg|tr ' ' ,) ${{ env.XPKG }}:${{ env.XPKG_VERSION }}"

0 commit comments

Comments
 (0)