# Publishes a GitHub release when a version tag is pushed: # git tag v1.2.0 && git push origin v1.2.0 # # Repository secrets (Settings > Secrets and variables > Actions), optional but recommended: # LASTFM_API_KEY / LASTFM_API_SECRET baked into the exe and the Mac app so users don't need their own API key # # One release holds both platforms: the Windows job creates it, the macOS job builds in parallel # and attach-macos adds the Mac zip once both are done. name: Release on: push: tags: ['v*'] permissions: contents: write jobs: release: name: Windows + create release runs-on: windows-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-dotnet@v4 with: dotnet-version: '10.0.x' - name: Test run: dotnet test AppleMusicScrobbler.sln -c Release - name: Build shell: pwsh env: LASTFM_API_KEY: ${{ secrets.LASTFM_API_KEY }} LASTFM_API_SECRET: ${{ secrets.LASTFM_API_SECRET }} run: | if (-not $env:LASTFM_API_KEY) { Write-Host "::warning::LASTFM_API_KEY secret not set - users will have to create their own Last.fm API key." } $version = '${{ github.ref_name }}'.TrimStart('v') dotnet build src/AppleMusicScrobbler -c Release ` "-p:Version=$version" ` "-p:LastFmApiKey=$env:LASTFM_API_KEY" ` "-p:LastFmApiSecret=$env:LASTFM_API_SECRET" ` "-p:GitHubRepo=${{ github.repository }}" if ($LASTEXITCODE) { exit $LASTEXITCODE } - name: Create release shell: pwsh env: GH_TOKEN: ${{ github.token }} run: | $exe = 'src/AppleMusicScrobbler/bin/Release/net48/AppleMusicScrobbler.exe' $hash = (Get-FileHash $exe -Algorithm SHA256).Hash.ToLower() $prerelease = if ('${{ github.ref_name }}' -like '*-*') { '--prerelease' } else { $null } gh release create '${{ github.ref_name }}' $exe ` --title 'Apple Music Scrobbler ${{ github.ref_name }}' ` --notes "**Windows:** download ``AppleMusicScrobbler.exe`` below, put it somewhere permanent and run it.`n`nSHA-256: ``$hash``" ` --generate-notes $prerelease macos: runs-on: macos-latest defaults: run: working-directory: macos steps: - uses: actions/checkout@v4 - name: Test run: swift test - name: Build app env: LASTFM_API_KEY: ${{ secrets.LASTFM_API_KEY }} LASTFM_API_SECRET: ${{ secrets.LASTFM_API_SECRET }} GITHUB_REPO: ${{ github.repository }} UNIVERSAL: '1' run: ./build-app.sh '${{ github.ref_name }}' - uses: actions/upload-artifact@v4 with: name: AppleMusicScrobbler-macOS path: macos/build/AppleMusicScrobbler-macOS.zip attach-macos: name: Add the Mac app to the release needs: [release, macos] runs-on: ubuntu-latest steps: - uses: actions/download-artifact@v4 with: name: AppleMusicScrobbler-macOS - name: Upload env: GH_TOKEN: ${{ github.token }} GH_REPO: ${{ github.repository }} TAG: ${{ github.ref_name }} run: | gh release upload "$TAG" AppleMusicScrobbler-macOS.zip --clobber hash=$(sha256sum AppleMusicScrobbler-macOS.zip | cut -d' ' -f1) body=$(gh release view "$TAG" --json body -q .body) printf '%s\n\n**Mac** (macOS 13 or newer): download `AppleMusicScrobbler-macOS.zip` below, unzip it and move the app to Applications before opening it. The app isn'"'"'t notarized by Apple; see the README for how to open it the first time.\n\nSHA-256: `%s`\n' "$body" "$hash" > notes.md gh release edit "$TAG" --notes-file notes.md