-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
OSOE-131: Detect in submodules if there's no PR here
- Loading branch information
Showing
1 changed file
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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." |