name: Release

on:
  push:
    tags:
      - 'v*'

jobs:
  release:
    runs-on: ubuntu-latest
    env:
      ROLLUP_FORCE_JS: 1
    steps:
      - name: Checkout code
        uses: actions/checkout@v4
        with:
          fetch-depth: 0
          
      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '22'
          registry-url: 'https://registry.npmjs.org'
          cache: 'npm'
          
      - name: Install dependencies
        run: npm ci
      
      - name: Security audit
        run: npm run audit:ci
        
      - name: License compliance check
        run: npm run license-check
        
      - name: Run linting
        run: npm run lint
        
      - name: Build package
        run: npm run build
        
      - name: Run tests
        run: npm run test:coverage
        
      - name: Publish to npm
        run: npm publish
        env:
          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
          
      - name: Create GitHub Release
        uses: softprops/action-gh-release@v1
        with:
          tag_name: ${{ github.ref_name }}
          name: Release ${{ github.ref_name }}
          draft: false
          prerelease: ${{ contains(github.ref_name, 'alpha') || contains(github.ref_name, 'beta') || contains(github.ref_name, 'rc') }}
          body: |
            ## What's Changed
            
            See [CHANGELOG.md](./docs/CHANGELOG.md) for detailed changes.
            
            ## Installation
            
            ```bash
            npm install github-pr-automation
            ```
            
            ## Usage
            
            ### MCP Server Mode
            Add to your Claude Desktop MCP configuration:
            
            ```json
            {
              "mcpServers": {
                "github-pr-automation": {
                  "command": "npx",
                  "args": ["github-pr-automation"],
                  "env": {
                    "GITHUB_TOKEN": "your_github_token"
                  }
                }
              }
            }
            ```
            
            ### CLI Mode
            ```bash
            npx github-pr-automation get-failing-tests --pr "owner/repo#123"
            ```
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
