Skip to content

Update plugins.csv

Update plugins.csv #11

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: Checkout repository
uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '20'
- name: Install dependencies
run: npm install @octokit/rest csv-stringify
- name: Update plugins.csv
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
node - <<EOF
const { Octokit } = require('@octokit/rest');
const { stringify } = require('csv-stringify/sync');
const octokit = new Octokit({ auth: process.env.GITHUB_TOKEN });
async function updatePluginsCsv() {
const org = 'Open-WP-Club';
const [owner, repo] = process.env.GITHUB_REPOSITORY.split('/');
const blocklist = ['plugin-hub', '.github', 'security-checker'];
console.log('Fetching repositories...');
const { data: repos } = await octokit.repos.listForOrg({ org, per_page: 100 });
console.log(`Found ${repos.length} repositories`);
const csvData = [['repo-name', 'Display Name', 'Description', 'Version', 'Repo URL']];
for (const repo of repos) {
if (!blocklist.includes(repo.name)) {
let version = 'N/A';
try {
const { data: release } = await octokit.repos.getLatestRelease({ owner: org, repo: repo.name });
version = release.tag_name.replace(/^v/, '');
} catch (error) {
console.log(`No releases found for ${repo.name}`);
}
csvData.push([
repo.name,
repo.name.replace(/-/g, ' ').replace(/\b\w/g, l => l.toUpperCase()),
repo.description || 'No description available',
version,
repo.html_url
]);
}
}
const csvContent = stringify(csvData);
try {
const { data: existingFile } = await octokit.repos.getContent({
owner,
repo,
path: 'plugins.csv',
});
console.log('Updating existing plugins.csv file');
await octokit.repos.createOrUpdateFileContents({
owner,
repo,
path: 'plugins.csv',
message: 'Update plugins.csv',
content: Buffer.from(csvContent).toString('base64'),
sha: existingFile.sha,
});
} catch (error) {
if (error.status === 404) {
console.log('Creating new plugins.csv file');
await octokit.repos.createOrUpdateFileContents({
owner,
repo,
path: 'plugins.csv',
message: 'Create plugins.csv',
content: Buffer.from(csvContent).toString('base64'),
});
} else {
throw error;
}
}
console.log('plugins.csv has been updated successfully');
}
updatePluginsCsv().catch(error => {
console.error('Error:', error);
process.exit(1);
});
EOF