|
| 1 | +name: Build & Update with Arduino CLI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + - test_package_update |
| 8 | + workflow_dispatch: |
| 9 | + |
| 10 | +permissions: |
| 11 | + contents: read |
| 12 | + |
| 13 | +jobs: |
| 14 | + build-and-update: |
| 15 | + runs-on: ubuntu-22.04 |
| 16 | + # services: |
| 17 | + # docker: |
| 18 | + # image: docker:dind |
| 19 | + # options: --privileged --shm-size=2g |
| 20 | + # volumes: |
| 21 | + # - /var/run/docker.sock:/var/run/docker.sock:ro |
| 22 | + # container: |
| 23 | + # image: ubuntu:latest |
| 24 | + |
| 25 | + env: |
| 26 | + TAG_VERSION: "v0.6.7" |
| 27 | + ARCH: amd64 |
| 28 | + APPCLI_REPO: arduino/arduino-app-cli |
| 29 | + ROUTER_REPO: arduino/arduino-router |
| 30 | + # ---- Configure what to fetch ---- |
| 31 | + # Use a specific tag (with leading v) or leave empty to use the latest stable release. |
| 32 | + APPCLI_TAG: v0.6.6 # or "" to auto-use latest |
| 33 | + APPCLI_REGEX: "amd64\\.deb$" # choose the matching asset (regex) |
| 34 | + |
| 35 | + ROUTER_TAG: v0.5.3 # or "" to auto-use latest |
| 36 | + ROUTER_REGEX: "amd64\\.deb$" # e.g. change to "arm64\\.deb$" if you need arm64 |
| 37 | + |
| 38 | + steps: |
| 39 | + - name: Checkout |
| 40 | + uses: actions/checkout@v4 |
| 41 | + |
| 42 | + - name: Checkout |
| 43 | + uses: actions/checkout@v4 |
| 44 | + |
| 45 | + - name: Set up Go |
| 46 | + uses: actions/setup-go@v5 |
| 47 | + with: |
| 48 | + go-version-file: go.mod |
| 49 | + |
| 50 | + - name: Build deb |
| 51 | + run: | |
| 52 | + go tool task build-deb VERSION=${TAG_VERSION} ARCH=${{ matrix.arch }} |
| 53 | +
|
| 54 | + - name: Fetch .debs dynamically into build/stable |
| 55 | + env: |
| 56 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 57 | + run: | |
| 58 | + set -euo pipefail |
| 59 | + mkdir -p build/stable |
| 60 | +
|
| 61 | + fetch_deb () { |
| 62 | + local repo="$1" tag="${2:-}" regex="$3" |
| 63 | +
|
| 64 | + echo "==> Resolving release for ${repo} (tag='${tag:-<latest>}')" |
| 65 | + if [ -n "${tag}" ]; then |
| 66 | + url="https://api.github.com/repos/${repo}/releases/tags/${tag}" |
| 67 | + else |
| 68 | + url="https://api.github.com/repos/${repo}/releases/latest" |
| 69 | + fi |
| 70 | +
|
| 71 | + rel="$(curl -sfL -H "Authorization: token ${GH_TOKEN}" -H "Accept: application/vnd.github+json" "${url}")" |
| 72 | +
|
| 73 | + name="$(echo "$rel" | jq -r --arg re "${regex}" '.assets[] | select(.name | test($re)) | .name' | head -n1)" |
| 74 | + dl="$(echo "$rel" | jq -r --arg re "${regex}" '.assets[] | select(.name | test($re)) | .browser_download_url' | head -n1)" |
| 75 | +
|
| 76 | + if [ -z "${name}" ] || [ "${name}" = "null" ] || [ -z "${dl}" ] || [ "${dl}" = "null" ]; then |
| 77 | + echo "!! No asset found in ${repo} matching regex: ${regex}" |
| 78 | + echo " Available assets:" |
| 79 | + echo "$rel" | jq -r '.assets[].name' |
| 80 | + exit 1 |
| 81 | + fi |
| 82 | +
|
| 83 | + echo "Found: ${name}" |
| 84 | + echo "Downloading: ${dl}" |
| 85 | +
|
| 86 | + curl -sfL -H "Authorization: token ${GH_TOKEN}" \ |
| 87 | + -o "build/stable/${name}" \ |
| 88 | + "${dl}" |
| 89 | +
|
| 90 | + ls -lh "build/stable/${name}" |
| 91 | + } |
| 92 | +
|
| 93 | + fetch_deb "${APPCLI_REPO}" "${APPCLI_TAG}" "${APPCLI_REGEX}" |
| 94 | + fetch_deb "${ROUTER_REPO}" "${ROUTER_TAG}" "${ROUTER_REGEX}" |
| 95 | +
|
| 96 | + echo "✅ Downloaded files:" |
| 97 | + ls -lh build/stable/ |
| 98 | + ls -lh build/ |
| 99 | +
|
| 100 | + - name: Build Docker image (no cache) |
| 101 | + run: | |
| 102 | + docker build --no-cache -t mock-apt-repo -f test.Dockerfile . |
| 103 | + |
| 104 | + - name: Run mock-apt-repo container |
| 105 | + run: | |
| 106 | + docker run --rm -d \ |
| 107 | + --privileged \ |
| 108 | + --cgroupns=host \ |
| 109 | + -v /sys/fs/cgroup:/sys/fs/cgroup:rw \ |
| 110 | + -v /var/run/docker.sock:/var/run/docker.sock \ |
| 111 | + -e DOCKER_HOST=unix:///var/run/docker.sock \ |
| 112 | + --name apt-test-update \ |
| 113 | + mock-apt-repo |
| 114 | +
|
| 115 | + - name: Verify container is running |
| 116 | + run: docker ps |
| 117 | + |
| 118 | + # (Optional) wait a bit if your container needs to boot services |
| 119 | + - name: Wait for container to be ready |
| 120 | + run: | |
| 121 | + for i in {1..30}; do |
| 122 | + if docker exec apt-test-update sh -c 'true' 2>/dev/null; then |
| 123 | + echo "Container is ready"; break |
| 124 | + fi |
| 125 | + echo "Waiting for container... ($i)" |
| 126 | + sleep 2 |
| 127 | + done |
| 128 | +
|
| 129 | + - name: Run arduino-app-cli current version |
| 130 | + run: | |
| 131 | + mkdir -p artifacts |
| 132 | + docker exec apt-test-update sh -lc 'arduino-app-cli system version' |
| 133 | +
|
| 134 | + - name: Run arduino-app-cli with auto-yes (as arduino) |
| 135 | + run: | |
| 136 | + mkdir -p artifacts |
| 137 | + docker exec apt-test-update sh -lc 'su - arduino -c "yes | arduino-app-cli system update"' \ |
| 138 | + | tee artifacts/arduino-system-update.log |
| 139 | +
|
| 140 | + - name: Run arduino-app-cli version updated |
| 141 | + run: | |
| 142 | + mkdir -p artifacts |
| 143 | + docker exec apt-test-update sh -lc 'arduino-app-cli system version' |
| 144 | +
|
| 145 | + - name: Show recent container logs (for context) |
| 146 | + if: always() |
| 147 | + run: docker logs --tail=200 apt-test-update || true |
| 148 | + |
0 commit comments