name: build quyun abc
run-name: ${{ gitea.actor }} build quyun
on: [push]

jobs:
  Build:
    runs-on: ubuntu-latest
    steps:
      - name: Check out repository code
        uses: actions/checkout@v4

      - name: Set up Node.js
        uses: actions/setup-node@v4
        with:
          node-version: "22"

      - name: build frontend/Admin
        run: |
          cd frontend/admin
          npm config set registry https://npm.hub.ipao.vip
          npm install -g bun
          bun install
          bun run build

      - name: build frontend/Wechat
        run: |
          cd frontend/wechat
          npm config set registry https://npm.hub.ipao.vip
          npm install -g bun
          bun install
          bun run build

      - name: Set up Go
        uses: actions/setup-go@v3
        with:
          go-version: "1.24"

      - name: Build Go App
        run: |
          cd backend
          mkdir -p build
          go env -w GOPROXY=https://go.hub.ipao.vip,direct
          go env -w GONOPROXY='git.ipao.vip'
          go env -w GONOSUMDB='git.ipao.vip'
          go mod tidy
          CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o build/app .

      - name: Build Docker image
        run: |
          docker login -u ${{ secrets.DOCKER_AF_USERNAME }} -p ${{ secrets.DOCKER_AF_PASSWORD }} docker-af.hub.ipao.vip
          docker build -f Dockerfile --push -t docker-af.hub.ipao.vip/rogeecn/quyun:latest  .

      - name: Send Message To Gotify
        run: |
          curl -X POST "https://gotify.jdwan.com/message?token=${{ secrets.GOTIFY_TOKEN }}" \
          -H "Content-Type: application/json" \
          -d '{
            "title": "GITEA Build: quyun ",
            "message": "quyun Build Success",
            "priority": 5
          }'
