|
| 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 | + ARCH: amd64 |
| 27 | + APPCLI_REPO: arduino/arduino-app-cli |
| 28 | + ROUTER_REPO: arduino/arduino-router |
| 29 | + STABLE_DIR: build/stable |
| 30 | + |
| 31 | + steps: |
| 32 | + - name: Checkout |
| 33 | + uses: actions/checkout@v4 |
| 34 | + |
| 35 | + - name: Set up Go |
| 36 | + uses: actions/setup-go@v5 |
| 37 | + with: |
| 38 | + go-version-file: go.mod |
| 39 | + |
| 40 | + # - name: Set up Docker |
| 41 | + # uses: docker/setup-docker-action@v2 |
| 42 | + |
| 43 | + # - name: Set up Docker Buildx |
| 44 | + # uses: docker/setup-buildx-action@v3 |
| 45 | + |
| 46 | + - name: Install Task (go-task) |
| 47 | + run: | |
| 48 | + go tool task --version |
| 49 | +
|
| 50 | + - name: Prepare folder |
| 51 | + run: | |
| 52 | + mkdir -p "${STABLE_DIR}" |
| 53 | +
|
| 54 | + - name: Checkout |
| 55 | + uses: actions/checkout@v4 |
| 56 | + |
| 57 | + |
| 58 | + - name: Configure Git for private repo cloning |
| 59 | + env: |
| 60 | + GITHUB_USERNAME: ${{ secrets.GITHUB_USERNAME }} |
| 61 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 62 | + run: | |
| 63 | + git config --global url."https://${GITHUB_USERNAME}:${GITHUB_TOKEN}@github.com".insteadOf "https://github.com" |
| 64 | +
|
| 65 | + - name: Install jq & curl |
| 66 | + run: | |
| 67 | + sudo apt-get update |
| 68 | + sudo apt-get install -y jq curl |
| 69 | +
|
| 70 | + - name: Fetch .debs dynamically into build/stable |
| 71 | + env: |
| 72 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} # for private access; use a PAT with repo scope if needed |
| 73 | + run: | |
| 74 | + set -euo pipefail |
| 75 | + mkdir -p build/stable |
| 76 | +
|
| 77 | + fetch_deb () { |
| 78 | + local repo="$1" tag="${2:-}" regex="$3" |
| 79 | +
|
| 80 | + echo "==> Resolving release for ${repo} (tag='${tag:-<latest>}')" |
| 81 | + if [ -n "${tag}" ]; then |
| 82 | + url="https://api.github.com/repos/${repo}/releases/tags/${tag}" |
| 83 | + else |
| 84 | + url="https://api.github.com/repos/${repo}/releases/latest" |
| 85 | + fi |
| 86 | +
|
| 87 | + # Get release JSON |
| 88 | + rel="$(curl -sfL -H "Authorization: token ${GH_TOKEN}" -H "Accept: application/vnd.github+json" "${url}")" |
| 89 | +
|
| 90 | + # Extract asset that matches regex |
| 91 | + name="$(echo "$rel" | jq -r --arg re "${regex}" '.assets[] | select(.name | test($re)) | .name' | head -n1)" |
| 92 | + dl="$(echo "$rel" | jq -r --arg re "${regex}" '.assets[] | select(.name | test($re)) | .browser_download_url' | head -n1)" |
| 93 | +
|
| 94 | + if [ -z "${name}" ] || [ "${name}" = "null" ] || [ -z "${dl}" ] || [ "${dl}" = "null" ]; then |
| 95 | + echo "!! No asset found in ${repo} matching regex: ${regex}" |
| 96 | + echo " Available assets were:" |
| 97 | + echo "$rel" | jq -r '.assets[].name' |
| 98 | + exit 1 |
| 99 | + fi |
| 100 | +
|
| 101 | + echo "Found asset: ${name}" |
| 102 | + echo "Downloading: ${dl}" |
| 103 | + curl -sfL -H "Authorization: token ${GH_TOKEN}" -o "build/stable/${name}" "${dl}" |
| 104 | + ls -lh "build/stable/${name}" |
| 105 | + } |
| 106 | +
|
| 107 | + # Arduino App CLI |
| 108 | + fetch_deb "${APPCLI_REPO}" "${APPCLI_TAG}" "${APPCLI_REGEX}" |
| 109 | +
|
| 110 | + # Arduino Router |
| 111 | + fetch_deb "${ROUTER_REPO}" "${ROUTER_TAG}" "${ROUTER_REGEX}" |
| 112 | + - name: List assets for Arduino App CLI v0.6.6 |
| 113 | + env: |
| 114 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 115 | + run: | |
| 116 | + curl -H "Authorization: token ${GITHUB_TOKEN}" \ |
| 117 | + -H "Accept: application/vnd.github+json" \ |
| 118 | + "https://api.github.com/repos/arduino/arduino-app-cli/releases/tags/v0.6.6" \ |
| 119 | + | jq -r '.assets[] | "\(.name) -> \(.browser_download_url)"' |
| 120 | +
|
| 121 | + - name: Download Arduino App CLI .deb |
| 122 | + run: | |
| 123 | + mkdir -p build/stable |
| 124 | + wget -O build/stable/arduino-app-cli_0.6.6_amd64.deb \ |
| 125 | + https://github.com/arduino/arduino-app-cli/releases/download/0.6.6/arduino-app-cli_0.6.6_amd64.deb |
| 126 | + |
| 127 | + - name: Download Arduino Router .deb |
| 128 | + run: | |
| 129 | + mkdir -p build/stable |
| 130 | + wget -O build/stable/arduino-router_0.5.3_amd64.deb \ |
| 131 | + https://github.com/arduino/arduino-router/releases/download/v0.5.3/arduino-router_0.5.3_amd64.deb |
| 132 | +
|
| 133 | + - name: Build Docker image (no cache) |
| 134 | + run: | |
| 135 | + docker build --no-cache -t mock-apt-repo -f test.Dockerfile . |
| 136 | + |
| 137 | + - name: Run mock-apt-repo container |
| 138 | + run: | |
| 139 | + docker run --rm -d \ |
| 140 | + --privileged \ |
| 141 | + --cgroupns=host \ |
| 142 | + -v /sys/fs/cgroup:/sys/fs/cgroup:rw \ |
| 143 | + -v /var/run/docker.sock:/var/run/docker.sock \ |
| 144 | + -e DOCKER_HOST=unix:///var/run/docker.sock \ |
| 145 | + --name apt-test-update \ |
| 146 | + mock-apt-repo |
| 147 | +
|
| 148 | + - name: Verify container is running |
| 149 | + run: docker ps |
0 commit comments