# Tests every pull request and every push to main. When the tests pass on main, builds the # Docker image and pushes it to this Gitea server's container registry, then (optionally) # tells Portainer to redeploy. Secrets and variables it uses are listed in docs/runbook.md. name: CI on: push: branches: [main] pull_request: jobs: test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: node-version: 24 cache: npm - run: npm ci - run: npm run lint - run: npm run check - run: npm test - run: npm run build image: needs: test if: github.event_name == 'push' runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Work out the image name id: image run: | registry="${GITHUB_SERVER_URL#*://}" registry="${registry%/}" repository="$(echo "$GITHUB_REPOSITORY" | tr '[:upper:]' '[:lower:]')" echo "registry=$registry" >> "$GITHUB_OUTPUT" echo "name=$registry/$repository" >> "$GITHUB_OUTPUT" echo "short_sha=$(echo "$GITHUB_SHA" | cut -c1-7)" >> "$GITHUB_OUTPUT" - name: Log in to the registry env: REGISTRY: ${{ steps.image.outputs.registry }} REGISTRY_USERNAME: ${{ vars.REGISTRY_USERNAME || github.repository_owner }} REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }} run: echo "$REGISTRY_TOKEN" | docker login "$REGISTRY" -u "$REGISTRY_USERNAME" --password-stdin # ORIGIN is fixed into the image at build time; leave the variable unset behind an HTTPS proxy - name: Build env: IMAGE: ${{ steps.image.outputs.name }} SHORT_SHA: ${{ steps.image.outputs.short_sha }} ORIGIN: ${{ vars.ORIGIN }} run: > docker build --build-arg ORIGIN="$ORIGIN" --label org.opencontainers.image.revision="$GITHUB_SHA" --tag "$IMAGE:latest" --tag "$IMAGE:$SHORT_SHA" . - name: Push env: IMAGE: ${{ steps.image.outputs.name }} run: docker push --all-tags "$IMAGE" - name: Redeploy in Portainer env: PORTAINER_WEBHOOK_URL: ${{ secrets.PORTAINER_WEBHOOK_URL }} run: | if [ -z "$PORTAINER_WEBHOOK_URL" ]; then echo "PORTAINER_WEBHOOK_URL is not set; redeploy the stack in Portainer by hand." exit 0 fi curl --fail --silent --show-error --request POST "$PORTAINER_WEBHOOK_URL"