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: Build & Update with Arduino CLI | |
| on: | |
| push: | |
| branches: | |
| - main | |
| - test_package_update | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| jobs: | |
| build-and-update: | |
| runs-on: ubuntu-22.04 | |
| # services: | |
| # docker: | |
| # image: docker:dind | |
| # options: --privileged --shm-size=2g | |
| # volumes: | |
| # - /var/run/docker.sock:/var/run/docker.sock:ro | |
| # container: | |
| # image: ubuntu:latest | |
| env: | |
| TAG_VERSION: "v0.6.7" | |
| ARCH: amd64 | |
| APPCLI_REPO: arduino/arduino-app-cli | |
| ROUTER_REPO: arduino/arduino-router | |
| # ---- Configure what to fetch ---- | |
| # Use a specific tag (with leading v) or leave empty to use the latest stable release. | |
| APPCLI_TAG: v0.6.6 # or "" to auto-use latest | |
| APPCLI_REGEX: "amd64\\.deb$" # choose the matching asset (regex) | |
| ROUTER_TAG: v0.5.3 # or "" to auto-use latest | |
| ROUTER_REGEX: "amd64\\.deb$" # e.g. change to "arm64\\.deb$" if you need arm64 | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version-file: go.mod | |
| - name: Build deb | |
| run: | | |
| go tool task build-deb VERSION=${TAG_VERSION} ARCH=${{ matrix.arch }} | |
| - name: Fetch .debs dynamically into build/stable | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| set -euo pipefail | |
| mkdir -p build/stable | |
| fetch_deb () { | |
| local repo="$1" tag="${2:-}" regex="$3" | |
| echo "==> Resolving release for ${repo} (tag='${tag:-<latest>}')" | |
| if [ -n "${tag}" ]; then | |
| url="https://api.github.com/repos/${repo}/releases/tags/${tag}" | |
| else | |
| url="https://api.github.com/repos/${repo}/releases/latest" | |
| fi | |
| rel="$(curl -sfL -H "Authorization: token ${GH_TOKEN}" -H "Accept: application/vnd.github+json" "${url}")" | |
| name="$(echo "$rel" | jq -r --arg re "${regex}" '.assets[] | select(.name | test($re)) | .name' | head -n1)" | |
| dl="$(echo "$rel" | jq -r --arg re "${regex}" '.assets[] | select(.name | test($re)) | .browser_download_url' | head -n1)" | |
| if [ -z "${name}" ] || [ "${name}" = "null" ] || [ -z "${dl}" ] || [ "${dl}" = "null" ]; then | |
| echo "!! No asset found in ${repo} matching regex: ${regex}" | |
| echo " Available assets:" | |
| echo "$rel" | jq -r '.assets[].name' | |
| exit 1 | |
| fi | |
| echo "Found: ${name}" | |
| echo "Downloading: ${dl}" | |
| curl -sfL -H "Authorization: token ${GH_TOKEN}" \ | |
| -o "build/stable/${name}" \ | |
| "${dl}" | |
| ls -lh "build/stable/${name}" | |
| } | |
| fetch_deb "${APPCLI_REPO}" "${APPCLI_TAG}" "${APPCLI_REGEX}" | |
| fetch_deb "${ROUTER_REPO}" "${ROUTER_TAG}" "${ROUTER_REGEX}" | |
| echo "✅ Downloaded files:" | |
| ls -lh build/stable/ | |
| ls -lh build/ | |
| - name: Build Docker image (no cache) | |
| run: | | |
| docker build --no-cache -t mock-apt-repo -f test.Dockerfile . | |
| - name: Run mock-apt-repo container | |
| run: | | |
| docker run --rm -d \ | |
| --privileged \ | |
| --cgroupns=host \ | |
| -v /sys/fs/cgroup:/sys/fs/cgroup:rw \ | |
| -v /var/run/docker.sock:/var/run/docker.sock \ | |
| -e DOCKER_HOST=unix:///var/run/docker.sock \ | |
| --name apt-test-update \ | |
| mock-apt-repo | |
| - name: Verify container is running | |
| run: docker ps | |
| # (Optional) wait a bit if your container needs to boot services | |
| - name: Wait for container to be ready | |
| run: | | |
| for i in {1..30}; do | |
| if docker exec apt-test-update sh -c 'true' 2>/dev/null; then | |
| echo "Container is ready"; break | |
| fi | |
| echo "Waiting for container... ($i)" | |
| sleep 2 | |
| done | |
| - name: Run arduino-app-cli current version | |
| run: | | |
| mkdir -p artifacts | |
| docker exec --user arduino apt-test-update arduino-app-cli system version | |
| - name: Run arduino-app-cli with auto-yes (as arduino) | |
| run: | | |
| mkdir -p artifacts | |
| docker exec apt-test-update sh -lc 'su - arduino -c "yes | arduino-app-cli system update"' \ | |
| | tee artifacts/arduino-system-update.log | |
| - name: Run arduino-app-cli version updated | |
| run: | | |
| mkdir -p artifacts | |
| docker exec --user arduino apt-test-update arduino-app-cli system version | |
| - name: Show recent container logs (for context) | |
| if: always() | |
| run: docker logs --tail=200 apt-test-update || true | |