Test base PR for #5110 (7e5d56fa9388782b32d3cf5bb18869bfd28afaf5) #8318
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Test | |
on: | |
push: | |
branches: [main] | |
pull_request: | |
branches: [main, '[0-9]+-[0-9]+-*'] | |
workflow_run: | |
workflows: ['Dependabot', 'Fork'] | |
branches-ignore: ['workflows/tests/*'] | |
types: | |
- completed | |
workflow_dispatch: | |
workflow_call: | |
jobs: | |
test: | |
name: Test | |
if: |- | |
${{ | |
(!startsWith(github.head_ref, 'workflows/tests/')) && | |
(github.event.pull_request.head.repo.full_name == github.repository || | |
github.event_name == 'workflow_run') | |
}} | |
runs-on: ubuntu-latest | |
permissions: write-all | |
env: | |
SHA: ${{ github.sha }} | |
PULL_REQUEST_NUMBER: ${{ github.event.pull_request.number || github.event.workflow_run.pull_requests[0].number }} | |
PULL_REQUEST_HEAD_REF: |- | |
${{ | |
(github.event.pull_request.head.repo.full_name == github.repository) | |
&& (github.event.pull_request.head.ref || github.event.workflow_run.head_branch) | |
|| (github.event.pull_request.head.sha || github.event.workflow_run.head_sha) | |
}} | |
RUN_ID: ${{ github.run_id }} | |
RUN_NUMBER: ${{ github.run_number }} | |
RUN_ATTEMPT: ${{ github.run_attempt }} | |
TEST_BASE_BRANCH_NAME: ${{ format('workflows/tests/base/id-{0}/run-{1}/attempt-{2}/sha-{3}', github.run_id, github.run_number, github.run_attempt, github.sha) }} | |
TEST_HEAD_BRANCH_NAME: ${{ format('workflows/tests/head/id-{0}/run-{1}/attempt-{2}/sha-{3}', github.run_id, github.run_number, github.run_attempt, github.sha) }} | |
steps: | |
- uses: actions/checkout@v4 | |
if: ${{ github.event_name != 'workflow_run' }} | |
with: | |
fetch-depth: 0 | |
- uses: actions/checkout@v4 | |
if: ${{ github.event_name == 'workflow_run' }} | |
with: | |
repository: ${{ github.event.workflow_run.head_repository.full_name }} | |
ref: ${{ github.event.workflow_run.head_branch }} | |
fetch-depth: 0 | |
- name: Replace the fork repo in git remote origin with the base repo | |
if: ${{ github.event_name == 'workflow_run' && github.event.workflow_run.head_repository.full_name != github.repository }} | |
env: | |
SERVER: ${{ github.server_url }} | |
REPO: ${{ github.repository }} | |
run: | | |
git remote set-url origin "$SERVER/$REPO" | |
- uses: CatChen/config-git-with-token-action@v1 | |
with: | |
github-token: ${{ secrets.CREATE_PULL_REQUEST_ACTION_TOKEN }} | |
- name: Git checkout PR head commit | |
id: git-checkout | |
run: | | |
echo "::notice::PR head ref is $PULL_REQUEST_HEAD_REF" | |
git checkout $PULL_REQUEST_HEAD_REF | |
- name: Git checkout test base branch | |
run: | | |
echo "::notice::Test base branch is $TEST_BASE_BRANCH_NAME" | |
git checkout -b "$TEST_BASE_BRANCH_NAME" | |
- name: Make test base commit | |
run: | | |
git commit --allow-empty -m "Test base commit for #$PULL_REQUEST_NUMBER ($SHA) by $RUN_NUMBER-$RUN_ATTEMPT" | |
echo "::notice::Test base commit is `git rev-parse --verify HEAD`" | |
- name: Git push test base branch | |
run: | | |
git push -f --set-upstream origin "$TEST_BASE_BRANCH_NAME" | |
echo "::notice::Remote test branch is origin/$TEST_BASE_BRANCH_NAME" | |
- name: Open base PR | |
id: open-base-pr | |
env: | |
GH_TOKEN: ${{ secrets.CREATE_PULL_REQUEST_ACTION_TOKEN }} | |
run: | | |
echo "::notice::Run number is $RUN_NUMBER" | |
echo "::notice::Run attempt is $RUN_ATTEMPT" | |
echo "::notice::Base PR number is $PULL_REQUEST_NUMBER" | |
gh pr create --base "main" --title "Test base PR for #$PULL_REQUEST_NUMBER ($SHA)" --body "Generated from #$PULL_REQUEST_NUMBER. | |
Run ID: [$RUN_ID]($(gh run view $RUN_ID --json 'url' --jq '.url')). Number: $RUN_NUMBER. Attempt: $RUN_ATTEMPT." | |
TEST_BASE_PR_NUMBER=`gh pr view | grep 'number:' | cut -f 2` | |
echo "test-base-pr-number=$TEST_BASE_PR_NUMBER" >> $GITHUB_OUTPUT | |
echo "::notice::Test base PR number is $TEST_BASE_PR_NUMBER" | |
- name: Git checkout test head branch | |
run: | | |
echo "::notice::Test head branch is $TEST_HEAD_BRANCH_NAME" | |
git checkout -b "$TEST_HEAD_BRANCH_NAME" | |
- name: Make test head commit | |
run: | | |
git commit --allow-empty -m "Test head commit for #$PULL_REQUEST_NUMBER ($SHA) by $RUN_NUMBER-$RUN_ATTEMPT" | |
echo "::notice::Test head commit is `git rev-parse --verify HEAD`" | |
- name: Git push test head branch | |
run: | | |
git push -f --set-upstream origin "$TEST_HEAD_BRANCH_NAME" | |
echo "::notice::Remote test branch is origin/$TEST_HEAD_BRANCH_NAME" | |
- name: Open head PR | |
id: open-head-pr | |
env: | |
GH_TOKEN: ${{ secrets.CREATE_PULL_REQUEST_ACTION_TOKEN }} | |
run: | | |
echo "::notice::Base PR number is $PULL_REQUEST_NUMBER" | |
gh pr create --base "$TEST_BASE_BRANCH_NAME" --title "Test head PR for #$PULL_REQUEST_NUMBER ($SHA)" --body "Generated from #$PULL_REQUEST_NUMBER. | |
Run ID: [$RUN_ID]($(gh run view $RUN_ID --json 'url' --jq '.url')). Number: $RUN_NUMBER. Attempt: $RUN_ATTEMPT. | |
#accept2ship" | |
TEST_HEAD_PR_NUMBER=`gh pr view | grep 'number:' | cut -f 2` | |
echo "test-head-pr-number=$TEST_HEAD_PR_NUMBER" >> $GITHUB_OUTPUT | |
echo "::notice::Test head PR number is $TEST_HEAD_PR_NUMBER" | |
- name: Approve PR | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
gh pr review --approve | |
- name: Check PR | |
id: check-pr | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
TEST_HEAD_PR_NUMBER: ${{ steps.open-head-pr.outputs.test-head-pr-number }} | |
run: | | |
CHECKS_TEMP_FILE="$(mktemp)" | |
echo "checks-temp-file=$CHECKS_TEMP_FILE" >> $GITHUB_OUTPUT; | |
sleep 10 | |
CHECKS=$(gh pr checks $TEST_HEAD_PR_NUMBER | tee -a $CHECKS_TEMP_FILE) | |
PENDING=$(echo "$CHECKS" | cut -f2 | grep pending | wc -l) | |
while [[ $PENDING -gt 0 && -n "$PENDING" ]] | |
do | |
echo "::group::Pending checks: $PENDING" | |
gh pr checks $TEST_HEAD_PR_NUMBER --watch --fail-fast | tee -a $CHECKS_TEMP_FILE | |
sleep 10 | |
CHECKS=$(gh pr checks $TEST_HEAD_PR_NUMBER | tee -a $CHECKS_TEMP_FILE) | |
PENDING=$(echo "$CHECKS" | cut -f2 | grep pending | wc -l) | |
echo "::endgroup::" | |
done | |
if [[ -s $CHECKS_TEMP_FILE ]] | |
then | |
echo "::group::Temp file content" | |
cat $CHECKS_TEMP_FILE | |
echo "::endgroup::" | |
else | |
echo "checks-temp-file=" >> $GITHUB_OUTPUT; | |
fi | |
gh pr checks $TEST_HEAD_PR_NUMBER # Let check outcome determine the step exit code | |
- name: Report Checks | |
if: ${{ always() && steps.check-pr.outputs.checks-temp-file != '' && (github.event_name == 'pull_request' || github.event_name == 'workflow_run')}} | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
TEST_HEAD_PR_NUMBER: ${{ steps.open-head-pr.outputs.test-head-pr-number }} | |
CHECKS_TEMP_FILE: ${{ steps.check-pr.outputs.checks-temp-file }} | |
run: | | |
gh pr comment $PULL_REQUEST_NUMBER --body "**Checks from Test PR #$TEST_HEAD_PR_NUMBER** | |
| Check | Status | Time | | |
| --- | --- | --: | | |
$(cat $CHECKS_TEMP_FILE | | |
grep -E 'https://' | | |
tac | | |
awk 'BEGIN { FS ="\t" } ; { if (! seen[$1]++) print }' | | |
sed -E 's/(.*)\t(pass)\t(.*)\t(.*)\t(.*)/| [**\1**](\4) | ✅ | \3 |/; | |
s/(.*)\t(fail)\t(.*)\t(.*)\t(.*)/| [*\1*](\4) | ⛔ | \3 |/; | |
s/(.*)\t(skipping)\t(.*)\t(.*)\t(.*)/| [~\1~](\4) | ⏭️ | |/; | |
s/(.*)\t(pending)\t(.*)\t(.*)\t(.*)/| [\1](\4) | 🔄 | |/; | |
s/(.*)\t(.*)\t(.*)\t(.*)\t(.*)/| [\1](\4) | \2 | \3 |/')" | |
rm -f $CHECKS_TEMP_FILE | |
- name: Verify PR | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
TEST_HEAD_PR_NUMBER: ${{ steps.open-head-pr.outputs.test-head-pr-number }} | |
run: | | |
TEST_PR_STATE=`gh pr view $TEST_HEAD_PR_NUMBER --json 'state' -q '.state'` | |
echo "::notice::Test PR state is $TEST_PR_STATE" | |
if [ "$TEST_PR_STATE" != 'MERGED' ] | |
then | |
exit 1 | |
fi | |
- name: Close head PR | |
if: ${{ failure() || cancelled() }} | |
continue-on-error: true | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
TEST_HEAD_PR_NUMBER: ${{ steps.open-head-pr.outputs.test-head-pr-number }} | |
run: | | |
TEST_PR_STATE=`gh pr view $TEST_HEAD_PR_NUMBER --json 'state' -q '.state'` | |
if [ "$TEST_PR_STATE" = 'MERGED' ] | |
then | |
exit | |
fi | |
gh pr close $TEST_HEAD_PR_NUMBER -d -c "Finished testing $SHA by $RUN_NUMBER-$RUN_ATTEMPT. Closing PR." | |
- name: Delete remote test head branch | |
if: ${{ always() }} | |
continue-on-error: true | |
run: | | |
if test $(git ls-remote origin --heads "$TEST_HEAD_BRANCH_NAME" | wc -l ) != 0 | |
then | |
git push -d origin "$TEST_HEAD_BRANCH_NAME" | |
fi | |
- name: Close base PR | |
if: ${{ always() }} | |
continue-on-error: true | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
TEST_BASE_PR_NUMBER: ${{ steps.open-base-pr.outputs.test-base-pr-number }} | |
run: | | |
gh pr close $TEST_BASE_PR_NUMBER -d -c "Finished testing $SHA by $RUN_NUMBER-$RUN_ATTEMPT. Closing PR." | |
- name: Delete remote test base branch | |
if: ${{ always() }} | |
continue-on-error: true | |
run: | | |
if test $(git ls-remote origin --heads "$TEST_BASE_BRANCH_NAME" | wc -l ) != 0 | |
then | |
git push -d origin "$TEST_BASE_BRANCH_NAME" | |
fi |