name: 打包
on: 
    workflow_dispatch:
jobs:
    build-windows: 
        runs-on: windows-latest
        steps:
            - uses: actions/checkout@v4
            - uses: actions/setup-node@v4
              with:
                node-version: 18
            - run: echo (node -p -e '`VERSION=${require("./package.json").version}`') >> $Env:GITHUB_ENV
            - run: npm install
            - run: npm run package
            - uses: maotoumao/inno-setup-action-cli@main
              with: 
                  filepath: ./release/build-windows.iss
                  variables: /DMyAppVersion=${{ env.VERSION }} /DMyAppId=${{ secrets.MYAPPID }}
            - name: Upload Setup
              uses: actions/upload-artifact@v4
              with:
                  name: windows-release
                  path: ./out/MusicFreeSetup.exe
            - name: Generate Portable
              run: mkdir ./out/MusicFree-win32-x64/portable
            - uses: vimtor/action-zip@v1.1
              with:
                files: ./out/MusicFree-win32-x64
                dest: MusicFree-win32-x64-portable.zip
            - name: Upload Portable
              uses: actions/upload-artifact@v4
              with:
                  name: windows-portable-release
                  path: ${{ github.workspace }}/MusicFree-win32-x64-portable.zip

    build-windows-legacy: 
        runs-on: windows-latest
        steps:
            - uses: actions/checkout@v4
            - uses: actions/setup-node@v4
              with:
                node-version: 18
            - run: echo (node -p -e '`VERSION=${require("./package.json").version}`') >> $Env:GITHUB_ENV
            - run: npm install
            - run: npm install electron@22
            - run: npm run package
            - uses: maotoumao/inno-setup-action-cli@main
              with: 
                  filepath: ./release/build-windows.iss
                  variables: /DMyAppVersion=${{ env.VERSION }} /DMyAppId=${{ secrets.MYAPPID }}
            - name: Upload Setup
              uses: actions/upload-artifact@v4
              with:
                  name: windows-legacy-release
                  path: ./out/MusicFreeSetup.exe
            - name: Generate Portable
              run: mkdir ./out/MusicFree-win32-x64/portable
            - uses: vimtor/action-zip@v1.1
              with:
                files: ./out/MusicFree-win32-x64
                dest: MusicFree-win32-x64-legacy-portable.zip
            - name: Upload Portable
              uses: actions/upload-artifact@v4
              with:
                  name: windows-legacy-portable-release
                  path: ${{ github.workspace }}/MusicFree-win32-x64-legacy-portable.zip

    build-macos-x64: 
        runs-on: macos-13
        steps:
            - uses: actions/checkout@v4
            - uses: actions/setup-python@v4
              with:
                python-version: '3.10'
            - uses: actions/setup-node@v4
              with:
                node-version: 18
            - run: node -p -e '`VERSION=${require("./package.json").version}`' >> $GITHUB_ENV
            - run: npm install
            - run: npm run make
            - run: ls ./out/make
            - name: Upload Setup
              uses: actions/upload-artifact@v4
              with:
                  name: macos-x64-dmg-release
                  path: ./out/make/MusicFree-${{ env.VERSION }}-x64.dmg

    build-macos-arm64: 
        runs-on: macos-latest
        steps:
            - uses: actions/checkout@v4
            - uses: actions/setup-python@v4
              with:
                python-version: '3.10'
            - uses: actions/setup-node@v4
              with:
                node-version: 18
            - run: node -p -e '`VERSION=${require("./package.json").version}`' >> $GITHUB_ENV
            - run: npm install
            - run: npm run make -- --arch="arm64"
            - name: Upload Setup
              uses: actions/upload-artifact@v4
              with:
                  name: macos-arm64-dmg-release
                  path: ./out/make/MusicFree-${{ env.VERSION }}-arm64.dmg

    build-ubuntu: 
        runs-on: ubuntu-latest
        steps:
            - uses: actions/checkout@v4
            - uses: actions/setup-node@v4
              with:
                node-version: 18
            - run: node -p -e '`VERSION=${require("./package.json").version}`' >> $GITHUB_ENV
            - run: npm install
            - run: npm run make
            - name: Upload Setup
              uses: actions/upload-artifact@v4
              with:
                  name: ubuntu-release
                  path: ./out/make/deb/x64/

