Parse and Process Trigger #93
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |