|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: write |
| 11 | + |
| 12 | +concurrency: |
| 13 | + group: release-${{ github.ref }} |
| 14 | + cancel-in-progress: false |
| 15 | + |
| 16 | +jobs: |
| 17 | + windows-release: |
| 18 | + name: Windows release |
| 19 | + runs-on: windows-latest |
| 20 | + |
| 21 | + steps: |
| 22 | + - name: Check out repository |
| 23 | + uses: actions/checkout@v4 |
| 24 | + |
| 25 | + - name: Read package version |
| 26 | + id: version |
| 27 | + shell: pwsh |
| 28 | + env: |
| 29 | + GH_TOKEN: ${{ github.token }} |
| 30 | + run: | |
| 31 | + $package = Get-Content package.json | ConvertFrom-Json |
| 32 | + $version = $package.version |
| 33 | + $tag = "v$version" |
| 34 | +
|
| 35 | + "version=$version" >> $env:GITHUB_OUTPUT |
| 36 | + "tag=$tag" >> $env:GITHUB_OUTPUT |
| 37 | +
|
| 38 | + gh release view $tag --repo $env:GITHUB_REPOSITORY *> $null |
| 39 | + if ($LASTEXITCODE -eq 0) { |
| 40 | + "release_exists=true" >> $env:GITHUB_OUTPUT |
| 41 | + "Release $tag already exists; skipping build and publish." >> $env:GITHUB_STEP_SUMMARY |
| 42 | + } else { |
| 43 | + "release_exists=false" >> $env:GITHUB_OUTPUT |
| 44 | + "Release $tag does not exist; building Windows installer." >> $env:GITHUB_STEP_SUMMARY |
| 45 | + } |
| 46 | +
|
| 47 | + - name: Set up Bun |
| 48 | + if: steps.version.outputs.release_exists != 'true' |
| 49 | + uses: oven-sh/setup-bun@v2 |
| 50 | + |
| 51 | + - name: Install dependencies |
| 52 | + if: steps.version.outputs.release_exists != 'true' |
| 53 | + run: bun install --frozen-lockfile |
| 54 | + |
| 55 | + - name: Run checks |
| 56 | + if: steps.version.outputs.release_exists != 'true' |
| 57 | + run: bun run check |
| 58 | + |
| 59 | + - name: Run unit tests |
| 60 | + if: steps.version.outputs.release_exists != 'true' |
| 61 | + run: bun run test:unit |
| 62 | + |
| 63 | + - name: Build Windows installer |
| 64 | + if: steps.version.outputs.release_exists != 'true' |
| 65 | + run: bun run dist:win |
| 66 | + |
| 67 | + - name: Upload workflow artifact |
| 68 | + if: steps.version.outputs.release_exists != 'true' |
| 69 | + uses: actions/upload-artifact@v4 |
| 70 | + with: |
| 71 | + name: path-profile-windows-${{ steps.version.outputs.version }} |
| 72 | + path: dist/Path-Profile*-win-x64.* |
| 73 | + if-no-files-found: error |
| 74 | + |
| 75 | + - name: Create GitHub release |
| 76 | + if: steps.version.outputs.release_exists != 'true' |
| 77 | + shell: pwsh |
| 78 | + env: |
| 79 | + GH_TOKEN: ${{ github.token }} |
| 80 | + run: | |
| 81 | + $tag = "${{ steps.version.outputs.tag }}" |
| 82 | + $version = "${{ steps.version.outputs.version }}" |
| 83 | + $artifacts = Get-ChildItem dist -File | |
| 84 | + Where-Object { $_.Name -like "Path-Profile*-win-x64.*" } | |
| 85 | + ForEach-Object { $_.FullName } |
| 86 | +
|
| 87 | + if (-not $artifacts) { |
| 88 | + throw "No release artifacts were found in dist/." |
| 89 | + } |
| 90 | +
|
| 91 | + gh release create $tag @artifacts ` |
| 92 | + --repo $env:GITHUB_REPOSITORY ` |
| 93 | + --title "Path Profile $version" ` |
| 94 | + --generate-notes |
0 commit comments