-
Notifications
You must be signed in to change notification settings - Fork 5
66 lines (56 loc) · 1.76 KB
/
commit-changes.yml
File metadata and controls
66 lines (56 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
name: Commit Changes
on:
workflow_call:
inputs:
commit_message:
required: true
type: string
description: 'Commit message'
file_patterns:
required: true
type: string
description: 'File patterns to add (space-separated)'
secrets:
APP_ID:
required: true
description: 'GitHub App ID'
APP_PRIVATE_KEY:
required: true
description: 'GitHub App private key'
jobs:
commit:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Generate App Token
id: app-token
uses: actions/create-github-app-token@v2
with:
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
- name: Configure Git
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email '41898282+github-actions[bot]@users.noreply.github.com'
- name: Commit and push changes with rebase
run: |
# Stage changes
git add ${{ inputs.file_patterns }}
# Only commit if there are changes
if git diff --staged --quiet; then
echo "No changes to commit"
exit 0
fi
# Create commit
git commit -m "${{ inputs.commit_message }}"
# Get the current branch name
BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD)
# Fetch latest changes from remote
git fetch origin $BRANCH_NAME
# Rebase our changes on top of the latest changes from remote
git rebase origin/$BRANCH_NAME
# Push the changes
git push origin $BRANCH_NAME
env:
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}