Update directory #4784
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 directory | |
on: | |
schedule: | |
- cron: '0 10-15 * * *' | |
workflow_dispatch: | |
jobs: | |
update-directory: | |
runs-on: ubuntu-latest | |
steps: | |
- name: check out | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 1 | |
- name: setup node | |
uses: actions/setup-node@v4 | |
with: | |
node-version: latest | |
cache: 'npm' | |
- name: npm install | |
run: | | |
npm install | |
- name: update directory | |
run: | | |
echo "UPDATED_PLUGIN_DATA=$(npm run --silent plugins-directory update-directory)" >> $GITHUB_ENV | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: set update name | |
if: ${{ env.UPDATED_PLUGIN_DATA }} | |
run: | | |
echo "UPDATED_PLUGIN=$(npm run --silent plugins-directory update-name-from-plugin-data)" >> $GITHUB_ENV | |
- name: save | |
if: ${{ env.UPDATED_PLUGIN }} | |
run: | | |
# Git config | |
git config user.name github-actions[bot] | |
git config user.email 41898282+github-actions[bot]@users.noreply.github.com | |
git checkout -b "update-directory/$UPDATED_PLUGIN" | |
git add . | |
git commit --allow-empty -m "$UPDATED_PLUGIN" | |
git push --set-upstream origin "update-directory/$UPDATED_PLUGIN" | |
- name: Open pull request | |
if: ${{ env.UPDATED_PLUGIN }} | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const { repo, owner } = context.repo; | |
const updatedPluginData = JSON.parse(Buffer.from(process.env.UPDATED_PLUGIN_DATA, 'base64').toString()); | |
const name = '## ' + '`` ' + (updatedPluginData.packageName ?? '-') + ' ``\n'; | |
const description = '### description:\n- ' + '`` ' + (updatedPluginData.description ?? '-') + ' ``\n'; | |
const keywords = '### keywords:\n- ' + (updatedPluginData.keywords ?? []).map(x => '`` ' + x + ' ``').join('\n- ') + '\n'; | |
const result = await github.rest.pulls.create({ | |
title: updatedPluginData.updateName, | |
owner, | |
repo, | |
head: `update-directory/${updatedPluginData.updateName}`, | |
base: 'main', | |
body: [ | |
'_This PR is auto-generated_', | |
name, | |
description, | |
keywords, | |
].join('\n') | |
}); | |
github.rest.issues.addLabels({ | |
owner, | |
repo, | |
issue_number: result.data.number, | |
labels: ['update directory'] | |
}); |