Skip to content

Commit c4a0345

Browse files
committed
fix: action
1 parent a50590e commit c4a0345

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

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

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

0 commit comments

Comments
 (0)