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: improve Release Assistant workflow #1051

Merged
merged 1 commit into from
Oct 8, 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
6 changes: 5 additions & 1 deletion .github/comments/pr_greetings.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@

- Add the label https://github.com/Devolutions/devolutions-gateway/labels/release-required when you request a maintainer to cut 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)
- Add the label https://github.com/Devolutions/devolutions-gateway/labels/release-blocker if a follow-up is required before cutting a new release

- 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.)

- Add the label https://github.com/Devolutions/devolutions-gateway/labels/publish-blocker if a follow-up is required before publishing libraries
29 changes: 0 additions & 29 deletions .github/workflows/create-comment.yml

This file was deleted.

16 changes: 16 additions & 0 deletions .github/workflows/publish-libraries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,22 @@ jobs:
env:
GH_TOKEN: ${{ secrets.DEVOLUTIONSBOT_WRITE_TOKEN }}

remove-labels:
name: Remove publish-required labels
runs-on: ubuntu-latest
if: needs.preflight.outputs.dry-run == 'false'
needs:
- nuget-build
- npm-publish

steps:
- name: Check out ${{ github.repository }}
uses: actions/checkout@v4

- name: Remove labels
shell: pwsh
run: ./ci/remove-labels.ps1 -Label 'publish-required'

notify:
name: Notify failure
runs-on: ubuntu-latest
Expand Down
101 changes: 101 additions & 0 deletions .github/workflows/release-assistant.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
name: Release Assistant

on:
pull_request:
branches: [ master ]
types: [ opened, labeled ]
schedule:
- cron: '49 3 * * 1' # 3:49 AM UTC every Monday

jobs:
create-comment:
name: Create Comment
runs-on: ubuntu-latest
if: |
github.event_name == 'pull_request'
&& github.event.pull_request.user.login != 'CBenoit'
&& github.event.pull_request.user.login != 'dependabot'
&& github.event.pull_request.head.repo.full_name == github.repository

steps:
- uses: actions/checkout@v4

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

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

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

notify-slack:
name: Notify Slack
runs-on: ubuntu-latest
if: github.event_name == 'schedule'

env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_ARCHITECTURE }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK

strategy:
matrix:
required-label: [ release-required, publish-required ]
include:
- required-label: release-required
blocker-label: release-blocker
message: Please cut a release
- required-label: publish-required
blocker-label: publish-blocker
message: Please publish libraries

steps:
- uses: actions/checkout@v4

- name: Verify labels
id: verify-labels
shell: pwsh
run: |
$blockerCount = ./ci/pr-count-for-label.ps1 -Label '${{ matrix.blocker-label }}'

if ($blockerCount -ne 0)
{
echo "notify=no" >> "$GITHUB_OUTPUT"
}
else
{
$requiredCount = ./ci/pr-count-for-label.ps1 -Label '${{ matrix.required-label }}'

if ($requiredCount -ne 0)
{
echo "notify=yes" >> "$GITHUB_OUTPUT"
}
else
{
echo "notify=no" >> "$GITHUB_OUTPUT"
}
}

- name: Send slack notification
id: slack
if: steps.verify-labels.outputs.do-send == 'yes'
uses: slackapi/[email protected]
with:
payload: |
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*${{ github.repository }}* :recycle: \n ${{ matrix.message }} for *${{ github.repository }}*"
}
}
]
}
20 changes: 20 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -420,3 +420,23 @@ jobs:
destination_path: /Agent/${{ steps.prepare.outputs.version }}
remote: releases
source_path: ${{ steps.prepare.outputs.files-to-upload }}

remove-labels:
name: Remove release-required labels
runs-on: ubuntu-latest
if: needs.preflight.outputs.skip-publishing == 'false' || ${{ inputs.dry-run }}
needs:
- containers
- github-release
- psgallery-release
- onedrive-gateway
- onedrive-agent

steps:
- name: Check out ${{ github.repository }}
uses: actions/checkout@v4

- name: Remove labels
shell: pwsh
run: ./ci/remove-labels.ps1 -Label 'release-required'

19 changes: 19 additions & 0 deletions ci/pr-count-for-label.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/env pwsh

param(
[Parameter(Mandatory=$true)]
[string] $Label
)

$ErrorActionPreference = "Stop"

# This script is intended for release process labels,
# and we don’t expect more than 100 of these.

$count = gh api `
-H "Accept: application/vnd.github+json" `
-H "X-GitHub-Api-Version: 2022-11-28" `
"/search/issues?per_page=100&q=repo:Devolutions/devolutions-gateway+is:closed+is:pull-request+label:$Label" `
--jq .total_count

[int]$count
29 changes: 29 additions & 0 deletions ci/remove-labels.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/env pwsh

param(
[Parameter(Mandatory=$true)]
[string] $Label
)

$ErrorActionPreference = "Stop"

# This script is intended for release process labels,
# and we don’t expect more than 100 of these.

$issues = gh api `
-H "Accept: application/vnd.github+json" `
-H "X-GitHub-Api-Version: 2022-11-28" `
"/repos/Devolutions/devolutions-gateway/issues?labels=$Label&state=closed&per_page=100"
| ConvertFrom-Json

foreach ($issue in $issues)
{
Write-Host "Removing $Label label from $($issue.url)..."

gh api `
--method DELETE `
-H "Accept: application/vnd.github+json" `
-H "X-GitHub-Api-Version: 2022-11-28" `
"/repos/Devolutions/devolutions-gateway/issues/$($issue.number)/labels/$Label"
| Out-Null
}
Loading