From 8db95ed17752792b21c20836554aacd836573113 Mon Sep 17 00:00:00 2001 From: Artur Stolear Date: Thu, 25 Jul 2024 12:24:59 +0200 Subject: [PATCH] add example workflow that updates to latest version the tasks/actions --- .github/workflows/examples-version.yml | 32 ++++++++++++++++++++++++++ update-version.ps1 | 20 ++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 .github/workflows/examples-version.yml create mode 100644 update-version.ps1 diff --git a/.github/workflows/examples-version.yml b/.github/workflows/examples-version.yml new file mode 100644 index 0000000..5bcde11 --- /dev/null +++ b/.github/workflows/examples-version.yml @@ -0,0 +1,32 @@ +name: Update examples version + +on: + repository_dispatch: + types: [ update-examples ] + +defaults: + run: + shell: pwsh + +jobs: + update-examples-version: + if: ${{ github.event_name == 'repository_dispatch' }} + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + token: ${{ secrets.PUSH_GITHUB_TOKEN }} + - run: | + $oldTag = "${{ github.event.client_payload.oldTag }}" + $newTag = "${{ github.event.client_payload.newTag }}" + + . .\update-version.ps1 # Import the functions + dir -r .github\**\*.yml | % { update-md-files $_ -OldVersion $oldTag -NewVersion $newTag } + dir -r .azure\**\*.yml | % { update-md-files $_ -OldVersion $oldTag -NewVersion $newTag } + + git add --verbose . + git config user.name 'Artur Stolear' + git config user.email 'artur.stolear@gmail.com' + git commit -m "update examples version to $newTag" --allow-empty + git push --force + name: Update examples version diff --git a/update-version.ps1 b/update-version.ps1 new file mode 100644 index 0000000..b7d11db --- /dev/null +++ b/update-version.ps1 @@ -0,0 +1,20 @@ +function update-md-files() +{ + param( + [Parameter(Mandatory = $True, Position = 0, ValueFromPipeline = $true)] + [System.String] + $file, + + [Parameter(Mandatory = $True, Position = 1, ValueFromPipeline = $false)] + [System.String] + $oldVersion, + + [Parameter(Mandatory = $True, Position = 2, ValueFromPipeline = $false)] + [System.String] + $newVersion + ) + $file = Resolve-Path $file + Write-Host "Update md file $file version from $oldVersion to $newVersion" + + ((Get-Content $file -Raw) -replace $oldVersion, $newVersion) | Set-Content $file -NoNewline +}