add: 文件整理桌面版与自动发布流程 #6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Release | |
| on: | |
| push: | |
| branches: | |
| - main | |
| tags: | |
| - 'v*' | |
| workflow_dispatch: | |
| inputs: | |
| tag: | |
| description: Release tag, for example v26.07.02 | |
| required: true | |
| type: string | |
| permissions: | |
| contents: write | |
| jobs: | |
| windows-release: | |
| name: Build Windows exe and publish release | |
| runs-on: windows-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 24 | |
| - name: Set up pnpm | |
| run: | | |
| corepack enable | |
| corepack prepare pnpm@11.7.0 --activate | |
| - name: Install dependencies | |
| run: pnpm install --frozen-lockfile | |
| - name: Run tests | |
| run: pnpm test | |
| - name: Build desktop executable | |
| env: | |
| CSC_IDENTITY_AUTO_DISCOVERY: false | |
| run: pnpm run release:desktop | |
| - name: Resolve release tag | |
| id: release | |
| shell: pwsh | |
| env: | |
| EVENT_NAME: ${{ github.event_name }} | |
| INPUT_TAG: ${{ inputs.tag }} | |
| REF_TYPE: ${{ github.ref_type }} | |
| REF_NAME: ${{ github.ref_name }} | |
| run: | | |
| [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 | |
| $OutputEncoding = [System.Text.Encoding]::UTF8 | |
| $package = Get-Content package.json -Raw | ConvertFrom-Json | |
| if ($env:EVENT_NAME -eq 'workflow_dispatch' -and $env:INPUT_TAG) { | |
| $tag = $env:INPUT_TAG | |
| } elseif ($env:REF_TYPE -eq 'tag') { | |
| $tag = $env:REF_NAME | |
| } else { | |
| $tag = "v$($package.releaseVersion)" | |
| } | |
| if (-not $tag.StartsWith('v')) { | |
| $tag = "v$tag" | |
| } | |
| "tag=$tag" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -Encoding utf8 | |
| "title=[FileOrganizer](https://github.com/cimorn/FileOrganizer)-$tag" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -Encoding utf8 | |
| "assetName=文件整理-$tag.exe" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -Encoding utf8 | |
| - name: Create or update GitHub release | |
| shell: pwsh | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| RELEASE_TAG: ${{ steps.release.outputs.tag }} | |
| RELEASE_TITLE: ${{ steps.release.outputs.title }} | |
| ASSET_NAME: ${{ steps.release.outputs.assetName }} | |
| run: | | |
| $ErrorActionPreference = 'Stop' | |
| [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 | |
| $OutputEncoding = [System.Text.Encoding]::UTF8 | |
| $asset = "dist/$env:ASSET_NAME#$env:ASSET_NAME" | |
| function Invoke-Gh { | |
| gh @args | |
| if ($LASTEXITCODE -ne 0) { | |
| throw "gh command failed: gh $($args -join ' ')" | |
| } | |
| } | |
| gh release view "$env:RELEASE_TAG" *> $null | |
| if ($LASTEXITCODE -eq 0) { | |
| $releaseJson = gh api "repos/$env:GITHUB_REPOSITORY/releases/tags/$env:RELEASE_TAG" | |
| if ($LASTEXITCODE -ne 0) { | |
| exit $LASTEXITCODE | |
| } | |
| $release = $releaseJson | ConvertFrom-Json | |
| foreach ($releaseAsset in $release.assets) { | |
| if ($releaseAsset.name.EndsWith('.exe') -and $releaseAsset.name -ne $env:ASSET_NAME) { | |
| Invoke-Gh api --method DELETE "repos/$env:GITHUB_REPOSITORY/releases/assets/$($releaseAsset.id)" | |
| } | |
| } | |
| Invoke-Gh release upload "$env:RELEASE_TAG" "$asset" --clobber | |
| Invoke-Gh release edit "$env:RELEASE_TAG" --title "$env:RELEASE_TITLE" | |
| } else { | |
| Invoke-Gh release create "$env:RELEASE_TAG" "$asset" --title "$env:RELEASE_TITLE" --generate-notes --target "${{ github.sha }}" | |
| } |