Skip to content

fix: action

fix: action #10

Workflow file for this run

name: Auto PR to infos folder
on:
push:
branches:
- main
jobs:
create-pr:
runs-on: ubuntu-latest
steps:
- name: Checkout source repository
uses: actions/checkout@v4
with:
path: source-repo
- name: Get filename from info.json
id: get-filename
run: |
cd source-repo
BASE_NAME=$(jq -r '.name' info.json)
FILENAME="${BASE_NAME}.json"
echo "filename=$FILENAME" >> $GITHUB_OUTPUT
echo "branch_name=update-file-$(date +%s)" >> $GITHUB_OUTPUT
cp info.json ../target.json
- name: Checkout target repository
uses: actions/checkout@v4
with:
repository: ExpTechTW/TREM-Plugins
token: ${{ secrets.PAT_TOKEN }}
path: target-repo
- name: Copy and commit file
run: |
mkdir -p target-repo/infos
mv target.json "target-repo/infos/${{ steps.get-filename.outputs.filename }}"
cd target-repo
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
git checkout -b ${{ steps.get-filename.outputs.branch_name }}
git add infos
git diff --exit-code
if [ $? -ne 0 ]; then
git commit -m "Update ${{ steps.get-filename.outputs.filename }}"
git push origin ${{ steps.get-filename.outputs.branch_name }}
else
echo "No changes to commit."
fi
- name: Create Pull Request
env:
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }}
run: |
REPO_OWNER="ExpTechTW"
REPO_NAME="TREM-Plugins"
HEAD_REF="${{ steps.get-filename.outputs.branch_name }}"
BASE_REF="main"
curl -X POST \
-H "Authorization: token ${{ secrets.PAT_TOKEN }}" \
-H "Content-Type: application/json" \
-d "{\"title\":\"Update ${{ steps.get-filename.outputs.filename }}\",\"head\":\"$HEAD_REF\",\"base\":\"$BASE_REF\"}" \
https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/pulls