Sync and Run Other Repo Releases #35
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: Sync and Run Other Repo Releases | |
permissions: | |
contents: write | |
on: | |
schedule: | |
- cron: '0 0 * * *' # 매일 자정 (00:00)에 실행되도록 설정 | |
workflow_dispatch: # 수동으로 실행할 수 있도록 설정 | |
jobs: | |
download_and_run: | |
runs-on: windows-latest | |
steps: | |
- name: Checkout the repository | |
uses: actions/checkout@v4 | |
with: | |
# Personal Access Token으로 push 권한 설정 | |
token: ${{ secrets.GIT_PAT }} | |
- name: Configure Git | |
run: | | |
git config --global user.name "Tb1281" | |
git config --global user.email "mail9595@jbnu.ac.kr" | |
- name: Get all releases from another repo | |
run: | | |
$repo = "armoha/euddraft" #euddraft repo | |
$releases_url = "https://api.github.com/repos/$repo/releases?" | |
$releases = @() | |
# 다른 사람의 릴리즈 목록 가져오기 | |
$page = 1 | |
do { | |
$current_page_url = "$releases_url&page=$page" | |
$current_releases = (Invoke-RestMethod -Uri $current_page_url).tag_name | |
$releases += $current_releases | |
$page++ | |
} while ($current_releases.Count -gt 0) | |
[Array]::Reverse($releases) | |
# 각 릴리즈마다 작업 수행 | |
foreach ($release in $releases) { | |
$zip_name = "euddraft$release.zip" -replace "euddraftv", "euddraft" | |
$exe_name = "euddraft.exe" | |
$json_name = "$release.json" | |
if (Test-Path $json_name) { | |
Write-Host "Skipping $release" | |
continue | |
} | |
$zip_url = "https://github.com/$repo/releases/download/$release/$zip_name" | |
$exe_output_folder = "$zip_name" -replace ".zip", "" | |
# zip 파일 다운로드 | |
Write-Host "Downloading $zip_name" | |
try { | |
Invoke-WebRequest -Uri $zip_url -OutFile $zip_name | |
Write-Host "Successfully fetched: $zip_url" | |
} | |
catch { | |
Write-Host "Failed to fetch: $zip_url. Skipping..." | |
continue | |
} | |
if (Test-Path $zip_name) { | |
# zip 파일 압축 풀기 | |
Write-Host "Extracting $zip_name" | |
Expand-Archive -Path $zip_name -DestinationPath $exe_output_folder -Force | |
# 압축이 풀린 폴더에서 exe 파일 찾기 | |
$exe_path = Get-ChildItem -Path $exe_output_folder -Filter "$exe_name" | Select-Object -First 1 | |
if ($exe_path) { | |
Write-Host "Disabling auto-update" | |
$timestamp = [math]::Round(((Get-Date) - (Get-Date "1970-01-01 00:00:00")).TotalSeconds) | |
Set-Content -Path "$exe_output_folder\vcheckpoint.dat" -Value "$timestamp $timestamp" | |
# exe 파일 실행 | |
Write-Host "Running $exe_name" | |
Start-Process cmd -ArgumentList '/c echo |', $exe_path.FullName, '.\src\EUDEditor.eds' -Wait | |
Rename-Item -Path '.\output.json' -NewName $json_name -Force | |
# 실행 후 JSON 파일 존재하는지 확인 | |
if (Test-Path $json_name) { | |
Write-Host "$json_name exists. Committing to repo." | |
# JSON 파일을 커밋 | |
git add $json_name | |
git commit -m "$release" | |
} else { | |
Write-Host "JSON file not found after running $exe_name" | |
} | |
} else { | |
Write-Host "No exe file found in $zip_name" | |
} | |
} else { | |
Write-Host "No zip file found" | |
} | |
} | |
# 커밋 푸시 | |
git push origin main | |