Skip to content

Commit 170e346

Browse files
ci: use gh in pr-sort.yml
1 parent 46d8559 commit 170e346

File tree

1 file changed

+34
-30
lines changed

1 file changed

+34
-30
lines changed

.github/workflows/pr-sort.yml

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,12 @@ jobs:
6363
fi
6464
fi
6565
66-
- name: Create changes
66+
- name: Create branch and make changes
6767
id: changes
6868
run: |
6969
# Create a new branch
70-
git checkout -b ${{ steps.vars.outputs.branch_name }}
70+
BRANCH_NAME="${{ steps.vars.outputs.branch_name }}"
71+
git checkout -b $BRANCH_NAME
7172
7273
# Run sort command
7374
pixi run sort
@@ -76,48 +77,51 @@ jobs:
7677
if [[ -n "${{ steps.vars.outputs.contributor }}" ]]; then
7778
pixi run install
7879
pixi run add ${{ steps.vars.outputs.contributor }} conference
79-
CONTRIBUTOR_MSG="* Add ${{ steps.vars.outputs.contributor }} as contributor"
80-
else
81-
CONTRIBUTOR_MSG=""
8280
fi
8381
8482
# Check if there are changes
85-
if ! git diff --quiet; then
83+
git status
84+
if git diff --exit-code --quiet; then
85+
echo "No changes detected in working directory"
86+
echo "has_changes=false" >> $GITHUB_OUTPUT
87+
else
8688
echo "has_changes=true" >> $GITHUB_OUTPUT
87-
89+
8890
# Stage and commit changes
8991
git config --global user.name 'github-actions[bot]'
9092
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
91-
git add _data/* .all-contributorsrc README.md CONTRIBUTING.md
93+
git add _data/* .all-contributorsrc README.md CONTRIBUTING.md || true
9294
9395
# Create commit message
9496
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-
10097
git commit -m "$COMMIT_MSG"
10198
10299
# Push the branch to the remote repository
103-
git push -u origin ${{ steps.vars.outputs.branch_name }}
104-
else
105-
echo "has_changes=false" >> $GITHUB_OUTPUT
100+
git push -u origin $BRANCH_NAME
106101
fi
107102
108-
- name: Create Pull Request
103+
- name: Manual PR creation
109104
if: steps.changes.outputs.has_changes == 'true'
110-
uses: peter-evans/create-pull-request@v7
111-
with:
112-
title: 'Automated updates from PR #${{ github.event.pull_request.number }}'
113-
body: |
114-
This PR was ${{ github.event_name == 'pull_request' && 'automatically created after merging' || 'manually triggered' }} ${{ steps.vars.outputs.pr_number }}
115-
116-
Changes include:
117-
- Sorted conferences
118-
${{ steps.vars.outputs.contributor != '' && format('- Added @{0} as contributor', steps.vars.outputs.contributor) || '' }}
105+
env:
106+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
107+
BRANCH_NAME: ${{ steps.vars.outputs.branch_name }}
108+
run: |
109+
# Check if PR already exists
110+
PR_EXISTS=$(gh pr list --head $BRANCH_NAME --json number | jq 'length')
111+
112+
if [[ "$PR_EXISTS" == "0" ]]; then
113+
# Create a new PR
114+
gh pr create \
115+
--title "Automated updates" \
116+
--body "Automated workflow update
119117
120-
Please review and merge these automated updates.
121-
branch: ${{ steps.vars.outputs.branch_name }}
122-
base: main
123-
delete-branch: true
118+
Changes include:
119+
- Sorted conferences
120+
- Added contributor (if specified)
121+
122+
Please review and merge these automated updates." \
123+
--base main \
124+
--head $BRANCH_NAME
125+
else
126+
echo "Pull request from branch $BRANCH_NAME already exists."
127+
fi

0 commit comments

Comments
 (0)