-
Notifications
You must be signed in to change notification settings - Fork 0
168 lines (143 loc) · 5.58 KB
/
parse_trigger.yml
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# compatible with AutoRepo-Worker 0.0.5 issue#1 comments
name: Parse and Process Trigger
on:
issue_comment:
types: [created]
secrets:
BOT_INVITE_ACCEPT_TOKEN:
description: 'A classic PAT with the full `repo` scope'
required: false
BOT_READ_REPOS_TOKEN:
description: 'A classic PAT with the full `repo` scope'
required: false
jobs:
parse_trigger:
name: Parse Trigger
runs-on: windows-latest
# Only bot comments on the trigger issue (#1)
if: |
github.event.comment.user.login == 'just-some-bot' &&
github.event.issue.number == 1
steps:
# Set git to use the bot's credentials
- name: Setup Git
id: setup_git
run: |
git config --global user.name 'just-some-bot'
git config --global user.email '[email protected]'
# Parse the JSON from the comment and save it to `parsed.json`
- name: Parse JSON from Comment
id: parse_json
run: |
$commentBody = @"
${{ github.event.comment.body }}
"@
$lines = $commentBody -split "`n"
Write-Output "Number of lines in comment body: $($lines.Count)"
Write-Output "Lines 13 through 28:"
$lines[12..27] | ForEach-Object { Write-Output $_ }
$jsonBlock = $lines[13..28] -join "`n"
Write-Output "Extracted JSON Block:"
Write-Output $jsonBlock
if (-not $jsonBlock) {
Write-Error "No JSON block found in the comment."
exit 1
}
$outputFilePath = "parsed.json"
$jsonBlock | Out-File -FilePath $outputFilePath
if (-not (Test-Path $outputFilePath)) {
Write-Error "Failed to write JSON block to file."
exit 1
}
shell: pwsh
# Convert the trigger's JSON to Outputs
# e.g. `steps.set_env_vars.outputs.trigger_branch_main`
# e.g. `needs.parse_trigger.outputs.trigger_branch_test`
- name: Parse JSON values to Outputs
id: set_env_vars
run: |
$json = Get-Content -Raw -Path parsed.json | ConvertFrom-Json
foreach ($key in $json.PSObject.Properties.Name) {
$value = $json.$key
echo "::set-output name=trigger_$key::$value"
}
shell: pwsh
# The bot auto-accepts collaboration invites every night,
# but we are doing it here to make sure that the bot has
# access to the repo
- name: Auto Accept Collaboration invites
id: accept_invites
run: |
# List all repository invitations
$invitations = Invoke-RestMethod -Uri "https://api.github.com/user/repository_invitations" -Headers @{
Accept = "application/vnd.github+json"
Authorization = "Bearer ${{ secrets.BOT_INVITE_ACCEPT_TOKEN }}"
"X-GitHub-Api-Version" = "2022-11-28"
}
# Parse the JSON response to extract invitation IDs
$invitation_ids = $invitations.id
# Accept each invitation by its ID
foreach ($id in $invitation_ids) {
Invoke-RestMethod -Uri "https://api.github.com/user/repository_invitations/$id" -Method Patch -Headers @{
Accept = "application/vnd.github+json"
Authorization = "Bearer ${{ secrets.BOT_INVITE_ACCEPT_TOKEN }}"
"X-GitHub-Api-Version" = "2022-11-28"
}
}
shell: pwsh
# Set up .NET for building later
- name: Set up .NET
id: setup_net
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
# Download Dalamud development tools
- name: Download Dalamud
id: download_dalamud
run: |
Invoke-WebRequest -Uri https://goatcorp.github.io/dalamud-distrib/latest.zip -OutFile dalamud.zip
Expand-Archive -Force dalamud.zip "$env:AppData\XIVLauncher\addon\Hooks\dev\"
# Setup folder to build into
- name: Create Folder in $HOME
id: make_builds_folder
run: mkdir $HOME/builds
shell: bash
- name: Debugging
id: debug
run: |
echo "trigger_branch_main: ${{ steps.set_env_vars.outputs.trigger_branch_test }}"
if [ "${{ steps.set_env_vars.outputs.trigger_branch_test }}" != "" ]; then
echo "Condition is true"
else
echo "Condition is false"
fi
shell: bash
# Build the main branch if it was requested in the trigger
build_main:
name: Build Main Branch
runs-on: windows-latest
needs: parse_trigger
if: ${{ needs.parse_trigger.outputs.trigger_branch_main != '' }}
steps:
- name: Trigger Plugin Build
id: trigger_main_build
uses: ./.github/workflows/build_plugin.yml
with:
branch: ${{ needs.parse_trigger.outputs.trigger_branch_main }}
build_config: ${{ needs.parse_trigger.outputs.trigger_branch_main_build }}
# Build the test branch if it was requested in the trigger
build_test:
name: Build Test Branch
runs-on: windows-latest
needs: parse_trigger
if: ${{ needs.parse_trigger.outputs.trigger_branch_test != '' }}
steps:
- name: Trigger Plugin Build
id: trigger_test_build
uses: ./.github/workflows/build_plugin.yml
with:
branch: ${{ needs.parse_trigger.outputs.trigger_branch_test }}
build_config: ${{ needs.parse_trigger.outputs.trigger_branch_test_build }}
# todo: add job to build or update repository json
# todo: add job to contribute the plugins to AutoRepo-Web
# todo: add job to update list of repos on discord via bot