Skip to content

Commit e558612

Browse files
author
nullptr0
committed
feat: add ci support
1 parent da9b1f6 commit e558612

2 files changed

Lines changed: 126 additions & 8 deletions

File tree

.github/workflows/build.yaml

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
name: Build and Release
2+
3+
on:
4+
schedule:
5+
- cron: "0 6 * * *" # daily at 06:00 UTC
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
check-version:
13+
runs-on: ubuntu-latest
14+
outputs:
15+
latest_version: ${{ steps.versions.outputs.latest_version }}
16+
current_version: ${{ steps.versions.outputs.current_version }}
17+
should_build: ${{ steps.versions.outputs.should_build }}
18+
steps:
19+
- name: Fetch current and latest versions
20+
id: versions
21+
env:
22+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
23+
run: |
24+
# Get current release version from iChizer0/nanobot-recamera (may not exist)
25+
CURRENT_VERSION="$(
26+
curl -fsSL \
27+
-H "Authorization: token ${GH_TOKEN}" \
28+
"https://api.github.com/repos/iChizer0/nanobot-recamera/releases/latest" \
29+
| jq -r '.tag_name // empty' 2>/dev/null
30+
)" || CURRENT_VERSION=""
31+
32+
echo "Current version: ${CURRENT_VERSION:-<none>}"
33+
34+
# Get latest release version from HKUDS/nanobot
35+
LATEST_VERSION="$(
36+
curl -fsSL \
37+
-H "Authorization: token ${GH_TOKEN}" \
38+
"https://api.github.com/repos/HKUDS/nanobot/releases/latest" \
39+
| jq -r '.tag_name'
40+
)"
41+
42+
if [ -z "$LATEST_VERSION" ] || [ "$LATEST_VERSION" = "null" ]; then
43+
echo "Error: failed to determine the latest release version." >&2
44+
exit 1
45+
fi
46+
47+
echo "Latest version: ${LATEST_VERSION}"
48+
49+
echo "current_version=${CURRENT_VERSION}" >> "$GITHUB_OUTPUT"
50+
echo "latest_version=${LATEST_VERSION}" >> "$GITHUB_OUTPUT"
51+
52+
if [ "$LATEST_VERSION" = "$CURRENT_VERSION" ]; then
53+
echo "No new version, exiting."
54+
echo "should_build=false" >> "$GITHUB_OUTPUT"
55+
else
56+
echo "should_build=true" >> "$GITHUB_OUTPUT"
57+
fi
58+
59+
build:
60+
needs: check-version
61+
if: needs.check-version.outputs.should_build == 'true'
62+
runs-on: ubuntu-latest
63+
strategy:
64+
matrix:
65+
python-version: ["3.11", "3.12"]
66+
steps:
67+
- name: Checkout
68+
uses: actions/checkout@v4
69+
70+
- name: Set up QEMU
71+
uses: docker/setup-qemu-action@v3
72+
73+
- name: Set up Docker Buildx
74+
uses: docker/setup-buildx-action@v3
75+
76+
- name: Build wheelhouse
77+
env:
78+
NANOBOT_VERSION_CURRENT: ${{ needs.check-version.outputs.current_version }}
79+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
80+
run: |
81+
chmod +x build-release.sh
82+
./build-release.sh armv7 ${{ matrix.python-version }}
83+
84+
- name: Upload wheelhouse artifact
85+
uses: actions/upload-artifact@v4
86+
with:
87+
name: wheelhouse-py${{ matrix.python-version }}
88+
path: dist/nanobot-armv7-py*-wheelhouse.tar.gz
89+
90+
release:
91+
needs: [check-version, build]
92+
runs-on: ubuntu-latest
93+
steps:
94+
- name: Download all wheelhouse artifacts
95+
uses: actions/download-artifact@v4
96+
with:
97+
path: artifacts
98+
merge-multiple: true
99+
100+
- name: List artifacts
101+
run: ls -lhR artifacts/
102+
103+
- name: Create release and upload assets
104+
env:
105+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
106+
run: |
107+
gh release create "${{ needs.check-version.outputs.latest_version }}" \
108+
--repo "${{ github.repository }}" \
109+
--title "nanobot-recamera ${{ needs.check-version.outputs.latest_version }}" \
110+
artifacts/*.tar.gz

build-release.sh

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
55
REPO_DIR="${SCRIPT_DIR}/nanobot"
66
GITHUB_REPO="HKUDS/nanobot"
77

8-
# ── 1. Parse target platform and python version arguments ─────────────────────
8+
# Parse target platform and python version arguments
99
if [ $# -lt 2 ]; then
1010
echo "Usage: $0 <platform> <python-version>" >&2
1111
echo " e.g. $0 armv7 3.11" >&2
@@ -16,7 +16,7 @@ PLATFORM="$1"
1616
PY_VERSION="$2"
1717
PY_VERSION_NODOT="${PY_VERSION//./}"
1818

19-
# ── Pre-flight checks ────────────────────────────────────────────────────────
19+
# Pre-flight checks
2020
if ! command -v docker >/dev/null 2>&1; then
2121
echo "Error: docker is required." >&2
2222
exit 1
@@ -27,7 +27,15 @@ if ! docker buildx version >/dev/null 2>&1; then
2727
exit 1
2828
fi
2929

30-
# ── 2. Find latest release version from GitHub ───────────────────────────────
30+
# Ensure a buildx builder with cross-platform support exists
31+
BUILDER_NAME="nanobot-multiarch"
32+
if ! docker buildx inspect "$BUILDER_NAME" >/dev/null 2>&1; then
33+
echo "==> Creating buildx builder '${BUILDER_NAME}' with QEMU support ..."
34+
docker buildx create --name "$BUILDER_NAME" --driver docker-container --bootstrap
35+
fi
36+
docker buildx use "$BUILDER_NAME"
37+
38+
# Find latest release version from GitHub
3139
echo "==> Fetching latest release from github.com/${GITHUB_REPO} ..."
3240

3341
CURL_OPTS=(-fsSL)
@@ -48,7 +56,7 @@ fi
4856

4957
echo " Latest release : $LATEST_VERSION"
5058

51-
# ── 3. Compare with current version ──────────────────────────────────────────
59+
# Compare with current version
5260
CURRENT_VERSION="${NANOBOT_VERSION_CURRENT:-}"
5361
echo " Current version: ${CURRENT_VERSION:-<not set>}"
5462

@@ -57,9 +65,9 @@ if [ "$LATEST_VERSION" = "$CURRENT_VERSION" ]; then
5765
exit 0
5866
fi
5967

60-
echo "==> Version differs proceeding with download and build."
68+
echo "==> Version differs - proceeding with download and build."
6169

62-
# ── 4. Download and extract the latest release ───────────────────────────────
70+
# Download and extract the latest release
6371
TARBALL_URL="https://github.com/${GITHUB_REPO}/archive/refs/tags/${LATEST_VERSION}.tar.gz"
6472
DOWNLOAD_DIR="${SCRIPT_DIR}/downloads"
6573
TARBALL_PATH="${DOWNLOAD_DIR}/${LATEST_VERSION}.tar.gz"
@@ -74,7 +82,7 @@ rm -rf "$REPO_DIR"
7482
mkdir -p "$REPO_DIR"
7583
tar -xzf "$TARBALL_PATH" -C "$REPO_DIR" --strip-components=1
7684

77-
# ── 5. Build the Python wheelhouse for the specified platform ─────────────────
85+
# Build the Python wheelhouse for the specified platform
7886
EXTRAS="${EXTRAS:-}"
7987
OUT_DIR="${SCRIPT_DIR}/dist/${PLATFORM}-py${PY_VERSION_NODOT}-wheelhouse"
8088

@@ -111,7 +119,7 @@ docker buildx build \
111119
--output "type=local,dest=$OUT_DIR" \
112120
"$REPO_DIR"
113121

114-
# buildx local output keeps stage root; wheelhouse will be under $OUT_DIR/wheelhouse
122+
# Check if wheelhouse was generated
115123
WHEEL_DIR="$OUT_DIR/wheelhouse"
116124
if [ ! -d "$WHEEL_DIR" ]; then
117125
echo "Error: wheelhouse output not found at $WHEEL_DIR" >&2

0 commit comments

Comments
 (0)