build: auto-tag and release anything pushed to the 'release' branch #381
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: Build App | |
| on: [ push, pull_request ] | |
| jobs: | |
| build: | |
| runs-on: windows-latest | |
| steps: | |
| - name: Inject slug/short variables | |
| uses: rlespinasse/github-slug-action@v3.x | |
| - name: Get current date | |
| id: date | |
| run: echo "::set-output name=date::$(date +'%Y-%m-%d')" | |
| - name: Set version string | |
| id: ver | |
| run: echo "::set-output name=ver::DiztinGUIsh-${{ steps.date.outputs.date }}--${{ env.GITHUB_REF_SLUG }}-${{ env.GITHUB_SHA_SHORT }}-${{env.GITHUB_REPOSITORY_OWNER_PART_SLUG != 'isofrieze' && env.GITHUB_REPOSITORY_OWNER_PART_SLUG || 'official'}}" | |
| - name: Print version | |
| run: echo "version ${{ steps.ver.outputs.ver }}" | |
| - name: Checkout | |
| uses: actions/checkout@v2 | |
| with: | |
| submodules: 'recursive' | |
| fetch-depth: 0 # Fetch all history for all tags | |
| - name: Auto-bump version and create tag on release branch | |
| if: github.ref == 'refs/heads/release' && github.event_name == 'push' | |
| run: | | |
| # Get the latest tag | |
| $latestTag = git describe --tags --abbrev=0 2>$null | |
| if (-not $latestTag) { | |
| $latestTag = "v0.0.0.0" | |
| } | |
| Write-Host "Latest tag: $latestTag" | |
| # Extract version numbers (remove 'v' prefix) | |
| $version = $latestTag.Substring(1) | |
| $versionParts = $version.Split('.') | |
| # Ensure we have 4 parts (major.minor.patch.build) | |
| while ($versionParts.Length -lt 4) { | |
| $versionParts += "0" | |
| } | |
| # Bump the patch version (third number) | |
| $major = [int]$versionParts[0] | |
| $minor = [int]$versionParts[1] | |
| $patch = [int]$versionParts[2] + 1 | |
| $build = [int]$versionParts[3] | |
| $newVersion = "$major.$minor.$patch.$build" | |
| $newTag = "v$newVersion" | |
| Write-Host "New tag: $newTag" | |
| # Configure git | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| # Create and push the new tag | |
| git tag $newTag | |
| git push origin $newTag | |
| shell: powershell | |
| - name: Setup dotnet | |
| uses: actions/setup-dotnet@v1 | |
| with: | |
| dotnet-version: 9.0.x | |
| # not currently working consistently, don't cache | |
| # - name: Nuget (restore from cache) | |
| # uses: actions/cache@v1 | |
| # id: cache | |
| # with: | |
| # path: ~/.nuget/packages | |
| # key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }} | |
| # | |
| # - name: NuGet (Restore from scratch if needed) | |
| # if: steps.cache.outputs.cache-hit != 'true' | |
| # run: dotnet restore --locked-mode | |
| - name: NuGet (Restore always from scratch) | |
| run: dotnet restore --locked-mode | |
| - name: Build | |
| run: dotnet build --no-restore --configuration Release | |
| - name: Test | |
| run: dotnet test --no-build --configuration Release | |
| # removed --no-restore on this for simplicity. it's a little more wasteful potentially though | |
| - name: Publish | |
| run: dotnet publish -c Release -r win-x64 --self-contained true /p:PublishProfile=FolderProfile /p:PublishSingleFile=true /p:IncludeNativeLibrariesForSelfExtract=true .\Diz.App.Winforms | |
| - uses: vimtor/action-zip@v1.2 | |
| with: | |
| files: Diz.App.Winforms\bin\Release\net9.0-windows\publish\ | |
| dest: ${{ steps.ver.outputs.ver }}.zip | |
| - name: Upload Artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ steps.ver.outputs.ver }}.zip | |
| path: ${{ steps.ver.outputs.ver }}.zip | |
| - name: Release | |
| uses: softprops/action-gh-release@v1 | |
| if: startsWith(github.ref, 'refs/tags/') | |
| with: | |
| files: ${{ steps.ver.outputs.ver }}.zip | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |