-
-
Notifications
You must be signed in to change notification settings - Fork 256
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create a GHA to run update and open a PR if diff (#327)
- Loading branch information
Showing
1 changed file
with
58 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
name: Update and Create PR | ||
|
||
on: | ||
schedule: | ||
- cron: '0 0 1 * *' # Runs on the first day of each month at midnight | ||
workflow_dispatch: # Allows the workflow to be triggered manually | ||
|
||
jobs: | ||
update-and-pr: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository 🛎️ | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Node.js 🛠️ | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: 'lts/*' # Use the LTS version of Node.js | ||
|
||
- name: Install dependencies 📦 | ||
run: npm install | ||
|
||
- name: Run update script 🔄 | ||
run: npm run update | ||
|
||
- name: Check for changes and create branch 📤 | ||
id: check_changes | ||
run: | | ||
git config --global user.name "github-actions[bot]" | ||
git config --global user.email "github-actions[bot]@users.noreply.github.com" | ||
if [ -n "$(git status --porcelain)" ]; then | ||
BRANCH_NAME="update-branch" | ||
if git show-ref --verify --quiet "refs/heads/$BRANCH_NAME"; then | ||
TIMESTAMP=$(date +%s) | ||
BRANCH_NAME="${BRANCH_NAME}-${TIMESTAMP}" | ||
fi | ||
git checkout -b $BRANCH_NAME | ||
git add db.json src/ | ||
git commit -m "Automated update" | ||
git push --set-upstream origin $BRANCH_NAME | ||
echo "::set-output name=changes_detected::true" | ||
echo "::set-output name=branch::$BRANCH_NAME" | ||
else | ||
echo "No changes detected." | ||
echo "::set-output name=changes_detected::false" | ||
echo "::set-output name=branch::" | ||
- name: Create Pull Request 🚀 | ||
if: steps.check_changes.outputs.changes_detected == 'true' | ||
uses: peter-evans/create-pull-request@v4 | ||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
branch: ${{ steps.check_changes.outputs.branch }} | ||
title: "🤖Automated update" | ||
body: "This PR contains automated updates from running `npm run update`" | ||
labels: ["automated update"] | ||
|