Skip to content

Update plugins.csv

Update plugins.csv #8

name: Update plugins.csv
on:
schedule:
- cron: '0 0 * * *' # Run daily at midnight UTC
workflow_dispatch: # Allow manual triggering
permissions:
contents: write
actions: read
checks: read
deployments: read
issues: read
packages: read
pull-requests: read
repository-projects: read
security-events: read
statuses: read
jobs:
update-plugins-csv:
runs-on: ubuntu-latest
steps:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install PyGithub requests
- name: Update plugins.csv
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
python - <<EOF
import os
import csv
from github import Github
# Initialize GitHub client
g = Github(os.environ['GITHUB_TOKEN'])
# Get the Open-WP-Club organization
org = g.get_organization('Open-WP-Club')
# Get the current repository
repo = g.get_repo(os.environ['GITHUB_REPOSITORY'])
# Define blocklist
blocklist = ['plugin-hub', '.github', 'security-checker']
# Get all repositories
repos = org.get_repos()
# Prepare CSV data
csv_data = [['repo-name', 'Display Name', 'Description', 'Version', 'Repo URL']]
for repo in repos:
if repo.name not in blocklist:
# Get the latest release version
try:
latest_release = repo.get_latest_release()
version = latest_release.tag_name.lstrip('v')
except:
version = 'N/A'
# Append repo data to CSV data
csv_data.append([
repo.name,
repo.name.replace('-', ' ').title(), # Display Name
repo.description or 'No description available',
version,
repo.html_url
])
# Convert CSV data to string
csv_content = '\n'.join([','.join(row) for row in csv_data])
# Get the current file (if it exists)
try:
file = repo.get_contents('plugins.csv', ref='main')
sha = file.sha
except:
sha = None
# Update or create the file
repo.update_file(
path='plugins.csv',
message='Update plugins.csv',
content=csv_content,
sha=sha,
branch='main'
)
print("plugins.csv has been updated successfully.")
EOF