name: Extension Build & Release
on:
  push:
    branches:
      - main
    paths:
      - 'extension/**'
      - '.gitea/workflows/extension-build.yml'

jobs:
  build:
    runs-on: arm
    container:
      image: catthehacker/ubuntu:act-latest
    steps:
      - name: 获取代码
        uses: actions/checkout@v4
      
      - name: 安装 Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '20'
          
      - name: 编译浏览器扩展
        run: |
          cd extension
          npm install
          npm run build
          
      - name: 打包为 Zip 文件
        run: |
          cd extension/dist
          zip -r ../../insight-reply-extension.zip .
          
      - name: 安装 Go
        uses: actions/setup-go@v5
        with:
          go-version: '1.22'

      - name: 发布到 Gitea Release
        uses: https://gitea.com/actions/release-action@main
        with:
          files: insight-reply-extension.zip
          api_key: '${{secrets.GITEA_TOKEN}}'
          name: 'Extension "Latest"'
          tag_name: 'latest-extension'
          draft: false
          prerelease: true
