Skip to content

Commit 2ff59b9

Browse files
authored
Create auto-pr-info.yml
1 parent 2302a75 commit 2ff59b9

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

.github/workflows/auto-pr-info.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Auto PR to infos folder
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- "info.json"
9+
10+
jobs:
11+
create-pr:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout source repository
15+
uses: actions/checkout@v4
16+
with:
17+
path: source-repo
18+
19+
- name: Get filename from info.json
20+
id: get-filename
21+
run: |
22+
cd source-repo
23+
BASE_NAME=$(jq -r '.name' info.json)
24+
FILENAME="${BASE_NAME}.json"
25+
echo "filename=$FILENAME" >> $GITHUB_OUTPUT
26+
echo "branch_name=update-file-$(date +%s)" >> $GITHUB_OUTPUT
27+
cp info.json ../target.json
28+
29+
- name: Checkout target repository
30+
uses: actions/checkout@v4
31+
with:
32+
repository: ExpTechTW/TREM-Plugins
33+
token: ${{ secrets.PAT_TOKEN }}
34+
path: target-repo
35+
36+
- name: Copy and commit file
37+
run: |
38+
mkdir -p target-repo/infos
39+
mv target.json "target-repo/infos/${{ steps.get-filename.outputs.filename }}"
40+
cd target-repo
41+
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
42+
git config --global user.name "github-actions[bot]"
43+
BRANCH_NAME="${{ steps.get-filename.outputs.branch_name }}"
44+
git checkout -b $BRANCH_NAME
45+
git add infos
46+
if ! git diff --cached --quiet; then
47+
git commit -m "Update ${{ steps.get-filename.outputs.filename }}"
48+
git push origin $BRANCH_NAME
49+
else
50+
echo "No changes to commit."
51+
exit 0
52+
fi
53+
54+
- name: Create Pull Request
55+
if: success()
56+
env:
57+
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }}
58+
run: |
59+
pr_url=$(gh pr create \
60+
--repo ExpTechTW/TREM-Plugins \
61+
--base main \
62+
--head ${{ steps.get-filename.outputs.branch_name }} \
63+
--title "Update ${{ steps.get-filename.outputs.filename }}" \
64+
--body "Automated update from plugin repository" \
65+
--label "auto-merge")
66+
echo "Created PR: $pr_url"

0 commit comments

Comments
 (0)