Skip to content

Commit 10fce91

Browse files
committed
create a GHA to run update and open a PR if diff
1 parent 2d87025 commit 10fce91

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

.github/workflows/generate.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Update and Create PR
2+
3+
on:
4+
schedule:
5+
- cron: '0 0 1 * *' # Runs on the first day of each month at midnight
6+
workflow_dispatch: # Allows the workflow to be triggered manually
7+
8+
jobs:
9+
update-and-pr:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout repository 🛎️
14+
uses: actions/checkout@v2
15+
16+
- name: Set up Node.js 🛠️
17+
uses: actions/setup-node@v2
18+
with:
19+
node-version: 'lts/*' # Use the LTS version of Node.js
20+
21+
- name: Install dependencies 📦
22+
run: npm install
23+
24+
- name: Run update script 🔄
25+
run: npm run update
26+
27+
- name: Check for changes and create branch 📤
28+
id: check_changes
29+
run: |
30+
git config --global user.name "github-actions[bot]"
31+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
32+
if [ -n "$(git status --porcelain)" ]; then
33+
BRANCH_NAME="update-branch"
34+
if git show-ref --verify --quiet "refs/heads/$BRANCH_NAME"; then
35+
TIMESTAMP=$(date +%s)
36+
BRANCH_NAME="${BRANCH_NAME}-${TIMESTAMP}"
37+
fi
38+
git checkout -b $BRANCH_NAME
39+
git add .
40+
git commit -m "Automated update"
41+
git push --set-upstream origin $BRANCH_NAME
42+
echo "::set-output name=changes_detected::true"
43+
echo "::set-output name=branch::$BRANCH_NAME"
44+
else
45+
echo "No changes detected."
46+
echo "::set-output name=changes_detected::false"
47+
echo "::set-output name=branch::"
48+
49+
- name: Create Pull Request 🚀
50+
if: steps.check_changes.outputs.changes_detected == 'true'
51+
uses: peter-evans/create-pull-request@v4
52+
with:
53+
token: ${{ secrets.GITHUB_TOKEN }}
54+
branch: ${{ steps.check_changes.outputs.branch }}
55+
title: "🤖Automated update"
56+
body: "This PR contains automated updates from running `npm run update`"
57+
labels: ["automated update"]
58+

0 commit comments

Comments
 (0)