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: | ||
| ARCH: amd64 | ||
| APPCLI_REPO: arduino/arduino-app-cli | ||
| ROUTER_REPO: arduino/arduino-router | ||
| STABLE_DIR: build/stable | ||
| # ---- 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: "arm64\\.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: Set up Go | ||
| # uses: actions/setup-go@v5 | ||
| # with: | ||
| # go-version-file: go.mod | ||
| # - name: Set up Docker | ||
| # uses: docker/setup-docker-action@v2 | ||
| # - name: Set up Docker Buildx | ||
| # uses: docker/setup-buildx-action@v3 | ||
| # - name: Install Task (go-task) | ||
| # run: | | ||
| # go tool task --version | ||
| - name: Prepare folder | ||
| run: | | ||
| mkdir -p "${STABLE_DIR}" | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
| - name: Configure Git for private repo cloning | ||
| env: | ||
| GITHUB_USERNAME: ${{ secrets.GITHUB_USERNAME }} | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| run: | | ||
| git config --global url."https://${GITHUB_USERNAME}:${GITHUB_TOKEN}@github.com".insteadOf "https://github.com" | ||
| # - name: Install jq & curl | ||
| # run: | | ||
| # sudo apt-get update | ||
| # sudo apt-get install -y jq curl | ||
| - 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/ | ||
| - 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 | ||