Skip to content

Commit

Permalink
Merge pull request #69 from Lombiq/issue/OSOE-385
Browse files Browse the repository at this point in the history
OSOE-385: verify-dotnet-consolidation action should not fail the installation if it's already installed
  • Loading branch information
Piedone authored Oct 14, 2022
2 parents 654cfe2 + e687c28 commit 1b9c7ff
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ runs:
shell: pwsh
run: |
"${{ github.action_path }}" >> $Env:GITHUB_PATH
Join-Path -Resolve "${{ github.action_path }}" .. verify-submodule-pull-request >> $Env:GITHUB_PATH
(Resolve-Path "${{ github.action_path }}/../../../Scripts").Path >> $Env:GITHUB_PATH
# Don't do anything for pull requests that are already related to an issue, i.e. their titles start with an issue
# key.
Expand All @@ -32,7 +32,7 @@ runs:
PR_TITLE: ${{ github.event.pull_request.title }}
shell: pwsh
run: |
$output = "${{ github.event.pull_request }}" -eq "" ? "False" : (Check-PullRequestTitle "$($Env:PR_TITLE)")
$output = "${{ github.event.pull_request }}" -eq "" ? "False" : (Confirm-PullRequestTitle "$($Env:PR_TITLE)")
Write-Output "::set-output name=is-issue-pr::$output"
- name: Login to Jira
Expand Down
22 changes: 22 additions & 0 deletions .github/actions/install-dotnet-tool/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Install .NET tool
description: Installs a .NET tool globally.

inputs:
name:
required: true
description: The name of the tool to install.
version:
required: true
description: The version of the tool to install.

runs:
using: "composite"
steps:
- name: Setup Scripts
shell: pwsh
run: |
(Resolve-Path "${{ github.action_path }}/../../../Scripts").Path >> $Env:GITHUB_PATH
- name: Install tool
shell: pwsh
run: |
Install-DotNetTool -Name "${{ inputs.name }}" -Version "${{ inputs.version }}" -Global
8 changes: 5 additions & 3 deletions .github/actions/verify-dotnet-consolidation/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ inputs:
runs:
using: "composite"
steps:
- name: Setup
shell: pwsh
run: dotnet tool install dotnet-consolidate --global --version 2.0.0
- name: Install dotnet-consolidate
uses: Lombiq/GitHub-Actions/.github/actions/install-dotnet-tool@dev
with:
name: dotnet-consolidate
version: 2.0.0
- name: Verify consolidation status
shell: pwsh
working-directory: ${{ inputs.directory }}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
param([string] $Title)

if (Check-PullRequestTitle $Title) { exit 0 }
if (Confirm-PullRequestTitle $Title) { exit 0 }
Set-Failed ('The pull request title is not in the expected format. Please start with the issue code followed by a ' +
'colon and the title, e.g. "PROJ-123: My PR Title".')

This file was deleted.

1 change: 1 addition & 0 deletions .github/actions/verify-submodule-pull-request/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ runs:
Write-Output "Pull Request Title: ${{ inputs.title }}"
"${{ github.action_path }}" >> $Env:GITHUB_PATH
(Resolve-Path "${{ github.action_path }}/../../../Scripts").Path >> $Env:GITHUB_PATH
New-Item -ItemType File -Force $Profile | Out-Null
Get-Content -Raw ${{ github.action_path }}/functions.ps1 >> $Profile
Expand Down
6 changes: 6 additions & 0 deletions Scripts/Confirm-PullRequestTitle.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
param (
[Parameter(Mandatory = $true, Position = 0)]
[string] $Title
)

return $Title -match '^\s*\w+-\d+\s*:'
48 changes: 48 additions & 0 deletions Scripts/Install-DotNetTool.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
param (
[Parameter(Mandatory = $true, Position = 1, HelpMessage = "The name of the tool to install.")]
[string]
$Name,

[Parameter(Mandatory = $true, Position = 2, HelpMessage = "The version of the tool to install.")]
[string]
$Version,

[Parameter(HelpMessage = "When present, the tool will be installed globally, locally otherwise.")]
[switch]
$Global
)

$scopeString = ""
if ($Global.IsPresent)
{
$scopeString = "--global"
}

$installedTool = dotnet tool list $scopeString | Select-Object -Skip 2 | ForEach-Object {
$segments = $_.Split(" ", [System.StringSplitOptions]::RemoveEmptyEntries)
return New-Object -TypeName PSObject -Property @{
PackageId = $segments[0]
Version = $segments[1]
Commands = $segments[2]
}
} | Where-Object { $_.PackageId -eq $Name }

$doInstall = $true

if ($null -ne $installedTool -and $installedTool -ne "")
{
if ($installedTool.Version -ne $Version)
{
dotnet tool uninstall $Name $scopeString
}
else
{
Write-Output "$Name version $Version is already installed!"
$doInstall = $false
}
}

if ($doInstall)
{
dotnet tool install $Name --version $Version $scopeString
}

0 comments on commit 1b9c7ff

Please sign in to comment.