From 9e0ee026af574f471c9f1355ea7d97b7050f390b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20CORTIER?= Date: Thu, 3 Oct 2024 16:24:47 +0900 Subject: [PATCH] ci: system for requesting maintainer action via tags --- .github/actions/create-comment/README.md | 3 ++ .github/actions/create-comment/action.yml | 29 +++++++++++ .github/actions/create-comment/run.ps1 | 62 +++++++++++++++++++++++ .github/comments/pr_greetings.md | 7 +++ .github/comments/publish_requested.md | 3 ++ .github/comments/release_requested.md | 3 ++ .github/workflows/create-comment.yml | 26 ++++++++++ ci/tlk.ps1 | 0 8 files changed, 133 insertions(+) create mode 100644 .github/actions/create-comment/README.md create mode 100644 .github/actions/create-comment/action.yml create mode 100755 .github/actions/create-comment/run.ps1 create mode 100644 .github/comments/pr_greetings.md create mode 100644 .github/comments/publish_requested.md create mode 100644 .github/comments/release_requested.md create mode 100644 .github/workflows/create-comment.yml mode change 100644 => 100755 ci/tlk.ps1 diff --git a/.github/actions/create-comment/README.md b/.github/actions/create-comment/README.md new file mode 100644 index 00000000..1d656ef9 --- /dev/null +++ b/.github/actions/create-comment/README.md @@ -0,0 +1,3 @@ +# Create Comment + +Create a comment on a pull request or an issue. diff --git a/.github/actions/create-comment/action.yml b/.github/actions/create-comment/action.yml new file mode 100644 index 00000000..ae0fa1d8 --- /dev/null +++ b/.github/actions/create-comment/action.yml @@ -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 }} diff --git a/.github/actions/create-comment/run.ps1 b/.github/actions/create-comment/run.ps1 new file mode 100755 index 00000000..e05cf312 --- /dev/null +++ b/.github/actions/create-comment/run.ps1 @@ -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 + diff --git a/.github/comments/pr_greetings.md b/.github/comments/pr_greetings.md new file mode 100644 index 00000000..8e1a4309 --- /dev/null +++ b/.github/comments/pr_greetings.md @@ -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) diff --git a/.github/comments/publish_requested.md b/.github/comments/publish_requested.md new file mode 100644 index 00000000..1d9b2352 --- /dev/null +++ b/.github/comments/publish_requested.md @@ -0,0 +1,3 @@ +Author requested libraries to be published. + +cc @CBenoit diff --git a/.github/comments/release_requested.md b/.github/comments/release_requested.md new file mode 100644 index 00000000..09e7e1d0 --- /dev/null +++ b/.github/comments/release_requested.md @@ -0,0 +1,3 @@ +Author requested a new release to be cut. + +cc @CBenoit diff --git a/.github/workflows/create-comment.yml b/.github/workflows/create-comment.yml new file mode 100644 index 00000000..231f76a0 --- /dev/null +++ b/.github/workflows/create-comment.yml @@ -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 diff --git a/ci/tlk.ps1 b/ci/tlk.ps1 old mode 100644 new mode 100755