|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ "master" ] |
| 6 | + pull_request: |
| 7 | + branches: [ "master" ] |
| 8 | + |
| 9 | +env: |
| 10 | + # Path to the solution file relative to the root of the project. |
| 11 | + SOLUTION_FILE_PATH: . |
| 12 | + # Build configuration and Platform. |
| 13 | + BUILD_CONFIGURATION: Release |
| 14 | + PLATFORM: x64 |
| 15 | + |
| 16 | +permissions: |
| 17 | + contents: write |
| 18 | + |
| 19 | +jobs: |
| 20 | + build: |
| 21 | + runs-on: windows-latest |
| 22 | + steps: |
| 23 | + - name: Checkout repository with tags |
| 24 | + uses: actions/checkout@v4 |
| 25 | + with: |
| 26 | + fetch-depth: 0 # Important: Fetch all history and tags |
| 27 | + |
| 28 | + - name: Add MSBuild to PATH |
| 29 | + |
| 30 | + |
| 31 | + - name: Restore NuGet packages |
| 32 | + run: nuget restore ${{ env.SOLUTION_FILE_PATH }} |
| 33 | + |
| 34 | + - name: Build x64 Release |
| 35 | + run: msbuild /m /p:Configuration=${{ env.BUILD_CONFIGURATION }} /p:Platform=${{ env.PLATFORM }} ${{ env.SOLUTION_FILE_PATH }} |
| 36 | + |
| 37 | + - name: Determine version and create tag if needed |
| 38 | + id: version |
| 39 | + shell: cmd |
| 40 | + run: | |
| 41 | + @echo off |
| 42 | + REM Retrieve the latest tag (assumes tags are in x.y.z format) |
| 43 | + for /f "delims=" %%t in ('git describe --tags --abbrev=0') do set LATEST_TAG=%%t |
| 44 | + echo Latest tag: %LATEST_TAG% |
| 45 | + |
| 46 | + REM Get the commit hash for the latest tag and for the HEAD |
| 47 | + for /f %%i in ('git rev-list -n 1 %LATEST_TAG%') do set TAG_COMMIT=%%i |
| 48 | + for /f %%i in ('git rev-parse HEAD') do set CURRENT_COMMIT=%%i |
| 49 | + |
| 50 | + echo Tag commit: %TAG_COMMIT% |
| 51 | + echo Current commit: %CURRENT_COMMIT% |
| 52 | + |
| 53 | + if "%TAG_COMMIT%"=="%CURRENT_COMMIT%" ( |
| 54 | + echo HEAD is tagged. Using existing version %LATEST_TAG%. |
| 55 | + set "VERSION=%LATEST_TAG%" |
| 56 | + ) else ( |
| 57 | + REM Count commits since the latest tag. |
| 58 | + for /f %%i in ('git rev-list %LATEST_TAG%..HEAD --count') do set COMMITS_SINCE=%%i |
| 59 | + echo Commits since tag: %COMMITS_SINCE% |
| 60 | + |
| 61 | + REM Split LATEST_TAG into MAJOR, MINOR, and PATCH. |
| 62 | + for /f "tokens=1-3 delims=." %%a in ("%LATEST_TAG%") do ( |
| 63 | + set MAJOR=%%a |
| 64 | + set MINOR=%%b |
| 65 | + set PATCH=%%c |
| 66 | + ) |
| 67 | + set /a NEW_PATCH=%PATCH% + %COMMITS_SINCE% |
| 68 | + set "VERSION=%MAJOR%.%MINOR%.%NEW_PATCH%" |
| 69 | + echo New version: %VERSION% |
| 70 | + |
| 71 | + REM Create an annotated tag and push it. |
| 72 | + git tag -a %VERSION% -m "Auto-incremented tag %VERSION%" |
| 73 | + git push origin %VERSION% |
| 74 | + ) |
| 75 | + |
| 76 | + REM Pass the version variable to later steps. |
| 77 | + echo version=%VERSION%>> %GITHUB_OUTPUT% |
| 78 | +
|
| 79 | + - name: Rename release package with version |
| 80 | + shell: cmd |
| 81 | + run: | |
| 82 | + REM Change directory to x64\release (adjust if needed). |
| 83 | + cd x64\release |
| 84 | + REM Rename the package (assumed name RekordBoxSongExporter.zip). |
| 85 | + ren RekordBoxSongExporter.zip RekordBoxSongExporter-${{ steps.version.outputs.version }}.zip |
| 86 | +
|
0 commit comments