diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml new file mode 100644 index 000000000..336b1cf55 --- /dev/null +++ b/.github/workflows/verify.yml @@ -0,0 +1,59 @@ +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: Ensure Parent PR Exists + steps: + - name: Print PR Title + run: echo $Env:PULL_REQUEST_TITLE + + - 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 + + - 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".' + + - 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."