Skip to content

skip the workflow when the Azure DevOps pat is not available #91

skip the workflow when the Azure DevOps pat is not available

skip the workflow when the Azure DevOps pat is not available #91

name: Handle versioning accros branches
on:
push:
# todo: add file paths of the files with version numbers
permissions:
contents: read
jobs:
extension-versioning:
if: github.actor != 'dependabot[bot]

Check failure on line 12 in .github/workflows/handle-versioning-accross-branches.yml

View workflow run for this annotation

GitHub Actions / Handle versioning accros branches

Invalid workflow file

The workflow is not valid. .github/workflows/handle-versioning-accross-branches.yml (Line: 12, Col: 9): Unexpected symbol: ''dependabot[bot]'. Located at position 17 within expression: github.actor != 'dependabot[bot]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Harden Runner
uses: step-security/harden-runner@a4aa98b93cab29d9b1101a6143fb8bce00e2eac4 # v2.7.1
with:
egress-policy: audit
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
with:
fetch-depth: 0
- uses: git-actions/set-user@49fa9362373dabe0bfcbdb5e8d4da08045ebf6f8 # v1.0.0
- name: Prevent branch warnings
run: |
# config git advice.detachedHead to false
git config advice.detachedHead false
- uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
with:
node-version: 16
- name: Install tfx extension
run: |
npm install -g tfx-cli
- name: Get highest version number accross all branches
id: get-version
shell: pwsh
env:
AZURE_DEVOPS_PAT: ${{ secrets.AZURE_DEVOPS_PAT}}
run: |
# get the last updated version for this extension from the server
$output = $(tfx extension show --token $env:AZURE_DEVOPS_PAT --vsix $vsix --publisher "RobBos" --extension-id "GHAzDoWidget-DEV" --output json | ConvertFrom-Json)
if ($null -eq $output) {
Write-Host "No versions found on the server"
exit 1
}
$lastVersion = ($output.versions | Sort-Object -Property lastUpdated -Descending)[0]
Write-Host "Last version: [$($lastVersion.version)] from server"
# SemVer code
function Parse-SemVer ($version) {
$parts = $version.Split('.')
return @{
Major = [int]$parts[0]
Minor = [int]$parts[1]
Patch = [int]$parts[2]
}
}
$highestVersion = @{
Major = 0
Minor = 0
Patch = 0
}
# loop over all branches
$highestVersion = 0
foreach ($branch in $(git branch -r --format='%(refname:short)')) {
Write-Host "Checkout the branch [$branch]"
git checkout $branch
# get the semantic version number from the version in the dependencyReviewTask/task.json file
$version = Get-Content -Path "dependencyReviewTask/task.json" | ConvertFrom-Json | Select-Object -ExpandProperty version
Write-Host "Found version: [$version] in branch: [$branch]"
# check if the version is semantically higher than the highest version using SemVer
if ($version.Major -gt $highestVersion.Major -or
($version.Major -eq $highestVersion.Major -and $version.Minor -gt $highestVersion.Minor) -or
($version.Major -eq $highestVersion.Major -and $version.Minor -eq $highestVersion.Minor -and $version.Patch -gt $highestVersion.Patch))
{
$highestVersion = $version
Write-Host "New highest version from PR task.json: [$($highestVersion.Major).$($highestVersion.Minor).$($highestVersion.Patch)]"
}
}
Write-Host "Highest version: [$($highestVersion.Major).$($highestVersion.Minor).$($highestVersion.Patch)]"
# show the highest version number in GitHub by writing to the job summary file
Set-Content -Path $env:GITHUB_STEP_SUMMARY -Value "Highest version of the extension: [$($lastVersion.version)]"
Set-Content -Path $env:GITHUB_STEP_SUMMARY -Value "Highest version of the PR check extension: [$($highestVersion.Major).$($highestVersion.Minor).$($highestVersion.Patch)]"