name: Deploy Application
on: [push]

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v3
        with:
          token: 0406afe7de6547e850dd62c84976c6def23a5193

      - name: Install curl
        run: |
          if command -v apt-get &> /dev/null; then
            apt-get update && apt-get install -y curl
          elif command -v apk &> /dev/null; then
            apk add --no-cache curl
          elif command -v yum &> /dev/null; then
            yum install -y curl
          fi

      - name: Upload config files to server
        env:
          GITEA_API: "https://gitea.miduway.space/api/v1/repos/levis/ebook/raw/main"
          GITEA_TOKEN: "0406afe7de6547e850dd62c84976c6def23a5193"
        run: |
          for file in docker-compose.yml Dockerfile; do
            echo "Uploading $file"
            curl -X PUT \
              -H "Authorization: token $GITEA_TOKEN" \
              -T "$file" \
              "$GITEA_API/$file"
          done
