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

ci: system for requesting maintainer action via tags #1037

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/actions/create-comment/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Create Comment

Create a comment on a pull request or an issue.
29 changes: 29 additions & 0 deletions .github/actions/create-comment/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Create Comment
description: Create a comment using the provided token
author: Devolutions Architecture Team

inputs:
repo-name:
description: "The name of the repository. Example: 'octocat/hello-world'"
default: ${{ github.repository }}
pr-number:
description: The ID of the pull request (/ issue)
default: ${{ github.event.number }}
branch:
description: Name of the branch
default: ${{ github.event.pull_request.head.ref }}
token:
description: GitHub token
default: ${{ github.token }}
template:
description: Message template

runs:
using: composite

steps:
- name: Run
env:
GITHUB_TOKEN: ${{ inputs.token }}
shell: pwsh
run: ${{ github.action_path }}/run.ps1 -RepoName ${{ inputs.repo-name }} -PullRequestId ${{ inputs.pr-number }} -Branch ${{ inputs.branch }} -Template ${{ inputs.template }}
62 changes: 62 additions & 0 deletions .github/actions/create-comment/run.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/bin/env pwsh

param(
[Parameter(Mandatory=$true)]
[string] $RepoName,
[Parameter(Mandatory=$true)]
[int] $PullRequestId,
[Parameter(Mandatory=$true)]
[string] $Branch,
[Parameter(Mandatory=$true)]
[string] $TemplatePath
)

$ErrorActionPreference = "Stop"

$MyInvocation.MyCommand.Parameters `
| Format-Table -AutoSize `
@{ Label = "Argument"; Expression = { $_.Key }; },
@{ Label = "Value"; Expression = { try { (Get-Variable -Name $_.Key).Value } catch { "" } }; }
Write-Host

function Invoke-Cmd
{
param(
[Parameter(Mandatory=$true)]
[string] $Name,
[Parameter(Mandatory=$true)]
[string[]] $Args,
[switch] $IgnoreFailure
)

Write-Host ">> Invoke '${Name}' $($Args | Join-String -FormatString '''{0}''' -Separator ' ')"

# Workaround: temporary change error action preferance because until v7.2 stderr redirection (>2) is redirected to the PowerShell error stream
$ErrorActionPreference = "Continue"
& $Name $Args 2>&1
$ErrorActionPreference = "Stop"

$failed = $LastExitCode -ne 0

if ($failed -and (-not $IgnoreFailure))
{
throw "${Name} invocation failed"
}
}

Write-Host ">> Read template file at $TemplatePath"

$body = Get-Content -Raw -Path "$TemplatePath"

Write-Host '>> Create new comment'

$args = @(
'api',
'-H', 'Accept: application/vnd.github.v3+json',
'-f', "body=$body",
'--method', 'POST',
"/repos/$RepoName/issues/$PullRequestId/comments"
)

Invoke-Cmd 'gh' $args | Out-Null

7 changes: 7 additions & 0 deletions .github/comments/pr_greetings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Let maintainers know that an action is required on their side.

# Maintainer action requested

- Add the label https://github.com/Devolutions/devolutions-gateway/labels/release-required when you request a maintainer to cut a new release a new release (Devolutions Gateway, Devolutions Agent, Jetsocat, PowerShell module)

- Add the label https://github.com/Devolutions/devolutions-gateway/labels/publish-required when you request a maintainer to publish libraries (`Devolutions.Gateway.Utils`, OpenAPI clients, etc)
3 changes: 3 additions & 0 deletions .github/comments/publish_requested.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Author requested libraries to be published.

cc @CBenoit
3 changes: 3 additions & 0 deletions .github/comments/release_requested.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Author requested a new release to be cut.

cc @CBenoit
26 changes: 26 additions & 0 deletions .github/workflows/create-comment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Create Comment

on:
pull_request:
branches: [ main ]
types: [ opened, labeled ]

jobs:
create-comment:
name: Create Comment
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- uses: ./.github/actions/create-comment
if: ${{ github.event.action == 'opened'}}
template: ${{ github.workspace }}/.github/comments/pr_greetings.md

- uses: ./.github/actions/create-comment
if: ${{ github.event.action == 'labeled' && github.event.label.name == 'publish-required' }}
template: ${{ github.workspace }}/.github/comments/publish_requested.md

- uses: ./.github/actions/create-comment
if: ${{ github.event.action == 'labeled' && github.event.label.name == 'release-required' }}
template: ${{ github.workspace }}/.github/comments/release_requested.md
Empty file modified ci/tlk.ps1
100644 → 100755
Empty file.