Update DeployToNuget.yml #37
This file contains 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
# .github/workflows/auto-increment-version.yml | |
name: Auto Increment Version | |
on: | |
push: | |
branches: | |
- master # Trigger when pushed to master branch | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Setup .NET | |
uses: actions/setup-dotnet@v1 | |
with: | |
dotnet-version: '7.x' # Update to your project's .NET version | |
- name: Restore dependencies | |
run: dotnet restore | |
- name: Build | |
run: dotnet build --no-restore | |
- name: Test | |
run: dotnet test --no-build --verbosity normal | |
- name: Increment version numbers | |
run: | | |
# Retrieve the old version numbers from your .csproj file | |
OLD_VERSION=$(grep -oP '(?<=<Version>).*?(?=</Version>)' TablerForNet.csproj) | |
OLD_ASSEMBLY_VERSION=$(grep -oP '(?<=<AssemblyVersion>).*?(?=</AssemblyVersion>)' TablerForNet.csproj) | |
OLD_FILE_VERSION=$(grep -oP '(?<=<FileVersion>).*?(?=</FileVersion>)' TablerForNet.csproj) | |
# Increment the version numbers | |
NEW_VERSION=$(echo $OLD_VERSION | awk -F. 'BEGIN {OFS="."} {$NF++; print $0}') | |
NEW_ASSEMBLY_VERSION=$(echo $OLD_ASSEMBLY_VERSION | awk -F. 'BEGIN {OFS="."} {$NF++; print $0}') | |
NEW_FILE_VERSION=$(echo $OLD_FILE_VERSION | awk -F. 'BEGIN {OFS="."} {$NF++; print $0}') | |
# Update the .csproj file with the new version numbers | |
sed -i "s/<Version>$OLD_VERSION<\/Version>/<Version>$NEW_VERSION<\/Version>/" TablerForNet.csproj | |
sed -i "s/<AssemblyVersion>$OLD_ASSEMBLY_VERSION<\/AssemblyVersion>/<AssemblyVersion>$NEW_ASSEMBLY_VERSION<\/AssemblyVersion>/" TablerForNet.csproj | |
sed -i "s/<FileVersion>$OLD_FILE_VERSION<\/FileVersion>/<FileVersion>$NEW_FILE_VERSION<\/FileVersion>/" TablerForNet.csproj | |
- name: Push new version | |
run: | | |
git config --local user.email "action@github.com" | |
git config --local user.name "GitHub Action" | |
git add TablerForNet.csproj | |
git commit -m "Increment version to $NEW_VERSION" | |
git pull --rebase https://x-access-token:${{ secrets.BUMPVERSIONTOKEN }}@github.com/Nix1983/TablerForNet.git master | |
git push https://x-access-token:${{ secrets.BUMPVERSIONTOKEN }}@github.com/Nix1983/TablerForNet.git master | |