# .github/workflows/release.yml
name: Release

on:
  push:
  workflow_dispatch:

jobs:
  release:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      packages: write
    steps:
      - uses: actions/checkout@v3

      # 发布到 NPM Registry
      - name: Setup Node.js for NPM
        uses: actions/setup-node@v3
        with:
          node-version: 20
          registry-url: 'https://registry.npmjs.org/'
      - run: npm install
      - name: Publish to NPM
        run: npm publish --access public
        env:
          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

      # 发布到 GitHub Packages
      - name: Setup Node.js for GitHub Packages
        uses: actions/setup-node@v3
        with:
          node-version: 20
          registry-url: 'https://npm.pkg.github.com'
      - name: Update package name for GitHub Packages
        run: |
          json=`cat package.json`
          echo "$json" | jq '.name = "@neteasecloudmusicapienhanced/api"' > package.json
      - name: Publish to GitHub Packages
        run: npm publish --access public
        env:
          NODE_AUTH_TOKEN: ${{ github.token }}
