Update plugins.csv #40
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: Update plugins.csv | |
on: | |
schedule: | |
- cron: '0 0 * * *' # Run daily at midnight UTC | |
workflow_dispatch: # Allow manual triggering | |
permissions: | |
contents: write | |
jobs: | |
update-plugins-csv: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Install jq | |
run: sudo apt-get install jq | |
- name: Update plugins.csv | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
#!/bin/bash | |
set -e | |
ORG="Open-WP-Club" | |
REPO="${GITHUB_REPOSITORY#*/}" | |
OWNER="${GITHUB_REPOSITORY%%/*}" | |
BLOCKLIST=(".github" "security-checker") | |
# Function to check if an item is in the blocklist | |
in_blocklist() { | |
local item="$1" | |
for i in "${BLOCKLIST[@]}"; do | |
if [[ "$i" == "$item" ]]; then | |
return 0 | |
fi | |
done | |
return 1 | |
} | |
# Fetch repositories | |
echo "Fetching repositories..." | |
REPOS=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \ | |
"https://api.github.com/orgs/$ORG/repos?per_page=100" | jq -r '.[] | @base64') | |
# Prepare CSV data | |
echo "repo-name,Display Name,Description,Version,Repo URL" > plugins.csv | |
# Process each repository | |
for repo in $REPOS; do | |
# Decode repository data | |
REPO_DATA=$(echo "$repo" | base64 --decode) | |
REPO_NAME=$(echo "$REPO_DATA" | jq -r '.name') | |
if ! in_blocklist "$REPO_NAME"; then | |
DESCRIPTION=$(echo "$REPO_DATA" | jq -r '.description // "No description available"') | |
HTML_URL=$(echo "$REPO_DATA" | jq -r '.html_url') | |
DISPLAY_NAME=$(echo "$REPO_NAME" | sed 's/-/ /g' | awk '{for(i=1;i<=NF;i++){ $i=toupper(substr($i,1,1)) substr($i,2) }}1') | |
# Get latest release version | |
RELEASE=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \ | |
"https://api.github.com/repos/$ORG/$REPO_NAME/releases/latest") | |
if [[ $(echo "$RELEASE" | jq -r '.message // empty') == "Not Found" ]]; then | |
VERSION="N/A" | |
else | |
VERSION=$(echo "$RELEASE" | jq -r '.tag_name' | sed 's/^v//') | |
fi | |
# Append to CSV | |
echo "$REPO_NAME,$DISPLAY_NAME,\"$DESCRIPTION\",$VERSION,$HTML_URL" >> plugins.csv | |
fi | |
done | |
echo "CSV file created." | |
# Check if plugins.csv exists in the repository | |
FILE_SHA=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \ | |
"https://api.github.com/repos/$OWNER/$REPO/contents/plugins.csv" | jq -r '.sha // empty') | |
if [[ -n "$FILE_SHA" ]]; then | |
echo "Updating existing plugins.csv file" | |
CONTENT=$(base64 -w 0 plugins.csv) | |
curl -X PUT -H "Authorization: token $GITHUB_TOKEN" \ | |
-d "{\"message\":\"Update plugins.csv\",\"content\":\"$CONTENT\",\"sha\":\"$FILE_SHA\"}" \ | |
"https://api.github.com/repos/$OWNER/$REPO/contents/plugins.csv" | |
else | |
echo "Creating new plugins.csv file" | |
CONTENT=$(base64 -w 0 plugins.csv) | |
curl -X PUT -H "Authorization: token $GITHUB_TOKEN" \ | |
-d "{\"message\":\"Create plugins.csv\",\"content\":\"$CONTENT\"}" \ | |
"https://api.github.com/repos/$OWNER/$REPO/contents/plugins.csv" | |
fi | |
echo "plugins.csv has been updated successfully" |