Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSOE-131: Detect in submodules if there's no PR here #7

Merged
merged 14 commits into from
Jun 8, 2022
59 changes: 59 additions & 0 deletions .github/workflows/verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Verify Submodule Pull Request
0liver marked this conversation as resolved.
Show resolved Hide resolved

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 }}
0liver marked this conversation as resolved.
Show resolved Hide resolved

defaults:
run:
shell: pwsh

jobs:
parent-pull-request-exists:
runs-on: ubuntu-latest
name: Parent PR Exists
0liver marked this conversation as resolved.
Show resolved Hide resolved
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}:"
0liver marked this conversation as resolved.
Show resolved Hide resolved
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."