Polytoria Update #9558
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
name: Polytoria Update | |
on: | |
schedule: | |
- cron: '*/15 * * * *' | |
push: | |
branches: | |
- main | |
jobs: | |
update: | |
runs-on: windows-latest | |
permissions: | |
contents: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Fetch Polytoria updates | |
id: fetch-updates | |
run: | | |
$response = Invoke-WebRequest -Uri 'https://api.polytoria.com/v1/launcher/updates?os=windows&release=stable' -UseBasicParsing | |
$json = $response.Content | ConvertFrom-Json | |
echo "VERSION=$($json.Client.Version)" >> $env:GITHUB_ENV | |
echo "DOWNLOAD_URL=$($json.Client.Download)" >> $env:GITHUB_ENV | |
- name: Check if client version exists | |
run: | | |
if (Test-Path "./versions/${{ env.VERSION }}") { | |
echo "Client version already exists. Cancelling." | |
exit 1 | |
} | |
- name: Download and unzip client | |
run: | | |
$outputPath = 'client.7z' | |
Invoke-WebRequest -Uri $env:DOWNLOAD_URL -OutFile $outputPath | |
7z x $outputPath -o"client" | |
- name: Run Polytoria Client and wait for 15 seconds | |
run: | | |
Start-Process -FilePath "client/Polytoria Client.exe" -ArgumentList "--dump-api" | |
Start-Sleep -s 15 | |
Stop-Process -Name "Polytoria Client" -Force | |
- name: Upload ReflectionData.xml | |
run: | | |
$version = '${{ env.VERSION }}' | |
$reflectionDataPath = [Environment]::GetFolderPath('MyDocuments') + "\Polytoria Scripting API Dump\ReflectionData.xml" | |
$destPath = "./versions/$version/ReflectionData.xml" | |
mkdir -p (Split-Path -Parent $destPath) | |
Copy-Item $reflectionDataPath -Destination $destPath | |
- name: Generate changes.md | |
run: | | |
$version = '${{ env.VERSION }}' | |
$previousVersion = Get-ChildItem -Directory ./versions | Sort-Object Name | Select-Object -Last 2 | Select-Object -First 1 | |
$oldFile = "./versions/$($previousVersion.Name)/ReflectionData.xml" | |
$newFile = "./versions/$version/ReflectionData.xml" | |
$changesFile = "./versions/$version/changes.md" | |
python ./scripts/generate_changes.py $oldFile $newFile $changesFile | |
- name: Upload file to archive.org | |
uses: qoijjj/internet-archive-upload@v7 | |
with: | |
access-key: ${{ secrets.IA_ACCESS_KEY }} | |
secret-key: ${{ secrets.IA_SECRET_KEY }} | |
identifier: "polytoria-client-${{ env.VERSION }}" | |
files: "client.7z" | |
- name: Create archive-link.md in versions folder | |
run: | | |
$version = '${{ env.VERSION }}' | |
echo "Download the client from [archive.org](https://archive.org/details/polytoria-client-${{ env.VERSION }})" > "./versions/$version/archive-link.md" | |
- name: Commit and push changes | |
uses: stefanzweifel/git-auto-commit-action@v5 | |
with: | |
commit_message: "Add ReflectionData.xml and changes.md and archive link for version ${{ env.VERSION }}" | |
branch: main | |
file_pattern: "./versions/${{ env.VERSION }}/*" | |
commit_user_name: github-actions[bot] | |
commit_user_email: github-actions[bot]@users.noreply.github.com | |
- name: Send changes to Discord | |
run: | | |
$version = '${{ env.VERSION }}' | |
$changes = Get-Content -Path "./versions/$version/changes.md" -Raw | |
$webhookUrl = '${{ secrets.DISCORD_WEBHOOK }}' | |
$changesToSend = if ($changes.Length -gt 1500) { | |
$changes.Substring(0, 1500) + "`n...`n[Read the full changelog](https://github.com/GoldenretriverYT/polytoria-update-changelog/blob/main/versions/$version/changes.md)" | |
} else { | |
$changes | |
} | |
$payload = @{ | |
content = "Changes for version $($version):`n`n$($changesToSend)" | |
} | ConvertTo-Json | |
Invoke-RestMethod -Uri $webhookUrl -Method Post -ContentType "application/json" -Body $payload |