Skip to content

Commit

Permalink
Merge branch 'anaskhan28:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
mizhuara authored Aug 10, 2024
2 parents e7d0c54 + fb1b561 commit 9f5c68a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 24 deletions.
19 changes: 13 additions & 6 deletions .github/scripts/verify_playlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)}")
Expand All @@ -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()
32 changes: 14 additions & 18 deletions .github/workflows/verify-playlist.yaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
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:
runs-on: ubuntu-latest
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
Expand All @@ -35,32 +37,26 @@ jobs:
id: read-result
run: |
if [ -f result.txt ]; then
RESULT=$(<result.txt)
RESULT=$(cat result.txt)
echo "RESULT<<EOF" >> $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
with:
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

0 comments on commit 9f5c68a

Please sign in to comment.