Skip to content

Commit 190ddf7

Browse files
authored
CICD: Setup the author in git config. (#26)
The patch is still generated by git config author.
1 parent b06c8a8 commit 190ddf7

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

.github/workflows/format-patch.sh

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ fi
1111

1212
PR_NUMBER="$1"
1313
PATCH_FILE="$2"
14+
TMP_BRANCH="$3"
1415
if [ -z "$PR_NUMBER" ]; then
1516
echo "Please provide a PR link or number. For example: https://github.com/ossrs/ffmpeg-webrtc/pull/20"
1617
exit 1
@@ -52,7 +53,7 @@ fi
5253

5354
git checkout workflows &&
5455
echo "Switched to workflows branch." &&
55-
git pull
56+
git pull &&
5657
echo "Pulled latest changes from workflows branch."
5758
if [[ $? -ne 0 ]]; then
5859
echo "Failed to switch to workflows branch or pull latest changes."
@@ -71,7 +72,9 @@ if [[ $? -ne 0 ]]; then
7172
exit 1
7273
fi
7374

74-
TMP_BRANCH=tmp-branch-for-patch-$PR_NUMBER &&
75+
if [[ -z "$TMP_BRANCH" ]]; then
76+
TMP_BRANCH="tmp-branch-for-patch-$PR_NUMBER"
77+
fi &&
7578
if git branch --list "$TMP_BRANCH" | grep -q "^..$TMP_BRANCH$"; then
7679
git branch -D "$TMP_BRANCH"
7780
fi &&
@@ -90,7 +93,7 @@ if [[ -z "$FIRST_AUTHOR_NAME" || -z "$FIRST_AUTHOR_EMAIL" ]]; then
9093
exit 1
9194
fi
9295

93-
COAUTHORS=$(git log workflows..HEAD --format='Co-authored-by: %an <%ae>' |grep -v "$FIRST_AUTHOR_NAME" | sort -u)
96+
COAUTHORS=$(git log workflows..HEAD --format='Co-authored-by: %an <%ae>' | sort -u)
9497
COAUTHOR_COUNT=$(echo "$COAUTHORS" | wc -l)
9598
if [[ "$COAUTHOR_COUNT" -gt 0 ]]; then
9699
echo "$COAUTHORS"
@@ -109,14 +112,27 @@ fi
109112
echo "Commit information:"
110113
echo "Author: $FIRST_AUTHOR_NAME <$FIRST_AUTHOR_EMAIL>"
111114
echo "==================================================================="
112-
echo -n -e "$COMMIT_MSG"
115+
echo -e "$COMMIT_MSG"
113116
echo "==================================================================="
114117
echo ""
115118

119+
if [[ $(git config --list --local |grep 'user.name' >/dev/null 2>&1 && echo yes) != "yes" ]]; then
120+
git config --local user.name "$FIRST_AUTHOR_NAME"
121+
fi &&
122+
if [[ $(git config --list --local |grep 'user.email' >/dev/null 2>&1 && echo yes) != "yes" ]]; then
123+
git config --local user.email "$FIRST_AUTHOR_EMAIL"
124+
fi &&
125+
git config --list &&
126+
echo "Set local git user configuration to: $FIRST_AUTHOR_NAME <$FIRST_AUTHOR_EMAIL>"
127+
if [[ $? -ne 0 ]]; then
128+
echo "Failed to set local git user configuration."
129+
exit 1
130+
fi
131+
116132
git rebase workflows &&
117133
git reset --soft workflows &&
118-
git commit --author "$FIRST_AUTHOR_NAME <$FIRST_AUTHOR_EMAIL>" -m "$(echo -n -e "$COMMIT_MSG")" &&
119-
echo "Squashed commits into a single commit." &&
134+
git commit --author "$FIRST_AUTHOR_NAME <$FIRST_AUTHOR_EMAIL>" -m "$(echo -e "$COMMIT_MSG")" &&
135+
echo "Squashed commits into a single commit."
120136
if [[ $? -ne 0 ]]; then
121137
echo "Failed to rebase or commit changes."
122138
exit 1

.github/workflows/test.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,11 +671,18 @@ jobs:
671671
672672
PR_NUMBER=${{ github.event.pull_request.number }}
673673
PATCH_FILENAME="whip-patch-$PR_NUMBER-$(date +%s)"
674+
TMP_BRANCH="tmp-branch-for-patch-$PR_NUMBER"
674675
echo "PR ID is ${{ github.event.pull_request.number }}"
675676
echo "Patch file is $PATCH_FILENAME.patch"
677+
echo "Temporary branch is $TMP_BRANCH"
676678
677679
bash .github/workflows/format-patch.sh $PR_NUMBER "$PATCH_FILENAME.patch"
678680
echo "patch_file=$PATCH_FILENAME" >> $GITHUB_OUTPUT
681+
echo "temporary_branch=$TMP_BRANCH" >> $GITHUB_OUTPUT
682+
- name: Show Branch Info
683+
run: git show ${{ steps.format_patch.outputs.temporary_branch }}
684+
- name: Show Patch File
685+
run: cat ${{ steps.format_patch.outputs.patch_file }}.patch
679686
- name: Upload all patch files
680687
uses: actions/upload-artifact@v4
681688
with:

0 commit comments

Comments
 (0)