Towerfall Ascension [PCSE00747] #7265
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: Compatibility database update | |
on: | |
push: | |
issues: | |
jobs: | |
update_compat_db: | |
runs-on: windows-latest | |
if: github.repository == 'Vita3K/compatibility' | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Generate compatibility database xml file | |
run: | | |
$headers = @{ | |
Authorization = "Token ${{ secrets.GITHUB_TOKEN }}" | |
} | |
$compat_link = "https://api.github.com/repos/Vita3K/compatibility" | |
$issues_link = $compat_link + "/issues" | |
$app_updated = (Invoke-RestMethod -Uri $issues_link"?state=all&sort=updated" -Headers $headers)[0] | |
$db_updated_at = [DateTime]::Parse($app_updated.updated_at).ToUniversalTime().ToString("yyyy-MM-dd HH:mm:ssZ", [System.Globalization.CultureInfo]::InvariantCulture) | |
$db_updated_at_old = [DateTime]::Parse($app_updated.updated_at).ToUniversalTime().ToString("MM-dd-yyyy HH:mm:ss", [System.Globalization.CultureInfo]::InvariantCulture) # Do not delete this line for keep compatibility | |
$open_issues_count = (Invoke-RestMethod -Uri "$compat_link" -Headers $headers).open_issues_count | |
$page_count = @() | |
for ($i = 0; $i -lt $open_issues_count; $i += 100) { | |
$page = [Math]::Floor($i / 100) + 1 | |
$per_page = [Math]::Min($open_issues_count - $i, 100) | |
$page_count += New-Object PSObject -Property @{First=$page; Second=$per_page} | |
} | |
$xml = New-Object System.Xml.XmlDocument | |
$xml.AppendChild($xml.CreateXmlDeclaration("1.0", "UTF-8", $null)) | Out-Null | |
$xml.AppendChild($xml.CreateComment("This file is automatically generated by a GitHub action. Do not edit it manually.")) | Out-Null | |
$root = $xml.CreateElement("compatibility") | |
$root.SetAttribute("iso_db_updated_at", $db_updated_at) | |
$root.SetAttribute("db_updated_at", $db_updated_at_old) | |
$root.SetAttribute("version", "1") | |
$xml.AppendChild($root) | Out-Null | |
$issue_count = 0 | |
foreach ($page in $page_count) { | |
$current_page = $page.First | |
$per_page = $page.Second | |
$issues = (Invoke-RestMethod -Uri $issues_link"?page=$current_page&per_page=100" -Headers $headers)[0..$per_page] | Where-Object { $_.pull_request -eq $null } | |
foreach ($issue in $issues) { | |
$issueNode = $xml.CreateElement("app") | |
$title = $issue.title.TrimEnd() | |
if ($title.Length -gt 9) { | |
$title = $title.Substring($title.Length-10,9) | |
} | |
$issueNode.SetAttribute("title_id", $title) | |
$numberNode = $xml.CreateElement("issue_id") | |
$numberNode.InnerText = $issue.number | |
$issueNode.AppendChild($numberNode) | Out-Null | |
$labelsNode = $xml.CreateElement("labels") | |
foreach ($label in $issue.labels) { | |
$labelNode = $xml.CreateElement("label") | |
$labelNode.InnerText = $label.id | |
$labelsNode.AppendChild($labelNode) | Out-Null | |
} | |
$issueNode.AppendChild($labelsNode) | Out-Null | |
$ts_updated_at = (([DateTime]::Parse($issue.updated_at).ToUniversalTime()) - ([DateTime]::Parse('01/01/1970 00:00:00'))).TotalSeconds | |
$updated_atNode = $xml.CreateElement("updated_at") | |
$updated_atNode.InnerText = $ts_updated_at | |
$issueNode.AppendChild($updated_atNode) | Out-Null | |
$root.AppendChild($issueNode) | Out-Null | |
$issue_count++ | |
} | |
} | |
$root.SetAttribute("issue_count", $issue_count) | |
$xml.Save("app_compat_db.xml") | |
"$issue_count issues have been retrieved from the compatibility database" | |
$issue_id_updated = $app_updated.number | |
Add-Content -Path $env:GITHUB_ENV -Value "issue_id_updated=$issue_id_updated" | |
$app_updated_title = $app_updated.title | |
Add-Content -Path $env:GITHUB_ENV -Value "app_updated_title=$app_updated_title" | |
Add-Content -Path $env:GITHUB_ENV -Value "db_updated_at=$db_updated_at" | |
Add-Content -Path $env:GITHUB_ENV -Value "db_updated_at_old=$db_updated_at_old" | |
- name: Zip compatibility database | |
run: | | |
Compress-Archive -Path app_compat_db.xml -DestinationPath app_compat_db.xml.zip | |
# 7z a -mx=9 app_compat_db.xml.7z app_compat_db.xml | |
- name: Prepare files for release | |
run: | | |
mkdir compat_dbs | |
cp app_compat_db.xml compat_dbs/ | |
cp app_compat_db.xml.zip compat_dbs/ | |
# cp app_compat_db.xml.7z compat_dbs/ | |
- name: Upload compatibility database | |
run: | | |
Invoke-WebRequest "https://github.com/tcnksm/ghr/releases/download/v0.16.2/ghr_v0.16.2_windows_amd64.zip" -OutFile ghr.zip | |
Expand-Archive -Force -Path ghr.zip -DestinationPath '.' | |
$releases = Invoke-RestMethod -Uri "https://api.github.com/repos/Vita3K/compatibility/releases" -Headers @{Authorization = "Bearer $env:GITHUB_TOKEN"} | |
if ($releases -ne $null) { | |
foreach ($release in $releases) { | |
Invoke-RestMethod -Uri $release.url -Method DELETE -Headers @{Authorization = "Bearer $env:GITHUB_TOKEN"} | |
} | |
} | |
.\ghr_v0.16.2_windows_amd64\ghr -u Vita3K -r compatibility -n "Automatic CI generated database" -b "Corresponding issue: #${{ env.issue_id_updated }} for App: ${{ env.app_updated_title }}`r`nLast updated: ${{ env.db_updated_at }}`r`n<!-- Updated at: ${{ env.db_updated_at_old }} -->" -t "${{ secrets.GITHUB_TOKEN }}" compat_db compat_dbs/ | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |