[Sync]: Request for chart sync #208
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: Daily Scrape | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: "30 20 * * *" | |
issues: | |
types: | |
- opened | |
jobs: | |
scrape: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
issues: write | |
steps: | |
- name: Check to proceed | |
id: check_to_proceed | |
shell: pwsh | |
run: | | |
$proceed = "false" | |
$chartSyncRequest = "false" | |
if ("${{ github.event_name }}" -eq "workflow_dispatch") { | |
$proceed = "true" | |
} elseif ("${{ github.event_name }}" -eq "schedule") { | |
$proceed = "true" | |
} elseif ("${{ github.event_name }}" -eq "issues" -and "${{ github.event.action }}" -eq "opened") { | |
if (${{ toJson(github.event.issue.body) }} -eq "### Issue Type\n\nSync Request") { | |
$proceed = "true" | |
$chartSyncRequest = "true" | |
} | |
} | |
"proceed=$proceed" >> $env:GITHUB_OUTPUT | |
"chartSyncRequest=$chartSyncRequest" >> $env:GITHUB_OUTPUT | |
- name: Checkout code | |
if: steps.check_to_proceed.outputs.proceed == 'true' | |
uses: actions/checkout@v4 | |
- name: Setup .NET | |
if: steps.check_to_proceed.outputs.proceed == 'true' | |
uses: actions/setup-dotnet@v4 | |
with: | |
dotnet-version: '8.x' | |
- name: Restore NuGet packages | |
if: steps.check_to_proceed.outputs.proceed == 'true' | |
shell: bash | |
run: | | |
dotnet restore | |
- name: Build solution | |
if: steps.check_to_proceed.outputs.proceed == 'true' | |
shell: bash | |
run: | | |
dotnet build -c Release | |
- name: Install Playwright | |
if: steps.check_to_proceed.outputs.proceed == 'true' | |
shell: pwsh | |
run: | | |
$playwright = Get-ChildItem -File Microsoft.Playwright.dll -Path . -Recurse | |
$installer = "$($playwright[0].Directory.FullName)/playwright.ps1" | |
& "$installer" install | |
- name: Run Melon app - Melon Top 100 | |
if: steps.check_to_proceed.outputs.proceed == 'true' | |
shell: pwsh | |
run: | | |
$date = (Get-Date).ToUniversalTime().AddHours(9).ToString("yyyyMMdd") | |
# $result = dotnet run --project ./samples/MelonChart.ConsoleApp/ -- -c Top100 --json | ConvertFrom-Json | |
$result = dotnet run --project ./samples/MelonChart.ConsoleApp/ -- -c Top100 --json | |
mkdir -p ./data | |
pushd ./data | |
# $result | ConvertTo-Json -Depth 100 | Out-File -FilePath "top100-$date.json" -Force | |
$result | Out-File -FilePath "top100-$date.json" -Force | |
popd | |
- name: Run Spotify app - Melon Top 100 | |
if: steps.check_to_proceed.outputs.proceed == 'true' | |
shell: pwsh | |
run: | | |
$appsettings = Get-Content -Path ./samples/SpotifyPlaylist.ConsoleApp/appsettings.Development.sample.json | ConvertFrom-Json | |
$appsettings.Azure.APIM.BaseUrl = "${{ secrets.APIM_BASE_URL }}" | |
$appsettings.Azure.APIM.SubscriptionKey = "${{ secrets.APIM_SUBSCRIPTION_KEY }}" | |
$appsettings | ConvertTo-Json -Depth 100 | Out-File -FilePath ./samples/SpotifyPlaylist.ConsoleApp/appsettings.Development.json -Force | |
$date = (Get-Date).ToUniversalTime().AddHours(9).ToString("yyyyMMdd") | |
# $result = dotnet run --project ./samples/SpotifyPlaylist.ConsoleApp/ -- -t melon -s "../../data/top100-$date.json" --json | ConvertFrom-Json | |
$result = dotnet run --project ./samples/SpotifyPlaylist.ConsoleApp/ -- -t melon -s "../../data/top100-$date.json" --json | |
mkdir -p ./data | |
pushd ./data | |
# $result[$($result.indexOf("{"))..$($result.Length-1)] | ConvertTo-Json -Depth 100 | Out-File -FilePath "spotify100-$date.json" -Force | |
$result[$($result.indexOf("{"))..$($result.Length-1)] | Out-File -FilePath "spotify100-$date.json" -Force | |
popd | |
# - name: Run Spotify app - Billboard Hot 100 | |
# if: steps.check_to_proceed.outputs.proceed == 'true' | |
# shell: pwsh | |
# run: | | |
# $appsettings = Get-Content -Path ./samples/SpotifyPlaylist.ConsoleApp/appsettings.Development.sample.json | ConvertFrom-Json | |
# $appsettings.Azure.APIM.BaseUrl = "${{ secrets.APIM_BASE_URL }}" | |
# $appsettings.Azure.APIM.SubscriptionKey = "${{ secrets.APIM_SUBSCRIPTION_KEY }}" | |
# $appsettings | ConvertTo-Json -Depth 100 | Out-File -FilePath ./samples/SpotifyPlaylist.ConsoleApp/appsettings.Development.json -Force | |
# $date = (Get-Date).ToUniversalTime().AddHours(9).ToString("yyyyMMdd") | |
# # $result = dotnet run --project ./samples/SpotifyPlaylist.ConsoleApp/ -- -t spotify -s ${{ secrets.SPOTIFY_BILLBOARD_HOT100_PLAYLIST_ID }} --json | ConvertFrom-Json | |
# $result = dotnet run --project ./samples/SpotifyPlaylist.ConsoleApp/ -- -t spotify -s ${{ secrets.SPOTIFY_BILLBOARD_HOT100_PLAYLIST_ID }} --json | |
# mkdir -p ./data | |
# pushd ./data | |
# # $result[$($result.indexOf("{"))..$($result.Length-1)] | ConvertTo-Json -Depth 100 | Out-File -FilePath "billboard100-$date.json" -Force | |
# $result[$($result.indexOf("{"))..$($result.Length-1)] | Out-File -FilePath "billboard100-$date.json" -Force | |
# popd | |
- name: Upload data | |
if: steps.check_to_proceed.outputs.proceed == 'true' | |
uses: stefanzweifel/git-auto-commit-action@v5 | |
with: | |
commit_message: "Update data" | |
branch: "main" | |
commit_user_name: "GitHub Actions" | |
commit_user_email: "scraper+github-actions[bot]@users.noreply.github.com" | |
commit_author: "GitHub Actions <scraper+github-actions[bot]@users.noreply.github.com>" | |
- name: Check missing tracks | |
id: missing_tracks | |
if: steps.check_to_proceed.outputs.proceed == 'true' | |
shell: pwsh | |
run: | | |
$date = (Get-Date).ToUniversalTime().AddHours(9).ToString("yyyyMMdd") | |
$collection = Get-Content "./data/spotify100-$date.json" | ConvertFrom-Json | |
$missingTracks = ($collection.missingTracks.Count -gt 0).ToString().ToLowerInvariant() | |
"exist=$missingTracks" >> $env:GITHUB_OUTPUT | |
- name: Issue missing tracks | |
if: | | |
steps.check_to_proceed.outputs.proceed == 'true' && | |
steps.missing_tracks.outputs.exist == 'true' | |
shell: pwsh | |
env: | |
GH_TOKEN: ${{ github.token }} | |
run: | | |
$date = (Get-Date).ToUniversalTime().AddHours(9).ToString("yyyyMMdd") | |
$collection = Get-Content "./data/spotify100-$date.json" | ConvertFrom-Json | |
$tracks = $collection.missingTracks | ConvertTo-Json -Depth 100 | |
gh issue create ` | |
--title "Missing tracks in Spotify playlist" ` | |
--body "The following tracks are missing in the Spotify playlist:`r`n```````jsonr`n$tracks`r`n```````r`n" ` | |
--label missing-tracks | |
- name: Close sync request | |
if: | | |
steps.check_to_proceed.outputs.proceed == 'true' && | |
steps.check_to_proceed.outputs.chartSyncRequest == 'true' | |
shell: pwsh | |
env: | |
GH_TOKEN: ${{ github.token }} | |
run: | | |
$issueNumber = ${{ github.event.issue.number }} | |
gh issue close $issueNumber ` | |
--reason completed ` | |
--comment "The chart has been synced up-to-date." |