Skip to content
This repository was archived by the owner on Dec 25, 2025. It is now read-only.

Commit 16b1078

Browse files
committed
create the pr in action
1 parent 74be8ac commit 16b1078

File tree

1 file changed

+45
-13
lines changed

1 file changed

+45
-13
lines changed

action.yml

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: 'Sync Template'
2-
description: 'Sync template into a project'
2+
description: 'Sync template into a project and optionally create a pull request'
33
author: 'Thomas Schmelzer'
44

55
inputs:
@@ -20,7 +20,7 @@ inputs:
2020
default: 'main'
2121
required: false
2222
token:
23-
description: 'Token to use for authentication'
23+
description: 'Token to use for authentication (PAT recommended)'
2424
default: ${{ github.token }}
2525
required: false
2626
include:
@@ -44,6 +44,10 @@ inputs:
4444
default: |
4545
.github/workflows/sync.yml
4646
required: false
47+
test-mode:
48+
description: 'If true, skip pushing changes and PR creation'
49+
default: 'false'
50+
required: false
4751

4852
runs:
4953
using: "composite"
@@ -77,32 +81,30 @@ runs:
7781
working-directory: .template-temp
7882
shell: bash
7983
run: |
80-
ls -all .
8184
echo "🔍 Processing exclude list..."
8285
while IFS= read -r item; do
8386
item="$(echo "$item" | xargs)"
8487
[ -z "$item" ] && continue
8588
echo " Excluding: $item"
8689
rm -rf "$item"
8790
done <<< "${{ inputs.exclude }}"
88-
ls -all .
8991
9092
- name: Copy template files into target repo
9193
shell: bash
9294
run: |
9395
echo "📂 Copying template files into repo..."
9496
cp -R .template-temp/. .
9597
rm -rf .template-temp
96-
ls -all .
98+
echo "✅ Files copied successfully."
99+
ls -al .
97100
tree .
98101
99-
- name: Commit and push changes
102+
- name: Commit changes
100103
shell: bash
101104
env:
102105
GITHUB_TOKEN: ${{ inputs.token }}
103-
106+
TEST_MODE: ${{ inputs.test-mode }}
104107
run: |
105-
git status
106108
git add -A
107109
if git diff --cached --quiet; then
108110
echo "✅ No changes to commit"
@@ -111,13 +113,43 @@ runs:
111113
git config user.name "github-actions[bot]"
112114
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
113115
git commit -m "${{ inputs.commit-message }}"
114-
115-
# Configure remote with token (critical!)
116-
git remote set-url origin "https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
117116
118-
# Skip push if in test mode
117+
- name: Push branch
118+
shell: bash
119+
env:
120+
GITHUB_TOKEN: ${{ inputs.token }}
121+
TEST_MODE: ${{ inputs.test-mode }}
122+
run: |
123+
git remote set-url origin "https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
119124
if [[ "${TEST_MODE}" == "true" ]]; then
120125
echo "🧪 Test mode enabled, skipping push"
121126
else
122-
git push origin "HEAD:${{ inputs.branch }}" --force
127+
echo "🚀 Pushing changes to branch '${{ inputs.branch }}'..."
128+
git push origin "HEAD:${{ inputs.branch }}" --force || echo "⚠️ Push failed. Check permissions."
123129
fi
130+
131+
- name: Check if branch exists
132+
id: branch-exists
133+
shell: bash
134+
run: |
135+
if git ls-remote --heads origin "${{ inputs.branch }}" | grep -q "${{ inputs.branch }}"; then
136+
echo "Branch exists"
137+
echo "exists=true" >> "$GITHUB_OUTPUT"
138+
else
139+
echo "Branch does not exist"
140+
echo "exists=false" >> "$GITHUB_OUTPUT"
141+
fi
142+
143+
- name: Create Pull Request (if branch exists)
144+
if: steps.branch-exists.outputs.exists == 'true' && inputs.test-mode != 'true'
145+
uses: peter-evans/create-pull-request@v7
146+
with:
147+
token: ${{ inputs.token }}
148+
branch: ${{ inputs.branch }}
149+
base: main
150+
title: "chore: sync template from ${{ inputs.template-repository }}@${{ inputs.template-branch }}"
151+
commit-message: "chore: sync template from ${{ inputs.template-repository }}@${{ inputs.template-branch }}"
152+
body: |
153+
This PR updates configuration files from `${{ inputs.template-repository }}@${{ inputs.template-branch }}`.
154+
delete-branch: true
155+
fail-on-no-changes: false

0 commit comments

Comments
 (0)