From b03909c07a28d813f76ed49b87d78f244ddcf4e1 Mon Sep 17 00:00:00 2001 From: Powei Feng Date: Thu, 16 Oct 2025 21:05:52 -0700 Subject: [PATCH] github: add hash id to commit message action (#9334) We add the commit hash as output of get-commit-msg --- .github/actions/get-commit-msg/action.yml | 23 ++++++++++++++++------- .github/workflows/postsubmit.yml | 4 ++-- .github/workflows/presubmit.yml | 5 +---- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/.github/actions/get-commit-msg/action.yml b/.github/actions/get-commit-msg/action.yml index 6b160d4890..88e20ec84d 100644 --- a/.github/actions/get-commit-msg/action.yml +++ b/.github/actions/get-commit-msg/action.yml @@ -4,6 +4,8 @@ name: 'Get commit message' outputs: msg: value: ${{ steps.action_output.outputs.msg }} + hash: + value: ${{ steps.action_output.outputs.hash }} runs: using: "composite" steps: @@ -16,29 +18,36 @@ runs: AUTHOR_NAME="${{ github.event.head_commit.author.name }}" AUTHOR_EMAIL="${{ github.event.head_commit.author.email }}" TSTAMP="${{ github.event.head_commit.timestamp }}" - echo "commit ${{ github.event.head_commit.id }}" >> /tmp/commit_msg.txt + HASH="${{ github.event.head_commit.id }}" + echo "commit $HASH" >> /tmp/commit_msg.txt echo "Author: ${AUTHOR_NAME}<${AUTHOR_EMAIL}>" >> /tmp/commit_msg.txt echo "Date: ${TSTAMP}" >> /tmp/commit_msg.txt echo "" >> /tmp/commit_msg.txt echo "$COMMIT_MESSAGE" >> /tmp/commit_msg.txt + echo "$HASH" > /tmp/commit_hash.txt - name: Find commit message (PR) shell: bash id: checkout_code if: github.event_name == 'pull_request' run: | - echo "hash=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT" - git checkout ${{ github.event.pull_request.head.sha }} - echo "$(git log -1 --no-merges)" >> /tmp/commit_msg.txt + BEFORE_HASH=$(git rev-parse HEAD) + echo "hash=$BEFORE_HASH" >> "$GITHUB_OUTPUT" + # Next we will checkout the actual head (not the merge commits) of the PR + AFTER_HASH="${{ github.event.pull_request.head.sha }}" + git checkout $AFTER_HASH + COMMIT_MESSAGE=$(git log -1 --no-merges) + echo "$COMMIT_MESSAGE" > /tmp/commit_msg.txt + echo "$AFTER_HASH" > /tmp/commit_hash.txt - shell: bash id: action_output run: | + # Get the commit message DELIMITER="EOF_FILE_CONTENT_$(date +%s)" # Using timestamp to make it more unique echo "msg<<$DELIMITER" >> "$GITHUB_OUTPUT" cat /tmp/commit_msg.txt >> "$GITHUB_OUTPUT" echo "$DELIMITER" >> "$GITHUB_OUTPUT" - echo "----- got commit message ---" - cat /tmp/commit_msg.txt - echo "----------------------------" + # Get the commit hash + echo "hash=$(cat /tmp/commit_hash.txt)" >> "$GITHUB_OUTPUT" - name: Cleanup Find commit message (PR) shell: bash if: github.event_name == 'pull_request' diff --git a/.github/workflows/postsubmit.yml b/.github/workflows/postsubmit.yml index 9b1f02aa14..e3e4c36d89 100644 --- a/.github/workflows/postsubmit.yml +++ b/.github/workflows/postsubmit.yml @@ -23,7 +23,7 @@ jobs: GH_TOKEN: ${{ secrets.FILAMENTBOT_TOKEN }} run: | GOLDEN_BRANCH=$(echo "${{ steps.get_commit_msg.outputs.msg }}" | python3 test/renderdiff/src/commit_msg.py) - COMMIT_HASH=$(echo "${{ steps.get_commit_msg.outputs.msg }}" | head -n 1 | sed "s/commit //g") + COMMIT_HASH="${{ steps.get_commit_msg.outputs.hash }}" if [[ "${GOLDEN_BRANCH}" != "main" ]]; then git config --global user.email "filament.bot@gmail.com" git config --global user.name "Filament Bot" @@ -51,7 +51,7 @@ jobs: GH_TOKEN: ${{ secrets.FILAMENTBOT_TOKEN }} run: | bash docs_src/build/install_mdbook.sh && source ~/.bashrc - COMMIT_HASH=$(echo "${{ steps.get_commit_msg.outputs.msg }}" | head -n 1 | sed "s/commit //g") + COMMIT_HASH="${{ steps.get_commit_msg.outputs.hash }}" git config --global user.email "filament.bot@gmail.com" git config --global user.name "Filament Bot" git config --global credential.helper cache diff --git a/.github/workflows/presubmit.yml b/.github/workflows/presubmit.yml index bb78d8e0d8..79a29fcbaf 100644 --- a/.github/workflows/presubmit.yml +++ b/.github/workflows/presubmit.yml @@ -107,11 +107,8 @@ jobs: - id: get_commit_msg uses: ./.github/actions/get-commit-msg - name: Check for manual edits to /docs - env: - COMMIT_MESSAGE: ${{ steps.get_commit_msg.outputs.msg }} run: | - COMMIT_ID=$(echo "${COMMIT_MESSAGE}" | head -n 1 | sed "s/commit //g") - bash docs_src/build/presubmit_check.sh ${COMMIT_ID} + bash docs_src/build/presubmit_check.sh ${{ steps.get_commit_msg.outputs.hash }} test-renderdiff: name: test-renderdiff