From f685af9d21aabf134862091984eb8b9e8d271745 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20El-Saig?= Date: Mon, 6 Jun 2022 14:09:55 +0200 Subject: [PATCH 01/13] Port verify workflow from HL. --- .github/workflows/verify.yml | 74 ++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 .github/workflows/verify.yml diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml new file mode 100644 index 000000000..dee5c1fe4 --- /dev/null +++ b/.github/workflows/verify.yml @@ -0,0 +1,74 @@ +name: Verify Submodule Pull Request + +on: + workflow_call: + inputs: + repo: + required: false + type: string + default: Lombiq/Open-Source-Orchard-Core-Extensions + +env: + PULL_REQUEST_TITLE: ${{ github.event.pull_request.title }} + +defaults: + run: + shell: pwsh + +jobs: + parent-pull-request-exists: + runs-on: ubuntu-latest + name: Parent PR Exists + steps: + - name: Print PR Title + run: echo $Env:PULL_REQUEST_TITLE + + - name: Add Scripts + run: | + $code = @' + <# + .Synopsis + Fails the current step with the provided message. Same as "core.setFailed()" from the official toolkit + (https://github.com/actions/toolkit). + #> + function Set-Failed([Parameter(Mandatory=$True)] [string] $Message) + { + echo "::error::$Message" + exit 1 + } + + <# + .Synopsis + Returns $True if any item is coming from the pipe. + #> + function Any-Object([Parameter(Mandatory=$True, ValueFromPipeline = $True)] $Input) + { + foreach($item in $Input) + { + return $True + } + + return $False + } + '@ + + $ProfileDirectory = [System.IO.Path]::GetDirectoryName($Profile) + [System.IO.Directory]::CreateDirectory($ProfileDirectory) + + echo $code >> $Profile + + - name: Current PR Title Includes Issue Code + run: | + if ($Env:PULL_REQUEST_TITLE -match '^\s*\w+-\d+\s*:') { exit 0 } + Set-Failed 'The pull request is not in the right format. Please start with the issue code followed by a colon e.g. "PROJ-123: My PR Title".' + + - name: Search Parent Repository for Matching PR + run: | + $issueCode = $Env:PULL_REQUEST_TITLE -replace '^\s*(\w+-\d+)\s*:.*$', '$1' + + $url = 'https://api.github.com/repos/Lombiq/Open-Source-Orchard-Core-Extensions/pulls?state=open&per_page=100' + $titles = curl -H 'Accept: application/vnd.github.v3+json' $url | ConvertFrom-Json | % { $_.title } + + $lookFor = "${issueCode}:" + if ($titles | ? { $_ -and $_.Contains($lookFor) } | Any-Object) { exit 0 } + Set-Failed "Couldn't find an Open-Source-Orchard-Core-Extensions pull request whose title starts with `"$lookFor`"." From 920e6c17602e760db36b448bc311c8746f2f53ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20El-Saig?= Date: Mon, 6 Jun 2022 20:48:41 +0200 Subject: [PATCH 02/13] Fix indentation. --- .github/workflows/verify.yml | 82 ++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml index dee5c1fe4..3deb9e2f3 100644 --- a/.github/workflows/verify.yml +++ b/.github/workflows/verify.yml @@ -23,52 +23,52 @@ jobs: - name: Print PR Title run: echo $Env:PULL_REQUEST_TITLE - - name: Add Scripts - run: | - $code = @' - <# - .Synopsis - Fails the current step with the provided message. Same as "core.setFailed()" from the official toolkit - (https://github.com/actions/toolkit). - #> - function Set-Failed([Parameter(Mandatory=$True)] [string] $Message) - { - echo "::error::$Message" - exit 1 - } + - name: Add Scripts + run: | + $code = @' + <# + .Synopsis + Fails the current step with the provided message. Same as "core.setFailed()" from the official toolkit + (https://github.com/actions/toolkit). + #> + function Set-Failed([Parameter(Mandatory=$True)] [string] $Message) + { + echo "::error::$Message" + exit 1 + } - <# - .Synopsis - Returns $True if any item is coming from the pipe. - #> - function Any-Object([Parameter(Mandatory=$True, ValueFromPipeline = $True)] $Input) - { - foreach($item in $Input) - { - return $True - } + <# + .Synopsis + Returns $True if any item is coming from the pipe. + #> + function Any-Object([Parameter(Mandatory=$True, ValueFromPipeline = $True)] $Input) + { + foreach($item in $Input) + { + return $True + } - return $False - } - '@ + return $False + } + '@ - $ProfileDirectory = [System.IO.Path]::GetDirectoryName($Profile) - [System.IO.Directory]::CreateDirectory($ProfileDirectory) + $ProfileDirectory = [System.IO.Path]::GetDirectoryName($Profile) + [System.IO.Directory]::CreateDirectory($ProfileDirectory) - echo $code >> $Profile + echo $code >> $Profile - - name: Current PR Title Includes Issue Code - run: | - if ($Env:PULL_REQUEST_TITLE -match '^\s*\w+-\d+\s*:') { exit 0 } - Set-Failed 'The pull request is not in the right format. Please start with the issue code followed by a colon e.g. "PROJ-123: My PR Title".' + - name: Current PR Title Includes Issue Code + run: | + if ($Env:PULL_REQUEST_TITLE -match '^\s*\w+-\d+\s*:') { exit 0 } + Set-Failed 'The pull request is not in the right format. Please start with the issue code followed by a colon e.g. "PROJ-123: My PR Title".' - - name: Search Parent Repository for Matching PR - run: | - $issueCode = $Env:PULL_REQUEST_TITLE -replace '^\s*(\w+-\d+)\s*:.*$', '$1' + - name: Search Parent Repository for Matching PR + run: | + $issueCode = $Env:PULL_REQUEST_TITLE -replace '^\s*(\w+-\d+)\s*:.*$', '$1' - $url = 'https://api.github.com/repos/Lombiq/Open-Source-Orchard-Core-Extensions/pulls?state=open&per_page=100' - $titles = curl -H 'Accept: application/vnd.github.v3+json' $url | ConvertFrom-Json | % { $_.title } + $url = 'https://api.github.com/repos/Lombiq/Open-Source-Orchard-Core-Extensions/pulls?state=open&per_page=100' + $titles = curl -H 'Accept: application/vnd.github.v3+json' $url | ConvertFrom-Json | % { $_.title } - $lookFor = "${issueCode}:" - if ($titles | ? { $_ -and $_.Contains($lookFor) } | Any-Object) { exit 0 } - Set-Failed "Couldn't find an Open-Source-Orchard-Core-Extensions pull request whose title starts with `"$lookFor`"." + $lookFor = "${issueCode}:" + if ($titles | ? { $_ -and $_.Contains($lookFor) } | Any-Object) { exit 0 } + Set-Failed "Couldn't find an Open-Source-Orchard-Core-Extensions pull request whose title starts with `"$lookFor`"." From b0562fa5d49ec37bf2a5ca5384a6256fa6173956 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20El-Saig?= Date: Wed, 8 Jun 2022 01:45:29 +0200 Subject: [PATCH 03/13] code styling --- .github/workflows/verify.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml index 3deb9e2f3..82f92ef34 100644 --- a/.github/workflows/verify.yml +++ b/.github/workflows/verify.yml @@ -31,7 +31,7 @@ jobs: Fails the current step with the provided message. Same as "core.setFailed()" from the official toolkit (https://github.com/actions/toolkit). #> - function Set-Failed([Parameter(Mandatory=$True)] [string] $Message) + function Set-Failed([Parameter(Mandatory = $True)] [string] $Message) { echo "::error::$Message" exit 1 @@ -41,7 +41,7 @@ jobs: .Synopsis Returns $True if any item is coming from the pipe. #> - function Any-Object([Parameter(Mandatory=$True, ValueFromPipeline = $True)] $Input) + function Any-Object([Parameter(Mandatory = $True, ValueFromPipeline = $True)] $Input) { foreach($item in $Input) { @@ -52,8 +52,8 @@ jobs: } '@ - $ProfileDirectory = [System.IO.Path]::GetDirectoryName($Profile) - [System.IO.Directory]::CreateDirectory($ProfileDirectory) + $profileDirectory = [System.IO.Path]::GetDirectoryName($Profile) + [System.IO.Directory]::CreateDirectory($profileDirectory) echo $code >> $Profile From e8d0f92750fd2637c9818da7326117c79c85a2e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20El-Saig?= Date: Wed, 8 Jun 2022 01:54:56 +0200 Subject: [PATCH 04/13] Apply suggestions from code review Co-authored-by: 0liver <0liver@users.noreply.github.com> --- .github/workflows/verify.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml index 82f92ef34..2e159ec3a 100644 --- a/.github/workflows/verify.yml +++ b/.github/workflows/verify.yml @@ -23,7 +23,7 @@ jobs: - name: Print PR Title run: echo $Env:PULL_REQUEST_TITLE - - name: Add Scripts + - name: Add Commands to Subsequent Workflow Steps run: | $code = @' <# @@ -57,12 +57,12 @@ jobs: echo $code >> $Profile - - name: Current PR Title Includes Issue Code + - name: Ensure Current PR Title Includes Issue Code run: | if ($Env:PULL_REQUEST_TITLE -match '^\s*\w+-\d+\s*:') { exit 0 } Set-Failed 'The pull request is not in the right format. Please start with the issue code followed by a colon e.g. "PROJ-123: My PR Title".' - - name: Search Parent Repository for Matching PR + - name: Ensure Parent Repository Contains Matching PR run: | $issueCode = $Env:PULL_REQUEST_TITLE -replace '^\s*(\w+-\d+)\s*:.*$', '$1' @@ -70,5 +70,5 @@ jobs: $titles = curl -H 'Accept: application/vnd.github.v3+json' $url | ConvertFrom-Json | % { $_.title } $lookFor = "${issueCode}:" - if ($titles | ? { $_ -and $_.Contains($lookFor) } | Any-Object) { exit 0 } - Set-Failed "Couldn't find an Open-Source-Orchard-Core-Extensions pull request whose title starts with `"$lookFor`"." + if ($titles | ? { $_ -and $_.Trim().StartsWith($lookFor) } | Any-Object) { exit 0 } + Set-Failed "Couldn't find any Open-Source-Orchard-Core-Extensions pull request whose title starts with `"$lookFor`"." From c35c5f2c0f86c1a0e9c5357f9720fb1b721734df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20El-Saig?= Date: Wed, 8 Jun 2022 02:43:25 +0200 Subject: [PATCH 05/13] Clean up code. --- .github/workflows/verify.yml | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml index 2e159ec3a..d4a80c262 100644 --- a/.github/workflows/verify.yml +++ b/.github/workflows/verify.yml @@ -33,29 +33,15 @@ jobs: #> function Set-Failed([Parameter(Mandatory = $True)] [string] $Message) { - echo "::error::$Message" + Write-Output "::error::$Message" exit 1 } - - <# - .Synopsis - Returns $True if any item is coming from the pipe. - #> - function Any-Object([Parameter(Mandatory = $True, ValueFromPipeline = $True)] $Input) - { - foreach($item in $Input) - { - return $True - } - - return $False - } '@ $profileDirectory = [System.IO.Path]::GetDirectoryName($Profile) [System.IO.Directory]::CreateDirectory($profileDirectory) - echo $code >> $Profile + code | Out-File $Profile - name: Ensure Current PR Title Includes Issue Code run: | @@ -66,9 +52,9 @@ jobs: run: | $issueCode = $Env:PULL_REQUEST_TITLE -replace '^\s*(\w+-\d+)\s*:.*$', '$1' - $url = 'https://api.github.com/repos/Lombiq/Open-Source-Orchard-Core-Extensions/pulls?state=open&per_page=100' - $titles = curl -H 'Accept: application/vnd.github.v3+json' $url | ConvertFrom-Json | % { $_.title } + $url = 'https://api.github.com/repos/${{ inputs.repo }}/pulls?state=open&per_page=100' + $titles = curl -s -H 'Accept: application/vnd.github.v3+json' $url | ConvertFrom-Json | % { $_.title } $lookFor = "${issueCode}:" - if ($titles | ? { $_ -and $_.Trim().StartsWith($lookFor) } | Any-Object) { exit 0 } + if (($titles | ? { $_ -and $_.Trim().StartsWith($lookFor) }).Count -eq 0) { exit 0 } Set-Failed "Couldn't find any Open-Source-Orchard-Core-Extensions pull request whose title starts with `"$lookFor`"." From 0667569036ceb5dcd4370c8510dc9f7e9afb4742 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20El-Saig?= Date: Wed, 8 Jun 2022 02:43:55 +0200 Subject: [PATCH 06/13] Let's move the $issueCode closer to its usage. --- .github/workflows/verify.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml index d4a80c262..2bd813b2b 100644 --- a/.github/workflows/verify.yml +++ b/.github/workflows/verify.yml @@ -50,11 +50,10 @@ jobs: - name: Ensure Parent Repository Contains Matching PR run: | - $issueCode = $Env:PULL_REQUEST_TITLE -replace '^\s*(\w+-\d+)\s*:.*$', '$1' - $url = 'https://api.github.com/repos/${{ inputs.repo }}/pulls?state=open&per_page=100' $titles = curl -s -H 'Accept: application/vnd.github.v3+json' $url | ConvertFrom-Json | % { $_.title } + $issueCode = $Env:PULL_REQUEST_TITLE -replace '^\s*(\w+-\d+)\s*:.*$', '$1' $lookFor = "${issueCode}:" if (($titles | ? { $_ -and $_.Trim().StartsWith($lookFor) }).Count -eq 0) { exit 0 } Set-Failed "Couldn't find any Open-Source-Orchard-Core-Extensions pull request whose title starts with `"$lookFor`"." From 8166dfcbf32020b63c89d57f2c5dd35bce6a04a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20El-Saig?= Date: Wed, 8 Jun 2022 02:49:13 +0200 Subject: [PATCH 07/13] Fix typo. --- .github/workflows/verify.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml index 2bd813b2b..b61b76dc5 100644 --- a/.github/workflows/verify.yml +++ b/.github/workflows/verify.yml @@ -41,7 +41,7 @@ jobs: $profileDirectory = [System.IO.Path]::GetDirectoryName($Profile) [System.IO.Directory]::CreateDirectory($profileDirectory) - code | Out-File $Profile + $code | Out-File $Profile - name: Ensure Current PR Title Includes Issue Code run: | From fd369786321565662b94aa9a01995fd9799b8578 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20El-Saig?= Date: Wed, 8 Jun 2022 02:58:15 +0200 Subject: [PATCH 08/13] Bug fix, invert condition. --- .github/workflows/verify.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml index b61b76dc5..af677a761 100644 --- a/.github/workflows/verify.yml +++ b/.github/workflows/verify.yml @@ -55,5 +55,5 @@ jobs: $issueCode = $Env:PULL_REQUEST_TITLE -replace '^\s*(\w+-\d+)\s*:.*$', '$1' $lookFor = "${issueCode}:" - if (($titles | ? { $_ -and $_.Trim().StartsWith($lookFor) }).Count -eq 0) { exit 0 } + if (($titles | ? { $_ -and $_.Trim().StartsWith($lookFor) }).Count -gt 0) { exit 0 } Set-Failed "Couldn't find any Open-Source-Orchard-Core-Extensions pull request whose title starts with `"$lookFor`"." From 9723194e47706d8797ad3eccf746c630dab6c4d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20El-Saig?= Date: Wed, 8 Jun 2022 14:27:08 +0200 Subject: [PATCH 09/13] Update .github/workflows/verify.yml Co-authored-by: 0liver <0liver@users.noreply.github.com> --- .github/workflows/verify.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml index af677a761..ce29d03a2 100644 --- a/.github/workflows/verify.yml +++ b/.github/workflows/verify.yml @@ -46,7 +46,7 @@ jobs: - name: Ensure Current PR Title Includes Issue Code run: | if ($Env:PULL_REQUEST_TITLE -match '^\s*\w+-\d+\s*:') { exit 0 } - Set-Failed 'The pull request is not in the right format. Please start with the issue code followed by a colon e.g. "PROJ-123: My PR Title".' + 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".' - name: Ensure Parent Repository Contains Matching PR run: | From 6f156bbd6356c9659ba413dac0e64a89a12814da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20El-Saig?= Date: Wed, 8 Jun 2022 14:27:44 +0200 Subject: [PATCH 10/13] Update .github/workflows/verify.yml Co-authored-by: 0liver <0liver@users.noreply.github.com> --- .github/workflows/verify.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml index ce29d03a2..6aecfcf10 100644 --- a/.github/workflows/verify.yml +++ b/.github/workflows/verify.yml @@ -56,4 +56,4 @@ jobs: $issueCode = $Env:PULL_REQUEST_TITLE -replace '^\s*(\w+-\d+)\s*:.*$', '$1' $lookFor = "${issueCode}:" if (($titles | ? { $_ -and $_.Trim().StartsWith($lookFor) }).Count -gt 0) { exit 0 } - Set-Failed "Couldn't find any Open-Source-Orchard-Core-Extensions pull request whose title starts with `"$lookFor`"." + Set-Failed "Couldn't find any Open-Source-Orchard-Core-Extensions pull request whose title starts with `"$lookFor`". Please create one." From e04a499d1dca2ead3c809049049f4ae3fb9efd3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20El-Saig?= Date: Wed, 8 Jun 2022 15:06:13 +0200 Subject: [PATCH 11/13] try using an external script file --- .github/workflows/verify.yml | 28 +++++-------------------- scripts/verify/commands.ps1 | 40 ++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 23 deletions(-) create mode 100644 scripts/verify/commands.ps1 diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml index 6aecfcf10..dae8a4493 100644 --- a/.github/workflows/verify.yml +++ b/.github/workflows/verify.yml @@ -25,35 +25,17 @@ jobs: - name: Add Commands to Subsequent Workflow Steps run: | - $code = @' - <# - .Synopsis - Fails the current step with the provided message. Same as "core.setFailed()" from the official toolkit - (https://github.com/actions/toolkit). - #> - function Set-Failed([Parameter(Mandatory = $True)] [string] $Message) - { - Write-Output "::error::$Message" - exit 1 - } - '@ - $profileDirectory = [System.IO.Path]::GetDirectoryName($Profile) [System.IO.Directory]::CreateDirectory($profileDirectory) - $code | Out-File $Profile + Write-Output "github.action_path = '${{ github.action_path }}'" + Get-Content -Raw '${{ github.action_path }}/scripts/verify/commands.ps1' | + Out-File $Profile -Append - name: Ensure Current PR Title Includes Issue Code run: | - if ($Env:PULL_REQUEST_TITLE -match '^\s*\w+-\d+\s*:') { 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".' + Exit-EnsureCurrentPullRequest $Env:PULL_REQUEST_TITLE - name: Ensure Parent Repository Contains Matching PR run: | - $url = 'https://api.github.com/repos/${{ inputs.repo }}/pulls?state=open&per_page=100' - $titles = curl -s -H 'Accept: application/vnd.github.v3+json' $url | ConvertFrom-Json | % { $_.title } - - $issueCode = $Env:PULL_REQUEST_TITLE -replace '^\s*(\w+-\d+)\s*:.*$', '$1' - $lookFor = "${issueCode}:" - if (($titles | ? { $_ -and $_.Trim().StartsWith($lookFor) }).Count -gt 0) { exit 0 } - Set-Failed "Couldn't find any Open-Source-Orchard-Core-Extensions pull request whose title starts with `"$lookFor`". Please create one." + Exit-EnsureParentPullRequest '${{ inputs.repo }}' $Env:PULL_REQUEST_TITLE diff --git a/scripts/verify/commands.ps1 b/scripts/verify/commands.ps1 new file mode 100644 index 000000000..015febef6 --- /dev/null +++ b/scripts/verify/commands.ps1 @@ -0,0 +1,40 @@ + +<# +.Synopsis +Fails the current step with the provided message. Same as "core.setFailed()" from the official +toolkit (https://github.com/actions/toolkit). +#> +function Set-Failed([Parameter(Mandatory = $True)] [string] $Message) +{ + Write-Output "::error::$Message" + exit 1 +} + +<# +.Synopsis +Checks if the current pull request title matches expectations and exits with success or an error +message and failure. +#> +function Exit-EnsureCurrentPullRequest([Parameter(Mandatory = $True)] [string] $title) +{ + if ($title -match '^\s*\w+-\d+\s*:') { 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".' +} + +<# +.Synopsis +Checks if a parent pull request exists in the given repo with the expected title and exits with +success or an error message and failure. +#> +function Exit-EnsureParentPullRequest( + [Parameter(Mandatory = $True)] [string] $repo, + [Parameter(Mandatory = $True)] [string] $title) +{ + $url = "https://api.github.com/repos/$repo/pulls?state=open&per_page=100" + $titles = curl -s -H 'Accept: application/vnd.github.v3+json' $url | ConvertFrom-Json | % { $_.title } + + $issueCode = $title -replace '^\s*(\w+-\d+)\s*:.*$', '$1' + $lookFor = "${issueCode}:" + if (($titles | ? { $_ -and $_.Trim().StartsWith($lookFor) }).Count -gt 0) { exit 0 } + Set-Failed "Couldn't find any Open-Source-Orchard-Core-Extensions pull request whose title starts with `"$lookFor`". Please create one." +} \ No newline at end of file From b4d921ae78a36c033ae1b0fa7d1d3f6276d298b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20El-Saig?= Date: Wed, 8 Jun 2022 15:12:30 +0200 Subject: [PATCH 12/13] Revert "try using an external script file" This reverts commit e04a499d1dca2ead3c809049049f4ae3fb9efd3a. --- .github/workflows/verify.yml | 28 ++++++++++++++++++++----- scripts/verify/commands.ps1 | 40 ------------------------------------ 2 files changed, 23 insertions(+), 45 deletions(-) delete mode 100644 scripts/verify/commands.ps1 diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml index dae8a4493..6aecfcf10 100644 --- a/.github/workflows/verify.yml +++ b/.github/workflows/verify.yml @@ -25,17 +25,35 @@ jobs: - name: Add Commands to Subsequent Workflow Steps run: | + $code = @' + <# + .Synopsis + Fails the current step with the provided message. Same as "core.setFailed()" from the official toolkit + (https://github.com/actions/toolkit). + #> + function Set-Failed([Parameter(Mandatory = $True)] [string] $Message) + { + Write-Output "::error::$Message" + exit 1 + } + '@ + $profileDirectory = [System.IO.Path]::GetDirectoryName($Profile) [System.IO.Directory]::CreateDirectory($profileDirectory) - Write-Output "github.action_path = '${{ github.action_path }}'" - Get-Content -Raw '${{ github.action_path }}/scripts/verify/commands.ps1' | - Out-File $Profile -Append + $code | Out-File $Profile - name: Ensure Current PR Title Includes Issue Code run: | - Exit-EnsureCurrentPullRequest $Env:PULL_REQUEST_TITLE + if ($Env:PULL_REQUEST_TITLE -match '^\s*\w+-\d+\s*:') { 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".' - name: Ensure Parent Repository Contains Matching PR run: | - Exit-EnsureParentPullRequest '${{ inputs.repo }}' $Env:PULL_REQUEST_TITLE + $url = 'https://api.github.com/repos/${{ inputs.repo }}/pulls?state=open&per_page=100' + $titles = curl -s -H 'Accept: application/vnd.github.v3+json' $url | ConvertFrom-Json | % { $_.title } + + $issueCode = $Env:PULL_REQUEST_TITLE -replace '^\s*(\w+-\d+)\s*:.*$', '$1' + $lookFor = "${issueCode}:" + if (($titles | ? { $_ -and $_.Trim().StartsWith($lookFor) }).Count -gt 0) { exit 0 } + Set-Failed "Couldn't find any Open-Source-Orchard-Core-Extensions pull request whose title starts with `"$lookFor`". Please create one." diff --git a/scripts/verify/commands.ps1 b/scripts/verify/commands.ps1 deleted file mode 100644 index 015febef6..000000000 --- a/scripts/verify/commands.ps1 +++ /dev/null @@ -1,40 +0,0 @@ - -<# -.Synopsis -Fails the current step with the provided message. Same as "core.setFailed()" from the official -toolkit (https://github.com/actions/toolkit). -#> -function Set-Failed([Parameter(Mandatory = $True)] [string] $Message) -{ - Write-Output "::error::$Message" - exit 1 -} - -<# -.Synopsis -Checks if the current pull request title matches expectations and exits with success or an error -message and failure. -#> -function Exit-EnsureCurrentPullRequest([Parameter(Mandatory = $True)] [string] $title) -{ - if ($title -match '^\s*\w+-\d+\s*:') { 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".' -} - -<# -.Synopsis -Checks if a parent pull request exists in the given repo with the expected title and exits with -success or an error message and failure. -#> -function Exit-EnsureParentPullRequest( - [Parameter(Mandatory = $True)] [string] $repo, - [Parameter(Mandatory = $True)] [string] $title) -{ - $url = "https://api.github.com/repos/$repo/pulls?state=open&per_page=100" - $titles = curl -s -H 'Accept: application/vnd.github.v3+json' $url | ConvertFrom-Json | % { $_.title } - - $issueCode = $title -replace '^\s*(\w+-\d+)\s*:.*$', '$1' - $lookFor = "${issueCode}:" - if (($titles | ? { $_ -and $_.Trim().StartsWith($lookFor) }).Count -gt 0) { exit 0 } - Set-Failed "Couldn't find any Open-Source-Orchard-Core-Extensions pull request whose title starts with `"$lookFor`". Please create one." -} \ No newline at end of file From cef5d8d88a929294e3f9f81b19ebd95c3ab332a7 Mon Sep 17 00:00:00 2001 From: 0liver <0liver@users.noreply.github.com> Date: Wed, 8 Jun 2022 17:16:26 +0200 Subject: [PATCH 13/13] Clarify job name --- .github/workflows/verify.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml index 6aecfcf10..336b1cf55 100644 --- a/.github/workflows/verify.yml +++ b/.github/workflows/verify.yml @@ -18,7 +18,7 @@ defaults: jobs: parent-pull-request-exists: runs-on: ubuntu-latest - name: Parent PR Exists + name: Ensure Parent PR Exists steps: - name: Print PR Title run: echo $Env:PULL_REQUEST_TITLE