name: web on: push: branches: [master] tags: ["v*"] paths: ["web/**", ".gitea/workflows/web.yml"] # tags build regardless of paths pull_request: paths: ["web/**", ".gitea/workflows/web.yml"] workflow_dispatch: env: IMAGE_NAME: mamadachi-web jobs: test: runs-on: ubuntu-latest defaults: run: working-directory: web # Production runs on Postgres, so the suite runs on both databases. services: postgres: image: postgres:17-alpine env: POSTGRES_PASSWORD: imbas-pass-secure steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 with: python-version: "3.13" # same as the Dockerfile - run: pip install -r requirements-dev.txt - name: Tests on SQLite run: python -m pytest - name: Wait for Postgres run: | python - <<'EOF' import time, psycopg for _ in range(30): try: psycopg.connect("postgresql://postgres:test@postgres:5432/postgres").close() break except psycopg.OperationalError: time.sleep(2) else: raise SystemExit("Postgres service never came up") EOF - name: Tests on Postgres env: TEST_DATABASE_URL: postgresql://postgres:test@postgres:5432/postgres run: python -m pytest image: needs: test if: github.event_name != 'pull_request' runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Work out the image name and tags id: meta env: REGISTRY: ${{ vars.REGISTRY }} run: | registry="${REGISTRY:-${GITHUB_SERVER_URL#*://}}" registry="${registry%/}" owner="$(echo "$GITHUB_REPOSITORY_OWNER" | tr '[:upper:]' '[:lower:]')" image="$registry/$owner/$IMAGE_NAME" tags="$image:sha-${GITHUB_SHA::7}" if [[ "$GITHUB_REF" == refs/tags/v* ]]; then tags="$tags $image:${GITHUB_REF_NAME#v}" fi echo "registry=$registry" >> "$GITHUB_OUTPUT" echo "tags=$tags" >> "$GITHUB_OUTPUT" echo "Will push: $tags" - name: Log in to the registry run: > echo "${{ secrets.REGISTRY_TOKEN }}" | docker login "${{ steps.meta.outputs.registry }}" -u "${{ vars.REGISTRY_USER || github.actor }}" --password-stdin - name: Build run: | args="" for t in ${{ steps.meta.outputs.tags }}; do args="$args -t $t"; done docker build --pull $args \ --label org.opencontainers.image.revision="$GITHUB_SHA" \ --label org.opencontainers.image.source="$GITHUB_SERVER_URL/$GITHUB_REPOSITORY" \ web - name: Push run: for t in ${{ steps.meta.outputs.tags }}; do docker push "$t"; done # The runner builds on the host's Docker, so don't leave images piling up on the NAS. - name: Clean up if: always() run: | docker image rm ${{ steps.meta.outputs.tags }} || true docker logout "${{ steps.meta.outputs.registry }}" || true