-
Notifications
You must be signed in to change notification settings - Fork 2
81 lines (72 loc) · 3.13 KB
/
oob-update.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
name: "OOB Update"
on:
repository_dispatch:
types:
- oob-update
jobs:
oob-update:
runs-on: ubuntu-latest
outputs:
agent-type: ${{ steps.validate-event.outputs.agent-type }}
agent-version: ${{ steps.validate-event.outputs.agent-version }}
steps:
- uses: actions/checkout@v4
- name: Validate Event
id: validate-event
run: |
$clientPayload = '${{ toJSON(github.event.client_payload) }}' | ConvertFrom-Json
[string] $agentType = $clientPayload.type
[string] $agentVersion = $clientPayload.version
[string] $manifestPath = "./src/$agentType/manifest.json"
if ($agentType -notmatch '^(nodejs|java|dotnet-core|dotnet-framework|php|python)$')
{
Write-Error "Failed to validate agent type."
exit 1
}
if (-not (Test-Path -Path $manifestPath))
{
Write-Error "$manifestPath does not exist."
exit 1
}
if ($agentVersion -notmatch '^\d+(\.\d+){2,3}$')
{
Write-Error "Failed to validate agent version."
exit 1
}
Write-Host "::set-output name=agent-type::$agentType"
Write-Host "::set-output name=agent-version::$agentVersion"
Write-Host "::set-output name=manifest-path::$manifestPath"
shell: pwsh
- name: Stage Changes
id: stage-changes
run: |
$agentVersion = '${{ steps.validate-event.outputs.agent-version }}'
$manifestPath = '${{ steps.validate-event.outputs.manifest-path }}'
$manifest = Get-Content -Path $manifestPath | ConvertFrom-Json
Write-Host "::set-output name=old-version::$($manifest.version)"
$manifest.version = $agentVersion
$manifest | ConvertTo-Json | Set-Content -Path $manifestPath -Encoding UTF8
shell: pwsh
- name: Create Pull Request
uses: peter-evans/create-pull-request@v7
id: create-pr
with:
add-paths: |
${{ steps.validate-event.outputs.manifest-path }}
commit-message: |
Upgraded '${{ steps.validate-event.outputs.agent-type }}' to '${{ steps.validate-event.outputs.agent-version }}'
branch: actions/oob-${{ steps.validate-event.outputs.agent-type }}-${{ steps.validate-event.outputs.agent-version }}
title: |
[OOB] Upgrades '${{ steps.validate-event.outputs.agent-type }}' to '${{ steps.validate-event.outputs.agent-version }}'
body: |
Automated OOB update requested by ${{ github.actor }}.
Agent: `${{ steps.validate-event.outputs.agent-type }}`
Version: `${{ steps.stage-changes.outputs.old-version }}` -> `${{ steps.validate-event.outputs.agent-version }}`
labels: |
oob-update
token: ${{ secrets.GH_PR_WRITE_PAT }}
- name: Enable Pull Request Automerge
if: steps.create-pr.outputs.pull-request-operation == 'created'
run: gh pr merge --rebase --auto "${{ steps.create-pr.outputs.pull-request-number }}"
env:
GH_TOKEN: ${{ secrets.GH_PR_WRITE_PAT }}