Repo: Update Dotnet Version to latest released version #673
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
| --- # Create a new branch for the latest (released) dotnet version if there's an update | |
| name: "Repo: Update Dotnet Version to latest released version" | |
| on: | |
| push: | |
| branches: | |
| - "main" | |
| paths: | |
| - ".github/workflows/dotnet-version.yml" | |
| schedule: | |
| - cron: "0 1 * * *" | |
| concurrency: | |
| group: ${{github.workflow}}-${{github.ref}} | |
| cancel-in-progress: false | |
| permissions: | |
| contents: write | |
| jobs: | |
| bump-dotnet-sdk-version: | |
| if: endsWith(github.repository, 'funfair-server-template') | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: "Initialise Workspace" | |
| if: startsWith(runner.name, 'buildagent-') | |
| shell: bash | |
| run: sudo chown -R "$USER:$USER" "$GITHUB_WORKSPACE" | |
| - name: "Set Active Environment" | |
| shell: bash | |
| run: | | |
| { | |
| echo "ACTIVE_RUNNER_NAME=${{runner.name}}" | |
| echo "ACTIVE_HOSTNAME=$HOSTNAME" | |
| echo "ACTIVE_USER=$USER" | |
| } >> "$GITHUB_ENV" | |
| - name: "Checkout Source" | |
| uses: actions/[email protected] | |
| with: | |
| clean: true | |
| fetch-depth: 0 | |
| fetch-tags: true | |
| token: ${{secrets.SOURCE_PUSH_TOKEN}} | |
| - name: "Install Build tools" | |
| if: startsWith(runner.name, 'buildagent-') | |
| uses: ./.github/actions/build-tools | |
| with: | |
| GITHUB_TOKEN: ${{secrets.SOURCE_PUSH_TOKEN}} | |
| NUGET_PUBLIC_RESTORE_FEED_CACHE: ${{vars.NUGET_BAGET_CACHE}} | |
| NUGET_PUBLIC_RESTORE_FEED: ${{vars.NUGET_PUBLIC_RESTORE_FEED}} | |
| NUGET_ADDITIONAL_RESTORE_FEED_RELEASE_CACHE: ${{vars.RELEASE_BAGET_CACHE}} | |
| NUGET_ADDITIONAL_RESTORE_FEED_PRERELEASE_CACHE: ${{vars.PRERELEASE_BAGET_CACHE}} | |
| NUGET_ADDITIONAL_RESTORE_FEED_RELEASE: ${{vars.NUGET_ADDITIONAL_RESTORE_FEED_RELEASE}} | |
| NUGET_ADDITIONAL_RESTORE_FEED_PRERELEASE: ${{vars.NUGET_ADDITIONAL_RESTORE_FEED_PRERELEASE}} | |
| - name: "Install Build tools" | |
| if: startsWith(runner.name, 'buildagent-') != true | |
| uses: ./.github/actions/build-tools | |
| with: | |
| GITHUB_TOKEN: ${{secrets.SOURCE_PUSH_TOKEN}} | |
| NUGET_PUBLIC_RESTORE_FEED_CACHE: "" | |
| NUGET_PUBLIC_RESTORE_FEED: ${{vars.NUGET_PUBLIC_RESTORE_FEED}} | |
| NUGET_ADDITIONAL_RESTORE_FEED_RELEASE_CACHE: "" | |
| NUGET_ADDITIONAL_RESTORE_FEED_PRERELEASE_CACHE: "" | |
| NUGET_ADDITIONAL_RESTORE_FEED_RELEASE: ${{vars.NUGET_ADDITIONAL_RESTORE_FEED_RELEASE}} | |
| NUGET_ADDITIONAL_RESTORE_FEED_PRERELEASE: ${{vars.NUGET_ADDITIONAL_RESTORE_FEED_PRERELEASE}} | |
| - name: "Get latest installed dotnet version" | |
| id: latest-dotnet-version | |
| run: | | |
| echo "Versions installed:" | |
| dotnet --list-sdks | cut -f 1 -d " " | grep "^[0-9]*\.[0-9]*\.[0-9]*$" | sort --version-sort | |
| echo "Latest Version: $(dotnet --list-sdks | cut -f 1 -d " " | grep "^[0-9]*\.[0-9]*\.[0-9]*$" | sort --version-sort | tail -1)" | |
| echo "LATEST_RELEASE_VERSION=$(dotnet --list-sdks | cut -f 1 -d " " | grep "^[0-9]*\.[0-9]*\.[0-9]*$" | sort --version-sort | tail -1)" >> "$GITHUB_OUTPUT" | |
| - name: "Display latest installed dotnet version" | |
| run: | | |
| echo "Latest installed dotnet version: ${{steps.latest-dotnet-version.outputs.LATEST_RELEASE_VERSION}}" | |
| echo "Requested dotnet version: ${{env.DOTNET_VERSION}}" | |
| - name: "Check if Latest is newer than the current defined" | |
| id: upgrade_check | |
| run: | | |
| VER=$(echo "${{env.DOTNET_VERSION}} ${{steps.latest-dotnet-version.outputs.LATEST_RELEASE_VERSION}}" | tr ' ' '\n' | uniq | sort --version-sort | tail -1) | |
| echo "Latest Version: $VER" | |
| [[ "$VER" == "${{steps.latest-dotnet-version.outputs.LATEST_RELEASE_VERSION}}" ]] && echo "NEW_VERSION=true" >> "$GITHUB_OUTPUT" || echo "NEW_VERSION=false" >> "$GITHUB_OUTPUT" | |
| - name: "Switch to version branch" | |
| if: steps.upgrade_check.outputs.NEW_VERSION == 'true' | |
| shell: bash | |
| run: | | |
| git checkout "depends/dotnet/${{env.NEW_DOTNET_VERSION}}" || git checkout -b "depends/dotnet/${{env.NEW_DOTNET_VERSION}}" | |
| env: | |
| NEW_DOTNET_VERSION: ${{steps.latest-dotnet-version.outputs.LATEST_RELEASE_VERSION}} | |
| - name: "Update global.json to latest version" | |
| if: steps.upgrade_check.outputs.NEW_VERSION == 'true' | |
| shell: bash | |
| working-directory: src | |
| run: | | |
| echo "Should update to ${{steps.latest-dotnet-version.outputs.LATEST_RELEASE_VERSION}}" | |
| mv "global.json" "global.json.tmp"; | |
| jq --arg v "$NEW_DOTNET_VERSION" '.sdk.version = $v' < "global.json.tmp" > "global.json"; | |
| [ -f "global.json.tmp" ] && rm -f "global.json.tmp" | |
| cat "global.json" | |
| env: | |
| NEW_DOTNET_VERSION: ${{steps.latest-dotnet-version.outputs.LATEST_RELEASE_VERSION}} | |
| - name: "Commit changes to new branch" | |
| if: steps.upgrade_check.outputs.NEW_VERSION == 'true' | |
| uses: stefanzweifel/[email protected] | |
| with: | |
| commit_message: "SDK - Update DotNet SDK to ${{steps.latest-dotnet-version.outputs.LATEST_RELEASE_VERSION}}" | |
| branch: "depends/dotnet/${{steps.latest-dotnet-version.outputs.LATEST_RELEASE_VERSION}}" | |
| file_pattern: src/global.json | |
| commit_user_name: "fun-version[bot]" | |
| commit_user_email: "[email protected]" | |
| commit_author: "fun-version[bot] <[email protected]>" | |
| skip_dirty_check: false |