diff --git a/.github/scripts/verify_playlist.py b/.github/scripts/verify_playlist.py index 524c404..7899fb3 100644 --- a/.github/scripts/verify_playlist.py +++ b/.github/scripts/verify_playlist.py @@ -47,7 +47,7 @@ def check_youtube_links(playlists): def main(): errors = [] try: - playlists = load_playlists('playlist.json') + playlists = load_playlists('../../playlist.json') validate_schema(playlists) except json.JSONDecodeError as e: errors.append(f"Invalid JSON format: {str(e)}") @@ -72,15 +72,22 @@ def main(): # Create the message if errors: - message = "❌ Playlist verification failed. Please address the following issues:\n\n" + message = "Playlist verification failed. Please address the following issues:\n\n" message += "\n".join(f"- {error}" for error in errors) message += "\n\nPlease review and update your submission." else: - message = "✅ Playlist verification passed! Your submission looks good." + message = "Playlist verification passed! Your submission looks good." - # Write result to result.txt - with open('result.txt', 'w') as fh: - fh.write(message) + # Write result to result.txt using UTF-8 encoding + try: + with open('result.txt', 'w', encoding='utf-8') as fh: + fh.write(message) + except Exception as e: + print(f"Error writing to file: {str(e)}") + # Fallback to printing the message if file writing fails + print(message) + # For GitHub Actions + print(f"::set-output name=result::{message}") if __name__ == "__main__": main() diff --git a/.github/workflows/verify-playlist.yaml b/.github/workflows/verify-playlist.yaml index ce3175f..f07e560 100644 --- a/.github/workflows/verify-playlist.yaml +++ b/.github/workflows/verify-playlist.yaml @@ -1,14 +1,14 @@ name: Verify Playlist Submission on: - pull_request: + pull_request_target: paths: - 'playlist.json' permissions: - contents: write # Needed for commenting on PR - issues: write # Needed for commenting on issues - pull-requests: write # Needed for commenting on PR + contents: read + issues: write + pull-requests: write jobs: verify: @@ -16,6 +16,8 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v3 + with: + ref: ${{ github.event.pull_request.head.sha }} - name: Set up Python uses: actions/setup-python@v4 @@ -35,14 +37,13 @@ jobs: id: read-result run: | if [ -f result.txt ]; then - RESULT=$(> $GITHUB_ENV echo "$RESULT" >> $GITHUB_ENV echo "EOF" >> $GITHUB_ENV - else - echo "RESULT=Verification script did not produce a result file." >> $GITHUB_ENV - fi - shell: /usr/bin/bash -e {0} + else + echo "RESULT=Verification script did not produce a result file." >> $GITHUB_ENV + fi - name: Comment on PR uses: actions/github-script@v6 @@ -50,17 +51,12 @@ jobs: github-token: ${{ secrets.GITHUB_TOKEN }} script: | const output = process.env.RESULT || "❌ Playlist verification failed."; - const issueNumber = context.payload.pull_request.number; - const owner = context.repo.owner; - const repo = context.repo.repo; - console.log(`Owner: ${owner}, Repo: ${repo}, Issue Number: ${issueNumber}`); await github.rest.issues.createComment({ - owner: owner, - repo: repo, - issue_number: issueNumber, + ...context.repo, + issue_number: context.issue.number, body: output }); - name: Set workflow status - if: ${{ env.RESULT != '✅ Playlist verification passed! Your submission looks good.' }} - run: exit 1 + if: ${{ !startsWith(env.RESULT, '✅ Playlist verification passed!') }} + run: exit 1 \ No newline at end of file