steps:
  tailwind:
    image: node:lts-alpine
    commands:
      - npm install
      - npx @tailwindcss/cli -o static/styles.css --minify

  zola:
    image: alpine:latest
    commands:
      - apk add --no-cache zola
      - zola build
      - rm public/404.html public/robots.txt public/sitemap.xml

  zip:
    image: alpine:latest
    commands:
      - apk add --no-cache zip
      - cd public
      - zip -r project.zip . -x ".*"
      - mv project.zip ..

  upload:
    image: alpine:latest
    commands:
      - apk add --no-cache curl
      - 'AUTH_HEADER="Authorization: Bearer $PAGES_API_KEY"'
      - API_URL=https://pages.hadeedahmad.com/pages/me
      - curl -s -w "%{http_code}" -F "zipfile=@project.zip" -H "$AUTH_HEADER" "$API_URL" | grep -q 200

    environment:
      PAGES_API_KEY:
        from_secret: PAGES_API_KEY

when:
  - event: manual
  - event: push
    branch: main