99 branches :
1010 - main
1111 workflow_dispatch :
12+ inputs :
13+ pr_number :
14+ description : ' PR number to reference (leave empty for sort-only)'
15+ required : false
16+ type : string
17+ contributor :
18+ description : ' GitHub username to add as contributor (leave empty to skip)'
19+ required : false
20+ type : string
1221
1322jobs :
14- process-merged-pr :
15- if : github.event.pull_request.merged == true
23+ process-changes :
1624 runs-on : ubuntu-latest
25+ # Only check for merged PR when triggered by a pull_request event
26+ if : github.event_name != 'pull_request' || github.event.pull_request.merged == true
1727 steps :
1828 - name : Checkout repository
1929 uses : actions/checkout@v4
30+ with :
31+ token : ${{ secrets.GITHUB_TOKEN }}
2032
2133 - name : Setup Pixi
2234 uses :
prefix-dev/[email protected] 2335
36+ - name : Set variables
37+ id : vars
38+ run : |
39+ if [[ "${{ github.event_name }}" == "pull_request" ]]; then
40+ # For PR-triggered workflow
41+ echo "pr_number=${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT
42+ echo "contributor=${{ github.event.pull_request.user.login }}" >> $GITHUB_OUTPUT
43+ echo "branch_name=automated-updates-${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT
44+ else
45+ # For manually triggered workflow
46+ PR_REF="${{ github.event.inputs.pr_number }}"
47+ CONTRIBUTOR="${{ github.event.inputs.contributor }}"
48+
49+ if [[ -n "$PR_REF" ]]; then
50+ echo "pr_number=$PR_REF" >> $GITHUB_OUTPUT
51+ echo "branch_name=automated-updates-$PR_REF" >> $GITHUB_OUTPUT
52+ else
53+ # Generate a timestamp if no PR number provided
54+ TIMESTAMP=$(date +%Y%m%d%H%M%S)
55+ echo "pr_number=manual-$TIMESTAMP" >> $GITHUB_OUTPUT
56+ echo "branch_name=automated-updates-$TIMESTAMP" >> $GITHUB_OUTPUT
57+ fi
58+
59+ if [[ -n "$CONTRIBUTOR" ]]; then
60+ echo "contributor=$CONTRIBUTOR" >> $GITHUB_OUTPUT
61+ else
62+ echo "contributor=" >> $GITHUB_OUTPUT
63+ fi
64+ fi
65+
2466 - name : Create changes
2567 id : changes
2668 run : |
2769 # Create a new branch
28- git checkout -b automated-updates- ${{ github.event.pull_request.number }}
70+ git checkout -b ${{ steps.vars.outputs.branch_name }}
2971
30- # Run your commands
72+ # Run sort command
3173 pixi run sort
32-
33- PR_AUTHOR="${{ github.event.pull_request.user.login }}"
34- pixi run install
35- pixi run add $PR_AUTHOR conference
74+
75+ # Add contributor if specified
76+ if [[ -n "${{ steps.vars.outputs.contributor }}" ]]; then
77+ pixi run install
78+ pixi run add ${{ steps.vars.outputs.contributor }} conference
79+ CONTRIBUTOR_MSG="* Add ${{ steps.vars.outputs.contributor }} as contributor"
80+ else
81+ CONTRIBUTOR_MSG=""
82+ fi
3683
3784 # Check if there are changes
3885 if ! git diff --quiet; then
@@ -42,10 +89,18 @@ jobs:
4289 git config --global user.name 'github-actions[bot]'
4390 git config --global user.email 'github-actions[bot]@users.noreply.github.com'
4491 git add _data/* .all-contributorsrc README.md CONTRIBUTING.md
45- git commit -m "chore: post-merge updates
46-
47- * Sort conferences
48- * Add $PR_AUTHOR as contributor"
92+
93+ # Create commit message
94+ COMMIT_MSG="chore: updates"
95+ COMMIT_MSG="$COMMIT_MSG\n\n* Sort conferences"
96+ if [[ -n "$CONTRIBUTOR_MSG" ]]; then
97+ COMMIT_MSG="$COMMIT_MSG\n$CONTRIBUTOR_MSG"
98+ fi
99+
100+ git commit -m "$COMMIT_MSG"
101+
102+ # Push the branch to the remote repository
103+ git push -u origin ${{ steps.vars.outputs.branch_name }}
49104 else
50105 echo "has_changes=false" >> $GITHUB_OUTPUT
51106 fi
@@ -54,15 +109,15 @@ jobs:
54109 if : steps.changes.outputs.has_changes == 'true'
55110 uses : peter-evans/create-pull-request@v7
56111 with :
57- title : ' Automated updates from PR #${{ github.event.pull_request.number }}'
112+ title : ' Automated updates ${{ steps.vars.outputs.pr_number != '' && format( '' from PR #{0} '' , steps.vars.outputs.pr_number) || '''' }}'
58113 body : |
59- This PR was automatically created after merging # ${{ github.event.pull_request.number }}
114+ This PR was ${{ github.event_name == 'pull_request' && ' automatically created after merging' || 'manually triggered' }} ${{ steps.vars.outputs.pr_number != '' && format('#{0}', steps.vars.outputs.pr_number) || '' }}
60115
61116 Changes include:
62117 - Sorted conferences
63- - Added @ ${{ github.event.pull_request.user.login }} as contributor
118+ ${{ steps.vars.outputs.contributor != '' && format('- Added @{0} as contributor', steps.vars.outputs.contributor) || '' }}
64119
65120 Please review and merge these automated updates.
66- branch : automated-updates- ${{ github.event.pull_request.number }}
121+ branch : ${{ steps.vars.outputs.branch_name }}
67122 base : main
68123 delete-branch : true
0 commit comments