name: CI # Tests and deploys the game into the host Docker daemon. # # * pull_request -> master : runs the server test suite (gates the merge). # * push -> master (a merge): runs the tests, then rebuilds the image and # (re)deploys the `15-puzzle` container via deploy/docker-compose.yml. # # The runner is host-mode, so docker / docker compose / git are available # directly and the image is built locally on the host daemon (no registry) — # the same pattern as ../galaxy-game/.gitea/workflows/dev-deploy.yaml. on: push: branches: [master] paths-ignore: ['**.md'] pull_request: branches: [master] paths-ignore: ['**.md'] jobs: test: runs-on: ubuntu-latest defaults: run: shell: bash steps: - name: Checkout uses: actions/checkout@v4 - name: Set up Go uses: actions/setup-go@v5 with: go-version-file: go.mod cache: true - name: Run Go tests # internal/puzzle and cmd/ui pull in desktop Ebitengine, which needs C # libraries (alsa, libX11, Xrandr) that are not installed on the runner # host. We test the server-side packages instead — exactly the code that # runs inside the deployed container (HMAC validation, file repository, # HTTP API). The wasm build is exercised by docker build in the deploy job. run: go test -count=1 ./internal/repo/... ./internal/validator/... ./internal/web-service/... deploy: needs: test if: ${{ gitea.event_name == 'push' }} runs-on: ubuntu-latest defaults: run: shell: bash steps: - name: Checkout uses: actions/checkout@v4 - name: Build image and (re)deploy container working-directory: deploy env: AWG_CONF: ${{ secrets.AWG_CONF }} BOT_TOKEN: ${{ secrets.BOT_TOKEN }} ACCESS_CODE: ${{ secrets.ACCESS_CODE }} PROJECT_LINK: ${{ vars.PROJECT_LINK }} DATA_FILE: ${{ vars.DATA_FILE }} SERVER_PORT: ${{ vars.SERVER_PORT }} CONTEXT_ROOT: ${{ vars.CONTEXT_ROOT }} run: docker compose up -d --build --remove-orphans - name: Probe the container env: SERVER_PORT: ${{ vars.SERVER_PORT }} CONTEXT_ROOT: ${{ vars.CONTEXT_ROOT }} run: | set -u port="${SERVER_PORT:-8080}" root="${CONTEXT_ROOT:-/}"; root="/${root#/}"; root="${root%/}" url="http://15-puzzle:${port}${root}/puzzle.html" echo "probing ${url}" for i in $(seq 1 15); do if docker run --rm --network edge alpine:3.20 \ wget -q -T 5 -O /dev/null "${url}"; then echo "healthy: ${url}" exit 0 fi sleep 2 done echo "probe failed for ${url}; recent container logs:" docker logs --tail 50 15-puzzle || true exit 1 - name: Prune dangling images if: always() run: docker image prune -f