Publish Explaining CNNs assignment notebook #228
Workflow file for this run
This file contains hidden or 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: Check Collaborators and Repo Privacy | |
| on: [push, public, workflow_dispatch] | |
| jobs: | |
| check-collaborators: | |
| runs-on: ubuntu-latest | |
| if: vars.ENABLE_COLLABORATOR_CHECK == 'true' | |
| steps: | |
| - name: Set up Python | |
| uses: actions/setup-python@v2 | |
| with: | |
| python-version: '3.x' | |
| - name: Install Dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install requests | |
| - name: Check Collaborators and Repository Privacy | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| REPOSITORY: ${{ github.repository }} | |
| COLLABORATORS: ${{ vars.COLLABORATORS }} | |
| run: | | |
| import requests | |
| import os | |
| # ANSI color codes | |
| RED = '\033[91m' | |
| GREEN = '\033[92m' | |
| RESET = '\033[0m' | |
| # Read collaborators from repository variable (comma-separated) | |
| # Configure in Settings > Secrets and variables > Actions > Variables | |
| collaborators_str = os.getenv('COLLABORATORS', '') | |
| users_to_check = [u.strip() for u in collaborators_str.split(',') if u.strip()] | |
| if not users_to_check: | |
| print(RED + "[X] No collaborators configured. Set the COLLABORATORS repository variable (comma-separated GitHub usernames)." + RESET) | |
| exit(1) | |
| action_result = 0 | |
| token = os.getenv('GITHUB_TOKEN') | |
| repo = os.getenv('REPOSITORY') | |
| headers = {'Authorization': f'token {token}'} | |
| # Check if the repository is private | |
| repo_info = requests.get(f'https://api.github.com/repos/{repo}', headers=headers).json() | |
| if repo_info.get('private', False): | |
| print(GREEN + "[✓] Repository is private." + RESET) | |
| else: | |
| print(RED + "[X] Repository is NOT private." + RESET) | |
| action_result = 1 | |
| # Check each user | |
| for user in users_to_check: | |
| response = requests.get(f'https://api.github.com/repos/{repo}/collaborators/{user}', headers=headers) | |
| if response.status_code == 204: | |
| print(GREEN + f"[✓] {user} is a collaborator." + RESET) | |
| else: | |
| print(RED + f"[X] {user} is NOT a collaborator." + RESET) | |
| action_result = 1 | |
| exit(action_result) | |
| shell: python |