From bb333ee6f10f3876f4cb3ffae22bed945435ac8f Mon Sep 17 00:00:00 2001 From: winlin Date: Sun, 8 Jun 2025 08:43:48 -0400 Subject: [PATCH] Update --- .github/workflows/format-patch.sh | 93 ++++++++++++++++++++----------- .github/workflows/test.yml | 53 ++++++++++++++++++ 2 files changed, 114 insertions(+), 32 deletions(-) diff --git a/.github/workflows/format-patch.sh b/.github/workflows/format-patch.sh index b7fe8c560f8aa..ef67cd50c4cc8 100755 --- a/.github/workflows/format-patch.sh +++ b/.github/workflows/format-patch.sh @@ -9,7 +9,9 @@ if [[ $(jq --version 1>/dev/null 2>&1 && echo yes) != "yes" ]]; then exit 1 fi -if [ -z "$1" ]; then +PR_NUMBER="$1" +PATCH_FILE="$2" +if [ -z "$PR_NUMBER" ]; then echo "Please provide a PR link or number. For example: https://github.com/ossrs/ffmpeg-webrtc/pull/20" exit 1 fi @@ -29,65 +31,77 @@ echo "Fetching PR #$PR_NUMBER from $PR_URL" PR_DATA=$(curl -s "https://api.github.com/repos/ossrs/ffmpeg-webrtc/pulls/$PR_NUMBER") REPO_NAME=$(printf '%s' "$PR_DATA" | jq -r '.head.repo.full_name') BRANCH_NAME=$(printf '%s' "$PR_DATA" | jq -r '.head.ref') +echo "Repository: $REPO_NAME, Branch: $BRANCH_NAME" if [[ -z "$REPO_NAME" || -z "$BRANCH_NAME" ]]; then echo "Error: REPO_NAME or BRANCH_NAME is empty!" exit 1 fi -echo "Repository: $REPO_NAME, Branch: $BRANCH_NAME" PR_TITLE=$(printf '%s' "$PR_DATA" | jq -r '.title') PR_DESCRIPTION=$(printf '%s' "$PR_DATA" | jq -r '.body // ""') -if [[ -z "$PR_TITLE" ]]; then - echo "Error: PR title is empty!" - exit 1 -fi - echo "PR information:" echo "===================================================================" echo "$PR_TITLE" echo "$PR_DESCRIPTION" echo "===================================================================" echo "" +if [[ -z "$PR_TITLE" ]]; then + echo "Error: PR title is empty!" + exit 1 +fi -set -euxo pipefail - -git checkout workflows -echo "Switched to workflows branch." - +git checkout workflows && +echo "Switched to workflows branch." && git pull echo "Pulled latest changes from workflows branch." +if [[ $? -ne 0 ]]; then + echo "Failed to switch to workflows branch or pull latest changes." + exit 1 +fi -REMOTE_NAME=patch-tmp +REMOTE_NAME=patch-tmp && if git remote | grep -q "^$REMOTE_NAME$"; then git remote rm "$REMOTE_NAME" -fi -git remote add $REMOTE_NAME https://github.com/${REPO_NAME}.git -git fetch $REMOTE_NAME $BRANCH_NAME +fi && +git remote add $REMOTE_NAME https://github.com/${REPO_NAME}.git && +git fetch $REMOTE_NAME $BRANCH_NAME && echo "Fetch remote $REMOTE_NAME at $(git remote get-url $REMOTE_NAME)" +if [[ $? -ne 0 ]]; then + echo "Failed to fetch remote branch $BRANCH_NAME from $REMOTE_NAME." + exit 1 +fi -TMP_BRANCH=tmp-branch-for-patch-$PR_NUMBER +TMP_BRANCH=tmp-branch-for-patch-$PR_NUMBER && if git branch --list "$TMP_BRANCH" | grep -q "^..$TMP_BRANCH$"; then git branch -D "$TMP_BRANCH" -fi -git checkout -b $TMP_BRANCH $REMOTE_NAME/$BRANCH_NAME +fi && +git checkout -b $TMP_BRANCH $REMOTE_NAME/$BRANCH_NAME && echo "Checkout branch $TMP_BRANCH from $REMOTE_NAME/$BRANCH_NAME" +if [[ $? -ne 0 ]]; then + echo "Failed to checkout branch $TMP_BRANCH from $REMOTE_NAME/$BRANCH_NAME." + exit 1 +fi FIRST_AUTHOR_NAME=$(git log workflows..HEAD --reverse --format='%an' | head -n1) FIRST_AUTHOR_EMAIL=$(git log workflows..HEAD --reverse --format='%ae' | head -n1) echo "Author: $FIRST_AUTHOR_NAME <$FIRST_AUTHOR_EMAIL>" +if [[ -z "$FIRST_AUTHOR_NAME" || -z "$FIRST_AUTHOR_EMAIL" ]]; then + echo "Error: Unable to determine the first author of the PR." + exit 1 +fi COAUTHORS=$(git log workflows..HEAD --format='Co-authored-by: %an <%ae>' |grep -v "$FIRST_AUTHOR_NAME" | sort -u) COAUTHOR_COUNT=$(echo "$COAUTHORS" | wc -l) -if [ "$COAUTHOR_COUNT" -gt 0 ]; then +if [[ "$COAUTHOR_COUNT" -gt 0 ]]; then echo "$COAUTHORS" fi COMMIT_MSG="$PR_TITLE" -if [ -n "$PR_DESCRIPTION" ]; then +if [[ -n "$PR_DESCRIPTION" ]]; then COMMIT_MSG="$COMMIT_MSG\n\n$PR_DESCRIPTION" fi -if [ "$COAUTHOR_COUNT" -gt 0 ]; then +if [[ "$COAUTHOR_COUNT" -gt 0 ]]; then COMMIT_MSG="$COMMIT_MSG\n" COMMIT_MSG="$COMMIT_MSG\n$COAUTHORS" fi @@ -95,26 +109,41 @@ fi echo "Commit information:" echo "Author: $FIRST_AUTHOR_NAME <$FIRST_AUTHOR_EMAIL>" echo "===================================================================" -echo -e "$COMMIT_MSG" +echo -n -e "$COMMIT_MSG" echo "===================================================================" echo "" -git rebase workflows -git reset --soft workflows -git commit --author "$FIRST_AUTHOR_NAME <$FIRST_AUTHOR_EMAIL>" -m "$(echo -e "$COMMIT_MSG")" -echo "Squashed commits into a single commit." +git rebase workflows && +git reset --soft workflows && +git commit --author "$FIRST_AUTHOR_NAME <$FIRST_AUTHOR_EMAIL>" -m "$(echo -n -e "$COMMIT_MSG")" && +echo "Squashed commits into a single commit." && +if [[ $? -ne 0 ]]; then + echo "Failed to rebase or commit changes." + exit 1 +fi + +git branch -vv && git log -1 --pretty=format:"%an <%ae> %h %s" +if [[ $? -ne 0 ]]; then + echo "Failed to display branch information or last commit." + exit 1 +fi -PATCH_FILE="patch-$PR_NUMBER-$(date +%s).patch" -rm -f $PATCH_FILE -git format-patch -1 --stdout > $PATCH_FILE +if [[ -z "$PATCH_FILE" ]]; then + PATCH_FILE="whip-patch-$PR_NUMBER-$(date +%s).patch" +fi && +rm -f $PATCH_FILE && +git format-patch -1 --stdout > $PATCH_FILE && +echo "Created patch file: $PATCH_FILE" +if [[ $? -ne 0 ]]; then + echo "Failed to create patch file." + exit 1 +fi git checkout workflows #git br -D $TMP_BRANCH #echo "Removed temporary branch $TMP_BRANCH." -set +e +u +x +o pipefail - echo "" echo "Patch file created: $PATCH_FILE" echo "" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index cb604c11e9dee..1a3aefe3ab092 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -633,6 +633,58 @@ jobs: run: exit 1 runs-on: ubuntu-22.04 + generate-patch: + name: "Generate Patch" + if: ${{ github.event_name == 'pull_request' }} + steps: + # Checkout to workflows branch, make sure the base branch is available. + - name: Checkout repository with workflows branch + uses: actions/checkout@v4 + with: + ref: workflows + fetch-depth: 0 + - name: Try to checkout to workflows branch + run: | + set -euxo pipefail + git checkout workflows + git branch -vv + # Checkout to PR commit, use the lastest script. + - name: Checkout repository to PR commit + uses: actions/checkout@v4 + - name: Show Git Info + run: | + set -euxo pipefail + git branch -vv + echo "Repository: ${{ github.repository }}" + echo "Ref: ${{ github.ref }}" + echo "Event Name: ${{ github.event_name }}" + echo "Pull Request Number: ${{ github.event.pull_request.number }}" + - name: Install Dependencies + run: | + set -euxo pipefail + sudo apt-get update + sudo apt-get install -y jq + - name: Run Script + id: format_patch + run: | + set -euxo pipefail + + PR_NUMBER=${{ github.event.pull_request.number }} + PATCH_FILENAME="whip-patch-$PR_NUMBER-$(date +%s)" + echo "PR ID is ${{ github.event.pull_request.number }}" + echo "Patch file is $PATCH_FILENAME.patch" + + bash .github/workflows/format-patch.sh $PR_NUMBER "$PATCH_FILENAME.patch" + echo "patch_file=$PATCH_FILENAME" >> $GITHUB_OUTPUT + - name: Upload all patch files + uses: actions/upload-artifact@v4 + with: + name: ${{ steps.format_patch.outputs.patch_file }} + path: | + whip-*.patch + retention-days: 90 + runs-on: ubuntu-22.04 + test-done: needs: - fate @@ -643,6 +695,7 @@ jobs: - openssl-1-1-0h - openssl-3-0 - openssl-latest + - generate-patch steps: - run: echo 'All done' runs-on: ubuntu-22.04