|
| 1 | +name: UpdateModuleTag |
| 2 | +on: |
| 3 | + workflow_dispatch: |
| 4 | + pull_request: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + - master |
| 8 | + paths-ignore: |
| 9 | + - 'docs/**' |
| 10 | + - '*.help.txt' |
| 11 | + - '*.md' |
| 12 | + |
| 13 | +jobs: |
| 14 | + UpdateModuleTag: |
| 15 | + if: ${{github.event.action == 'closed' && github.event.merged == true}} |
| 16 | + runs-on: ubuntu-latest |
| 17 | + steps: |
| 18 | + - name: Check out repository |
| 19 | + uses: actions/checkout@v2 |
| 20 | + - name: TagModuleVersion |
| 21 | + id: TagModuleVersion |
| 22 | + shell: pwsh |
| 23 | + run: | |
| 24 | + $Parameters = @{} |
| 25 | + $Parameters.ModulePath = ${env:ModulePath} |
| 26 | + $Parameters.UserEmail = ${env:UserEmail} |
| 27 | + $Parameters.UserName = ${env:UserName} |
| 28 | + $Parameters.TagVersionFormat = ${env:TagVersionFormat} |
| 29 | + $Parameters.TagAnnotationFormat = ${env:TagAnnotationFormat} |
| 30 | + foreach ($k in @($parameters.Keys)) { |
| 31 | + if ([String]::IsNullOrEmpty($parameters[$k])) { |
| 32 | + $parameters.Remove($k) |
| 33 | + } |
| 34 | + } |
| 35 | + Write-Host "::debug:: TagModuleVersion $(@(foreach ($p in $Parameters.GetEnumerator()) {'-' + $p.Key + ' ' + $p.Value}) -join ' ')" |
| 36 | + & {param( |
| 37 | + [string] |
| 38 | + $ModulePath, |
| 39 | + |
| 40 | + # The user email associated with a git commit. |
| 41 | + [string] |
| 42 | + $UserEmail, |
| 43 | + |
| 44 | + # The user name associated with a git commit. |
| 45 | + [string] |
| 46 | + $UserName, |
| 47 | + |
| 48 | + # The tag version format (default value: 'v$(imported.Version)') |
| 49 | + # This can expand variables. $imported will contain the imported module. |
| 50 | + [string] |
| 51 | + $TagVersionFormat = 'v$($imported.Version)', |
| 52 | + |
| 53 | + # The tag version format (default value: '$($imported.Name) $(imported.Version)') |
| 54 | + # This can expand variables. $imported will contain the imported module. |
| 55 | + [string] |
| 56 | + $TagAnnotationFormat = '$($imported.Name) $($imported.Version)' |
| 57 | + ) |
| 58 | + |
| 59 | + $imported = |
| 60 | + if (-not $ModulePath) { |
| 61 | + $orgName, $moduleName = $env:BUILD_REPOSITORY_ID -split "/" |
| 62 | + Import-Module ".\$moduleName.psd1" -Force -PassThru -Global |
| 63 | + } else { |
| 64 | + Import-Module $modulePath -Force -PassThru -Global |
| 65 | + } |
| 66 | + |
| 67 | + if (-not $imported) { return } |
| 68 | + |
| 69 | + $targetVersion =$ExecutionContext.InvokeCommand.ExpandString($TagVersionFormat) |
| 70 | + |
| 71 | + $versionTagExists = git tag --list | Where-Object { $_ -eq $targetVersion } |
| 72 | + |
| 73 | + if ($versionTagExists) { |
| 74 | + "::warning::Version $($versionTagExists)" |
| 75 | + return |
| 76 | + } |
| 77 | + |
| 78 | + if (-not $UserName) { $UserName = $env:GITHUB_ACTOR } |
| 79 | + if (-not $UserEmail) { $UserEmail = "[email protected]" } |
| 80 | + git config --global user.email $UserEmail |
| 81 | + git config --global user.name $UserName |
| 82 | + |
| 83 | + git tag -a $targetVersion -m $ExecutionContext.InvokeCommand.ExpandString($TagAnnotationFormat) |
| 84 | + git push --tags |
| 85 | + |
| 86 | + if ($env:GITHUB_ACTOR) { |
| 87 | + exit 0 |
| 88 | + } |
| 89 | + |
| 90 | + |
| 91 | + } @Parameters |
| 92 | +
|
0 commit comments