Skip to content

Commit 4aa17ba

Browse files
authored
CICD: Ignore files in .github for patch (#48)
All files in the .github directory pertain to CI/CD and should be ignored; they should not be included in the patch.
1 parent 86490ff commit 4aa17ba

File tree

5 files changed

+200
-167
lines changed

5 files changed

+200
-167
lines changed
File renamed without changes.

.github/scripts/format-patch.sh

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
#!/bin/bash
2+
3+
LOGPREFIX=">>"
4+
5+
if [[ $(jq --version 1>/dev/null 2>&1 && echo yes) != "yes" ]]; then
6+
echo "${LOGPREFIX} Tool jq is not installed. Please install it to parse JSON data. For example:"
7+
echo "${LOGPREFIX} apt install jq"
8+
echo "${LOGPREFIX} brew install jq"
9+
echo "${LOGPREFIX} yum install jq"
10+
echo "${LOGPREFIX} See https://github.com/jqlang/jq"
11+
exit 1
12+
fi
13+
14+
PR_NUMBER="$1"
15+
PATCH_FILE="$2"
16+
TMP_BRANCH="$3"
17+
if [ -z "$PR_NUMBER" ]; then
18+
echo "${LOGPREFIX} Please provide a PR link or number. For example: https://github.com/ossrs/ffmpeg-webrtc/pull/20"
19+
exit 1
20+
fi
21+
22+
if [[ "$1" =~ ^https://github.com/ossrs/ffmpeg-webrtc/pull/([0-9]+)$ ]]; then
23+
PR_NUMBER="${BASH_REMATCH[1]}"
24+
elif [[ "$1" =~ ^[0-9]+$ ]]; then
25+
PR_NUMBER="$1"
26+
else
27+
echo "${LOGPREFIX} Invalid input format. Please provide a PR link or number. For example: https://github.com/ossrs/ffmpeg-webrtc/pull/20"
28+
exit 1
29+
fi
30+
31+
PR_URL="https://github.com/ossrs/ffmpeg-webrtc/pull/$PR_NUMBER"
32+
echo "${LOGPREFIX} Fetching PR #$PR_NUMBER from $PR_URL"
33+
34+
PR_DATA=$(curl -s "https://api.github.com/repos/ossrs/ffmpeg-webrtc/pulls/$PR_NUMBER")
35+
REPO_NAME=$(printf '%s' "$PR_DATA" | jq -r '.head.repo.full_name')
36+
BRANCH_NAME=$(printf '%s' "$PR_DATA" | jq -r '.head.ref')
37+
echo "${LOGPREFIX} Repository: $REPO_NAME, Branch: $BRANCH_NAME"
38+
if [[ -z "$REPO_NAME" || -z "$BRANCH_NAME" ]]; then
39+
echo "${LOGPREFIX} Error: REPO_NAME or BRANCH_NAME is empty!"
40+
exit 1
41+
fi
42+
43+
PR_TITLE=$(printf '%s' "$PR_DATA" | jq -r '.title')
44+
PR_DESCRIPTION=$(printf '%s' "$PR_DATA" | jq -r '.body // ""')
45+
echo "${LOGPREFIX} PR information:"
46+
echo "${LOGPREFIX} ==================================================================="
47+
echo "${LOGPREFIX} $PR_TITLE"
48+
echo "${LOGPREFIX} $PR_DESCRIPTION"
49+
echo "${LOGPREFIX} ==================================================================="
50+
echo "${LOGPREFIX} "
51+
if [[ -z "$PR_TITLE" ]]; then
52+
echo "${LOGPREFIX} Error: PR title is empty!"
53+
exit 1
54+
fi
55+
56+
git checkout workflows &&
57+
echo "${LOGPREFIX} Switched to workflows branch." &&
58+
git pull &&
59+
echo "${LOGPREFIX} Pulled latest changes from workflows branch."
60+
if [[ $? -ne 0 ]]; then
61+
echo "${LOGPREFIX} Failed to switch to workflows branch or pull latest changes."
62+
exit 1
63+
fi
64+
65+
REMOTE_NAME=patch-tmp &&
66+
if git remote | grep -q "^$REMOTE_NAME$"; then
67+
git remote rm "$REMOTE_NAME"
68+
fi &&
69+
git remote add $REMOTE_NAME https://github.com/${REPO_NAME}.git &&
70+
git fetch $REMOTE_NAME $BRANCH_NAME &&
71+
echo "${LOGPREFIX} Fetch remote $REMOTE_NAME at $(git remote get-url $REMOTE_NAME)"
72+
if [[ $? -ne 0 ]]; then
73+
echo "${LOGPREFIX} Failed to fetch remote branch $BRANCH_NAME from $REMOTE_NAME."
74+
exit 1
75+
fi
76+
77+
if [[ -z "$TMP_BRANCH" ]]; then
78+
TMP_BRANCH="tmp-branch-for-patch-$PR_NUMBER"
79+
fi &&
80+
if git branch --list "$TMP_BRANCH" | grep -q "^..$TMP_BRANCH$"; then
81+
git branch -D "$TMP_BRANCH"
82+
fi &&
83+
git checkout -b $TMP_BRANCH $REMOTE_NAME/$BRANCH_NAME &&
84+
echo "${LOGPREFIX} Checkout branch $TMP_BRANCH from $REMOTE_NAME/$BRANCH_NAME"
85+
if [[ $? -ne 0 ]]; then
86+
echo "${LOGPREFIX} Failed to checkout branch $TMP_BRANCH from $REMOTE_NAME/$BRANCH_NAME."
87+
exit 1
88+
fi
89+
90+
FIRST_AUTHOR_NAME=$(git log workflows..HEAD --reverse --format='%an' | head -n1)
91+
FIRST_AUTHOR_EMAIL=$(git log workflows..HEAD --reverse --format='%ae' | head -n1)
92+
echo "${LOGPREFIX} Author: $FIRST_AUTHOR_NAME <$FIRST_AUTHOR_EMAIL>"
93+
if [[ -z "$FIRST_AUTHOR_NAME" || -z "$FIRST_AUTHOR_EMAIL" ]]; then
94+
echo "${LOGPREFIX} Error: Unable to determine the first author of the PR."
95+
exit 1
96+
fi
97+
98+
COAUTHORS=$(git log workflows..HEAD --format='Co-authored-by: %an <%ae>' |grep -v "$FIRST_AUTHOR_NAME" | sort -u)
99+
COAUTHOR_COUNT=$(echo "$COAUTHORS" | wc -l)
100+
if [[ "$COAUTHOR_COUNT" -gt 0 ]]; then
101+
echo "${LOGPREFIX} $COAUTHORS"
102+
fi
103+
104+
COMMIT_MSG="$PR_TITLE"
105+
if [[ -n "$PR_DESCRIPTION" ]]; then
106+
COMMIT_MSG="$COMMIT_MSG\n\n$PR_DESCRIPTION"
107+
fi
108+
109+
if [[ "$COAUTHOR_COUNT" -gt 0 ]]; then
110+
COMMIT_MSG="$COMMIT_MSG\n"
111+
COMMIT_MSG="$COMMIT_MSG\n$COAUTHORS"
112+
fi
113+
114+
echo "${LOGPREFIX} Commit information:"
115+
echo "${LOGPREFIX} Author: $FIRST_AUTHOR_NAME <$FIRST_AUTHOR_EMAIL>"
116+
echo "${LOGPREFIX} ==================================================================="
117+
echo -e "$COMMIT_MSG"
118+
echo "${LOGPREFIX} ==================================================================="
119+
echo "${LOGPREFIX} "
120+
121+
if [[ $(git config --list --local |grep 'user.name' >/dev/null 2>&1 && echo yes) != "yes" ]]; then
122+
git config --local user.name "$FIRST_AUTHOR_NAME"
123+
fi &&
124+
if [[ $(git config --list --local |grep 'user.email' >/dev/null 2>&1 && echo yes) != "yes" ]]; then
125+
git config --local user.email "$FIRST_AUTHOR_EMAIL"
126+
fi &&
127+
git config --list &&
128+
echo "${LOGPREFIX} Set local git user configuration to: $FIRST_AUTHOR_NAME <$FIRST_AUTHOR_EMAIL>"
129+
if [[ $? -ne 0 ]]; then
130+
echo "${LOGPREFIX} Failed to set local git user configuration."
131+
exit 1
132+
fi
133+
134+
git rebase workflows &&
135+
git reset --soft workflows &&
136+
echo "${LOGPREFIX} Rebased onto workflows branch and reset to soft."
137+
if [[ $? -ne 0 ]]; then
138+
echo "${LOGPREFIX} Failed to rebase or reset changes."
139+
exit 1
140+
fi
141+
142+
git status &&
143+
git restore --staged .github &&
144+
git restore .github &&
145+
git status &&
146+
echo "${LOGPREFIX} Restored .github directory to the state of workflows branch."
147+
if [[ $? -ne 0 ]]; then
148+
echo "${LOGPREFIX} Failed to restore .github directory."
149+
exit 1
150+
fi
151+
152+
if [[ $(git status | grep 'nothing to commit, working tree clean' >/dev/null 2>&1 && echo yes) == "yes" ]]; then
153+
echo "${LOGPREFIX} No changes to commit. Exiting."
154+
git checkout workflows
155+
exit 0
156+
fi
157+
158+
git commit --author "$FIRST_AUTHOR_NAME <$FIRST_AUTHOR_EMAIL>" -m "$(echo -e "$COMMIT_MSG")" &&
159+
echo "${LOGPREFIX} Squashed commits into a single commit."
160+
if [[ $? -ne 0 ]]; then
161+
echo "${LOGPREFIX} Failed to rebase or commit changes."
162+
exit 1
163+
fi
164+
165+
git branch -vv &&
166+
git log -1 --pretty=format:"%an <%ae> %h %s"
167+
if [[ $? -ne 0 ]]; then
168+
echo "${LOGPREFIX} Failed to display branch information or last commit."
169+
exit 1
170+
fi
171+
172+
if [[ -z "$PATCH_FILE" ]]; then
173+
PATCH_FILE="whip-patch-$PR_NUMBER-$(date +%s).patch"
174+
fi &&
175+
rm -f $PATCH_FILE &&
176+
git format-patch --add-header "X-Unsent: 1" --to [email protected] -1 --stdout > $PATCH_FILE &&
177+
echo "${LOGPREFIX} Created patch file: $PATCH_FILE"
178+
if [[ $? -ne 0 ]]; then
179+
echo "${LOGPREFIX} Failed to create patch file."
180+
exit 1
181+
fi
182+
183+
git checkout workflows
184+
#git br -D $TMP_BRANCH
185+
#echo "${LOGPREFIX} Removed temporary branch $TMP_BRANCH."
186+
187+
echo "${LOGPREFIX} "
188+
echo "${LOGPREFIX} Patch file created: $PATCH_FILE"
189+
echo "${LOGPREFIX} "

.github/workflows/fate-cache.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
- name: Build FFmpeg Fate Cache
2020
run: |
2121
set -euxo pipefail
22-
docker build -t ossrs/srs:ffmpeg-fate -f .github/workflows/Dockerfile .
22+
docker build -t ossrs/srs:ffmpeg-fate -f .github/docker/Dockerfile .
2323
- name: Push FFmpeg Fate Cache
2424
run: |
2525
set -euxo pipefail

.github/workflows/format-patch.sh

Lines changed: 0 additions & 165 deletions
This file was deleted.

.github/workflows/test.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,14 +676,23 @@ jobs:
676676
echo "Patch file is $PATCH_FILENAME.patch"
677677
echo "Temporary branch is $TMP_BRANCH"
678678
679-
bash .github/workflows/format-patch.sh $PR_NUMBER "$PATCH_FILENAME.patch"
679+
bash .github/scripts/format-patch.sh $PR_NUMBER "$PATCH_FILENAME.patch"
680680
echo "patch_file=$PATCH_FILENAME" >> $GITHUB_OUTPUT
681681
echo "temporary_branch=$TMP_BRANCH" >> $GITHUB_OUTPUT
682+
683+
if [[ -f "$PATCH_FILENAME.patch" ]]; then
684+
echo "has_patch=true" >> $GITHUB_OUTPUT
685+
else
686+
echo "has_patch=false" >> $GITHUB_OUTPUT
687+
fi
682688
- name: Show Branch Info
689+
if: ${{ steps.format_patch.outputs.has_patch == 'true' }}
683690
run: git show ${{ steps.format_patch.outputs.temporary_branch }}
684691
- name: Show Patch File
692+
if: ${{ steps.format_patch.outputs.has_patch == 'true' }}
685693
run: cat ${{ steps.format_patch.outputs.patch_file }}.patch
686694
- name: Upload all patch files
695+
if: ${{ steps.format_patch.outputs.has_patch == 'true' }}
687696
uses: actions/upload-artifact@v4
688697
with:
689698
name: ${{ steps.format_patch.outputs.patch_file }}

0 commit comments

Comments
 (0)