Merge pull request #37 from timonmdy/v2.2/hotfix-3 #34
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 | |
| permissions: | |
| contents: write | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| jobs: | |
| release: | |
| runs-on: windows-latest | |
| steps: | |
| # Checkout FIRST (needed to read package.json) | |
| - uses: actions/checkout@v4 | |
| # Get version early | |
| - name: Get version | |
| id: version | |
| shell: pwsh | |
| run: | | |
| $pkg = Get-Content package.json | ConvertFrom-Json | |
| $version = $pkg.version | |
| echo "version=$version" >> $env:GITHUB_OUTPUT | |
| echo "tag=v$version" >> $env:GITHUB_OUTPUT | |
| echo "name=jrc-v$version" >> $env:GITHUB_OUTPUT | |
| # Get latest release | |
| - name: Get latest release | |
| id: latest | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| try { | |
| const res = await github.rest.repos.getLatestRelease({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo | |
| }); | |
| return res.data.tag_name; | |
| } catch (e) { | |
| return null; | |
| } | |
| # Decide if we should continue | |
| - name: Check if version changed | |
| id: should_release | |
| shell: bash | |
| run: | | |
| echo "Latest: ${{ steps.latest.outputs.result }}" | |
| echo "Current: ${{ steps.version.outputs.tag }}" | |
| if [ "${{ steps.latest.outputs.result }}" = "${{ steps.version.outputs.tag }}" ]; then | |
| echo "release=false" >> $GITHUB_OUTPUT | |
| echo "No version change → stopping early" | |
| else | |
| echo "release=true" >> $GITHUB_OUTPUT | |
| echo "Version changed → continue" | |
| fi | |
| # 🚀 HARD STOP (nothing else runs) | |
| - name: Stop if no release | |
| if: steps.should_release.outputs.release == 'false' | |
| run: exit 0 | |
| # ------------------------- | |
| # ONLY RUNS IF VERSION CHANGED | |
| # ------------------------- | |
| - name: Setup Node | |
| if: steps.should_release.outputs.release == 'true' | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| - name: Install deps | |
| if: steps.should_release.outputs.release == 'true' | |
| run: npm ci | |
| - name: Build (dist) | |
| if: steps.should_release.outputs.release == 'true' | |
| run: npm run dist | |
| # Find EXE | |
| - name: Locate EXE | |
| if: steps.should_release.outputs.release == 'true' | |
| id: exe | |
| shell: pwsh | |
| run: | | |
| $version = "${{ steps.version.outputs.version }}" | |
| $file = Get-ChildItem -Recurse -Filter "Java Runner Client Setup $version.exe" | Select-Object -First 1 | |
| if (-not $file) { | |
| Write-Error "EXE not found" | |
| exit 1 | |
| } | |
| echo "path=$($file.FullName)" >> $env:GITHUB_OUTPUT | |
| # Release notes | |
| - name: Generate release notes | |
| if: steps.should_release.outputs.release == 'true' | |
| run: | | |
| cat <<EOF > RELEASE_NOTES.md | |
| ### Version ${{ steps.version.outputs.name }} | |
| Bugfixes: | |
| - [...] | |
| ___ | |
| Additions: | |
| - [...] | |
| ___ | |
| Adjustments/Changes: | |
| - [...] | |
| EOF | |
| shell: bash | |
| # Create release | |
| - name: Create draft release | |
| if: steps.should_release.outputs.release == 'true' | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ steps.version.outputs.tag }} | |
| name: ${{ steps.version.outputs.name }} | |
| body_path: RELEASE_NOTES.md | |
| draft: true | |
| files: ${{ steps.exe.outputs.path }} | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |