From fd3b1862647f9ef802083293eb0f0114ff65d63a Mon Sep 17 00:00:00 2001 From: Fabrizio Ferri Benedetti Date: Thu, 20 Mar 2025 10:55:17 +0100 Subject: [PATCH 01/14] Add nudge to PR actions --- .github/workflows/pr-actions.yml | 58 ++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/.github/workflows/pr-actions.yml b/.github/workflows/pr-actions.yml index 2e845581872e..544514af7bd7 100644 --- a/.github/workflows/pr-actions.yml +++ b/.github/workflows/pr-actions.yml @@ -118,3 +118,61 @@ jobs: gh pr comment $PR_NUM -b "fix:${PR_ACTION} failed or was cancelled. For details, see $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID." env: GH_TOKEN: ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN }} + + nudge-action: + name: Rerun PR checks + runs-on: ubuntu-latest + + if: | + github.event.issue.pull_request && + github.event.comment.body == '/nudge' + permissions: + contents: read + pull-requests: write + + steps: + - name: Context info + run: | + echo $PR_NUM + echo $COMMENT + env: + PR_NUM: ${{ github.event.issue.number }} + COMMENT: ${{ github.event.comment.body }} + + - name: Write start comment + run: | + gh pr comment $PR_NUM -b "You triggered /nudge action run at $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" + env: + GH_TOKEN: ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN }} + PR_NUM: ${{ github.event.issue.number }} + + - name: Rerun PR checks + run: | + # Get the latest check run to re-run all checks + gh pr checks $PR_NUM --repo $GITHUB_REPOSITORY --watch + # This doesn't actually re-run them, but shows the status + # Now re-run them + gh run rerun $(gh run list --branch $(gh pr view $PR_NUM --json headRefName -q .headRefName) --limit 1 --json databaseId -q '.[0].databaseId') + env: + GH_TOKEN: ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN }} + PR_NUM: ${{ github.event.issue.number }} + + - name: Report success + if: ${{ !failure() && !cancelled() }} + run: | + gh pr comment $PR_NUM --body "$(cat < Date: Thu, 20 Mar 2025 13:07:04 +0100 Subject: [PATCH 02/14] Fix --- .github/workflows/pr-actions.yml | 50 +++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 7 deletions(-) diff --git a/.github/workflows/pr-actions.yml b/.github/workflows/pr-actions.yml index 544514af7bd7..9b88723ca603 100644 --- a/.github/workflows/pr-actions.yml +++ b/.github/workflows/pr-actions.yml @@ -129,6 +129,7 @@ jobs: permissions: contents: read pull-requests: write + actions: write steps: - name: Context info @@ -148,11 +149,46 @@ jobs: - name: Rerun PR checks run: | - # Get the latest check run to re-run all checks - gh pr checks $PR_NUM --repo $GITHUB_REPOSITORY --watch - # This doesn't actually re-run them, but shows the status - # Now re-run them - gh run rerun $(gh run list --branch $(gh pr view $PR_NUM --json headRefName -q .headRefName) --limit 1 --json databaseId -q '.[0].databaseId') + # Get the PR head SHA + PR_HEAD_SHA=$(gh pr view $PR_NUM --json headRefOid -q .headRefOid) + echo "PR head SHA: $PR_HEAD_SHA" + + # Find workflow runs for this PR that need to be re-run + echo "Finding workflow runs for PR #$PR_NUM..." + + # Get the names of all the workflows that ran on the PR + WORKFLOW_RUNS=$(gh run list --limit 30 --json name,headSha,event,databaseId,conclusion,status --jq '.[] | select(.headSha=="'$PR_HEAD_SHA'" and .event=="pull_request") | "\(.databaseId)|\(.name)|\(.conclusion)|\(.status)"') + + if [ -z "$WORKFLOW_RUNS" ]; then + echo "No workflow runs found for PR head SHA: $PR_HEAD_SHA" + + # Try to find the most recent workflow runs for this PR regardless of SHA + PR_BRANCH=$(gh pr view $PR_NUM --json headRefName -q .headRefName) + echo "Trying with PR branch: $PR_BRANCH" + + WORKFLOW_RUNS=$(gh run list --branch $PR_BRANCH --limit 30 --json name,databaseId,conclusion,status --jq '.[] | "\(.databaseId)|\(.name)|\(.conclusion)|\(.status)"') + fi + + if [ -z "$WORKFLOW_RUNS" ]; then + echo "No workflow runs found for this PR" + exit 1 + fi + + # Rerun each workflow that's completed (whether it succeeded or failed) + echo "$WORKFLOW_RUNS" | while IFS="|" read -r RUN_ID NAME CONCLUSION STATUS; do + echo "Workflow $NAME (ID: $RUN_ID) - Status: $STATUS, Conclusion: $CONCLUSION" + + # Only rerun completed workflows + if [ "$STATUS" = "completed" ]; then + echo "Re-running workflow: $NAME (ID: $RUN_ID)" + gh run rerun $RUN_ID + echo "Successfully triggered rerun of workflow $NAME (ID: $RUN_ID)" + elif [ "$STATUS" = "in_progress" ]; then + echo "Workflow $NAME (ID: $RUN_ID) is already in progress, skipping" + else + echo "Cannot rerun workflow $NAME (ID: $RUN_ID) with status: $STATUS" + fi + done env: GH_TOKEN: ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN }} PR_NUM: ${{ github.event.issue.number }} @@ -161,8 +197,8 @@ jobs: if: ${{ !failure() && !cancelled() }} run: | gh pr comment $PR_NUM --body "$(cat < Date: Thu, 20 Mar 2025 13:12:20 +0100 Subject: [PATCH 03/14] Refactor --- .github/workflows/pr-actions.yml | 45 +++++++++++++++++++------------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/.github/workflows/pr-actions.yml b/.github/workflows/pr-actions.yml index 9b88723ca603..b02a286f2bb8 100644 --- a/.github/workflows/pr-actions.yml +++ b/.github/workflows/pr-actions.yml @@ -149,42 +149,51 @@ jobs: - name: Rerun PR checks run: | - # Get the PR head SHA + # Get the PR head SHA and branch name PR_HEAD_SHA=$(gh pr view $PR_NUM --json headRefOid -q .headRefOid) - echo "PR head SHA: $PR_HEAD_SHA" + PR_BRANCH=$(gh pr view $PR_NUM --json headRefName -q .headRefName) + + echo "PR #$PR_NUM" + echo "Head SHA: $PR_HEAD_SHA" + echo "Branch: $PR_BRANCH" # Find workflow runs for this PR that need to be re-run echo "Finding workflow runs for PR #$PR_NUM..." - # Get the names of all the workflows that ran on the PR - WORKFLOW_RUNS=$(gh run list --limit 30 --json name,headSha,event,databaseId,conclusion,status --jq '.[] | select(.headSha=="'$PR_HEAD_SHA'" and .event=="pull_request") | "\(.databaseId)|\(.name)|\(.conclusion)|\(.status)"') + # First try to get runs for the exact SHA + echo "Looking for runs with exact SHA: $PR_HEAD_SHA" + WORKFLOW_RUNS=$(gh run list --limit 30 --json name,headSha,event,databaseId,conclusion,status \ + --jq '.[] | select(.headSha=="'$PR_HEAD_SHA'" and .event=="pull_request") | "\(.databaseId)|\(.name)|\(.conclusion)|\(.status)"') + # If no runs found with exact SHA, try by branch name if [ -z "$WORKFLOW_RUNS" ]; then - echo "No workflow runs found for PR head SHA: $PR_HEAD_SHA" - - # Try to find the most recent workflow runs for this PR regardless of SHA - PR_BRANCH=$(gh pr view $PR_NUM --json headRefName -q .headRefName) - echo "Trying with PR branch: $PR_BRANCH" - - WORKFLOW_RUNS=$(gh run list --branch $PR_BRANCH --limit 30 --json name,databaseId,conclusion,status --jq '.[] | "\(.databaseId)|\(.name)|\(.conclusion)|\(.status)"') + echo "No workflow runs found for SHA $PR_HEAD_SHA, trying branch: $PR_BRANCH" + WORKFLOW_RUNS=$(gh run list --branch $PR_BRANCH --limit 30 --json name,databaseId,conclusion,status \ + --jq '.[] | "\(.databaseId)|\(.name)|\(.conclusion)|\(.status)"') fi + # Check if we found any workflows if [ -z "$WORKFLOW_RUNS" ]; then echo "No workflow runs found for this PR" exit 1 fi - # Rerun each workflow that's completed (whether it succeeded or failed) + # Print the workflows we found + echo "Found the following workflow runs:" + echo "$WORKFLOW_RUNS" | while IFS="|" read -r RUN_ID NAME CONCLUSION STATUS; do + echo "- $NAME (ID: $RUN_ID): Status=$STATUS, Conclusion=$CONCLUSION" + done + + # Rerun each completed workflow + echo "" + echo "Re-running workflows:" echo "$WORKFLOW_RUNS" | while IFS="|" read -r RUN_ID NAME CONCLUSION STATUS; do - echo "Workflow $NAME (ID: $RUN_ID) - Status: $STATUS, Conclusion: $CONCLUSION" - - # Only rerun completed workflows if [ "$STATUS" = "completed" ]; then echo "Re-running workflow: $NAME (ID: $RUN_ID)" - gh run rerun $RUN_ID - echo "Successfully triggered rerun of workflow $NAME (ID: $RUN_ID)" + RERUN_RESULT=$(gh run rerun $RUN_ID) + echo "Result: $RERUN_RESULT" elif [ "$STATUS" = "in_progress" ]; then - echo "Workflow $NAME (ID: $RUN_ID) is already in progress, skipping" + echo "Workflow $NAME (ID: $RUN_ID) is already running, skipping" else echo "Cannot rerun workflow $NAME (ID: $RUN_ID) with status: $STATUS" fi From cc7d5525dbf84e55d0248d740c6e5a4a51c79944 Mon Sep 17 00:00:00 2001 From: Fabrizio Ferri Benedetti Date: Thu, 20 Mar 2025 13:20:38 +0100 Subject: [PATCH 04/14] Actions prettyfier --- .github/workflows/pr-actions.yml | 84 +++++++++++++++++++++++--------- 1 file changed, 61 insertions(+), 23 deletions(-) diff --git a/.github/workflows/pr-actions.yml b/.github/workflows/pr-actions.yml index b02a286f2bb8..bc72cea36f2b 100644 --- a/.github/workflows/pr-actions.yml +++ b/.github/workflows/pr-actions.yml @@ -152,40 +152,76 @@ jobs: # Get the PR head SHA and branch name PR_HEAD_SHA=$(gh pr view $PR_NUM --json headRefOid -q .headRefOid) PR_BRANCH=$(gh pr view $PR_NUM --json headRefName -q .headRefName) - + PR_REPO=$(gh pr view $PR_NUM --json headRepositoryName -q .headRepositoryName) + PR_OWNER=$(gh pr view $PR_NUM --json headRepositoryOwner -q .headRepositoryOwner.login) + echo "PR #$PR_NUM" echo "Head SHA: $PR_HEAD_SHA" echo "Branch: $PR_BRANCH" - - # Find workflow runs for this PR that need to be re-run - echo "Finding workflow runs for PR #$PR_NUM..." - - # First try to get runs for the exact SHA - echo "Looking for runs with exact SHA: $PR_HEAD_SHA" - WORKFLOW_RUNS=$(gh run list --limit 30 --json name,headSha,event,databaseId,conclusion,status \ - --jq '.[] | select(.headSha=="'$PR_HEAD_SHA'" and .event=="pull_request") | "\(.databaseId)|\(.name)|\(.conclusion)|\(.status)"') - - # If no runs found with exact SHA, try by branch name - if [ -z "$WORKFLOW_RUNS" ]; then - echo "No workflow runs found for SHA $PR_HEAD_SHA, trying branch: $PR_BRANCH" - WORKFLOW_RUNS=$(gh run list --branch $PR_BRANCH --limit 30 --json name,databaseId,conclusion,status \ - --jq '.[] | "\(.databaseId)|\(.name)|\(.conclusion)|\(.status)"') + echo "Repo: $PR_OWNER/$PR_REPO" + + # Method 1: Try to trigger workflows by making an empty commit on the PR branch + # This will only work if we have write access to the PR's branch + if gh pr checkout $PR_NUM; then + echo "Checked out PR #$PR_NUM branch: $PR_BRANCH" + + # Try to push an empty commit to trigger the checks + git config --local user.email "$USER_EMAIL" + git config --local user.name "$USER_NAME" + + if git commit --allow-empty -m "Trigger PR checks via /nudge command"; then + echo "Created empty commit to trigger checks" + git push + echo "Pushed commit, checks should now be triggered on the PR" + exit 0 + else + echo "Failed to create empty commit, trying alternative method" + fi + else + echo "Could not checkout PR branch, likely due to permissions. Trying alternative method." fi - - # Check if we found any workflows + + # Method 2: Find workflow files and try to manually dispatch them if possible + echo "Finding workflow runs for PR #$PR_NUM..." + + # Try to trigger workflow_dispatch events for workflows that support it + echo "Attempting to trigger workflow_dispatch events..." + + # List all workflows in the repo + WORKFLOWS=$(gh workflow list --all --json id,name,state --jq '.[] | "\(.id)|\(.name)|\(.state)"') + + echo "Available workflows:" + echo "$WORKFLOWS" | while IFS="|" read -r WF_ID WF_NAME WF_STATE; do + echo "- $WF_NAME (ID: $WF_ID): State=$WF_STATE" + + if [ "$WF_STATE" = "active" ]; then + # Try to dispatch this workflow with the PR branch as ref + echo "Attempting to dispatch workflow: $WF_NAME (ID: $WF_ID) for branch: $PR_BRANCH" + if gh workflow run $WF_ID --ref $PR_BRANCH; then + echo "Successfully dispatched workflow: $WF_NAME" + else + echo "Could not dispatch workflow: $WF_NAME - It may not support workflow_dispatch event" + fi + fi + done + + # Method 3: As a fallback, just rerun existing workflow runs as we did before + echo "Falling back to rerunning existing workflow runs..." + + WORKFLOW_RUNS=$(gh run list --limit 30 --branch $PR_BRANCH --json name,databaseId,conclusion,status \ + --jq '.[] | "\(.databaseId)|\(.name)|\(.conclusion)|\(.status)"') + if [ -z "$WORKFLOW_RUNS" ]; then - echo "No workflow runs found for this PR" + echo "No workflow runs found for this PR branch: $PR_BRANCH" + echo "Unable to rerun checks for PR #$PR_NUM" exit 1 fi - - # Print the workflows we found + echo "Found the following workflow runs:" echo "$WORKFLOW_RUNS" | while IFS="|" read -r RUN_ID NAME CONCLUSION STATUS; do echo "- $NAME (ID: $RUN_ID): Status=$STATUS, Conclusion=$CONCLUSION" done - - # Rerun each completed workflow - echo "" + echo "Re-running workflows:" echo "$WORKFLOW_RUNS" | while IFS="|" read -r RUN_ID NAME CONCLUSION STATUS; do if [ "$STATUS" = "completed" ]; then @@ -201,6 +237,8 @@ jobs: env: GH_TOKEN: ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN }} PR_NUM: ${{ github.event.issue.number }} + USER_EMAIL: 107717825+opentelemetrybot@users.noreply.github.com + USER_NAME: opentelemetrybot - name: Report success if: ${{ !failure() && !cancelled() }} From 915b24a239db9643055de0f93924ef2ead9a9130 Mon Sep 17 00:00:00 2001 From: Fabrizio Ferri Benedetti Date: Fri, 21 Mar 2025 09:42:13 +0100 Subject: [PATCH 05/14] Comment status --- .github/workflows/pr-actions.yml | 207 ++++++++++++++++++++++++------- 1 file changed, 159 insertions(+), 48 deletions(-) diff --git a/.github/workflows/pr-actions.yml b/.github/workflows/pr-actions.yml index bc72cea36f2b..c2c271663ef8 100644 --- a/.github/workflows/pr-actions.yml +++ b/.github/workflows/pr-actions.yml @@ -48,74 +48,185 @@ jobs: - name: Write start comment run: | - gh pr comment $PR_NUM -b "You triggered fix:${PR_ACTION} action run at $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" - env: - GH_TOKEN: ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN }} - - - run: gh pr checkout $PR_NUM -b "pr-action-${RANDOM}" + gh pr comment $PR_NUM -b "You triggered /nudge action run at $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" env: GH_TOKEN: ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN }} + PR_NUM: ${{ github.event.issue.number }} - - name: Create NPM cache-hash input file - run: | - mkdir -p tmp - jq '{devDependencies, dependencies, engines, gitHubActionCacheKey}' package.json > tmp/package-ci.json - - - uses: actions/setup-node@v4 - with: - node-version-file: .nvmrc - cache: npm - cache-dependency-path: tmp/package-ci.json - - - run: | - case $PR_ACTION in - all|refcache*|text) - npm install --omit=optional - ;& - *) - npm run fix:$PR_ACTION - ;; - esac - git status - git branch -v - - - name: Commit and push changes, if any + - name: Rerun PR checks + id: rerun_checks run: | - git config --local user.email "$USER_EMAIL" - git config --local user.name "$USER_NAME" - if [[ $(git status --porcelain) ]]; then - git add -A - current_branch=$(git rev-parse --abbrev-ref HEAD) - echo current_branch=$current_branch - # gh pr checkout sets some git configs that we can use to make sure - # we push to the right repo & to the right branch - remote_repo=$(git config --get branch.${current_branch}.remote) - echo remote_repo=$remote_repo - remote_branch=$(git config --get branch.${current_branch}.merge) - echo remote_branch=$remote_branch - git commit -m "Results from /fix:${PR_ACTION}" - git push ${remote_repo} HEAD:${remote_branch} + # Get the PR head SHA and branch name + PR_HEAD_SHA=$(gh pr view $PR_NUM --json headRefOid -q .headRefOid) + PR_BRANCH=$(gh pr view $PR_NUM --json headRefName -q .headRefName) + PR_REPO=$(gh pr view $PR_NUM --json headRepositoryName -q .headRepositoryName) + PR_OWNER=$(gh pr view $PR_NUM --json headRepositoryOwner -q .headRepositoryOwner.login) + + echo "PR #$PR_NUM" + echo "Head SHA: $PR_HEAD_SHA" + echo "Branch: $PR_BRANCH" + echo "Repo: $PR_OWNER/$PR_REPO" + + # Set default status values + EMPTY_COMMIT_SUCCEEDED="false" + WORKFLOW_DISPATCH_SUCCEEDED="false" + RERUN_SUCCEEDED="false" + STATUS_MESSAGE="" + + # Method 1: Try to trigger workflows by making an empty commit on the PR branch + # This will only work if we have write access to the PR's branch + if gh pr checkout $PR_NUM; then + echo "Checked out PR #$PR_NUM branch: $PR_BRANCH" + + # Update PR comment + gh pr comment $PR_NUM -b "📡 /nudge: Attempting to trigger checks by creating an empty commit on the PR branch..." + + # Try to push an empty commit to trigger the checks + git config --local user.email "$USER_EMAIL" + git config --local user.name "$USER_NAME" + + if git commit --allow-empty -m "Trigger PR checks via /nudge command"; then + echo "Created empty commit to trigger checks" + if git push; then + echo "Pushed commit, checks should now be triggered on the PR" + EMPTY_COMMIT_SUCCEEDED="true" + STATUS_MESSAGE="✅ Successfully triggered checks by creating an empty commit on the PR branch." + gh pr comment $PR_NUM -b "$STATUS_MESSAGE" + echo "empty_commit_succeeded=true" >> $GITHUB_OUTPUT + exit 0 + else + echo "Failed to push commit" + gh pr comment $PR_NUM -b "⚠️ Created empty commit but failed to push to PR branch. Trying alternative methods..." + fi + else + echo "Failed to create empty commit, trying alternative method" + gh pr comment $PR_NUM -b "⚠️ Failed to create empty commit on PR branch. Trying alternative methods..." + fi else - echo "No changes to commit" + echo "Could not checkout PR branch, likely due to permissions. Trying alternative method." + gh pr comment $PR_NUM -b "⚠️ Could not checkout PR branch (likely due to permissions). Trying alternative methods..." + fi + + # Method 2: Find workflow files and try to manually dispatch them if possible + echo "Finding workflow runs for PR #$PR_NUM..." + gh pr comment $PR_NUM -b "📡 /nudge: Attempting to trigger workflow_dispatch events for workflows that support it..." + + # Try to trigger workflow_dispatch events for workflows that support it + echo "Attempting to trigger workflow_dispatch events..." + + # List all workflows in the repo + WORKFLOWS=$(gh workflow list --all --json id,name,state --jq '.[] | "\(.id)|\(.name)|\(.state)"') + DISPATCH_COUNT=0 + + echo "Available workflows:" + echo "$WORKFLOWS" | while IFS="|" read -r WF_ID WF_NAME WF_STATE; do + echo "- $WF_NAME (ID: $WF_ID): State=$WF_STATE" + + if [ "$WF_STATE" = "active" ]; then + # Try to dispatch this workflow with the PR branch as ref + echo "Attempting to dispatch workflow: $WF_NAME (ID: $WF_ID) for branch: $PR_BRANCH" + if gh workflow run $WF_ID --ref $PR_BRANCH; then + echo "Successfully dispatched workflow: $WF_NAME" + DISPATCH_COUNT=$((DISPATCH_COUNT+1)) + else + echo "Could not dispatch workflow: $WF_NAME - It may not support workflow_dispatch event" + fi + fi + done + + if [ $DISPATCH_COUNT -gt 0 ]; then + WORKFLOW_DISPATCH_SUCCEEDED="true" + STATUS_MESSAGE="✅ Successfully triggered $DISPATCH_COUNT workflows via workflow_dispatch." + gh pr comment $PR_NUM -b "$STATUS_MESSAGE" + echo "workflow_dispatch_succeeded=true" >> $GITHUB_OUTPUT + exit 0 + else + gh pr comment $PR_NUM -b "⚠️ Could not trigger any workflows via workflow_dispatch. Trying fallback method..." + fi + + # Method 3: As a fallback, just rerun existing workflow runs as we did before + echo "Falling back to rerunning existing workflow runs..." + gh pr comment $PR_NUM -b "📡 /nudge: Falling back to rerunning existing workflow runs..." + + WORKFLOW_RUNS=$(gh run list --limit 30 --branch $PR_BRANCH --json name,databaseId,conclusion,status \ + --jq '.[] | "\(.databaseId)|\(.name)|\(.conclusion)|\(.status)"') + + if [ -z "$WORKFLOW_RUNS" ]; then + echo "No workflow runs found for this PR branch: $PR_BRANCH" + echo "Unable to rerun checks for PR #$PR_NUM" + gh pr comment $PR_NUM -b "❌ No workflow runs found for branch: $PR_BRANCH. Unable to rerun checks." + exit 1 + fi + + echo "Found the following workflow runs:" + RERUN_COUNT=0 + + echo "$WORKFLOW_RUNS" | while IFS="|" read -r RUN_ID NAME CONCLUSION STATUS; do + echo "- $NAME (ID: $RUN_ID): Status=$STATUS, Conclusion=$CONCLUSION" + done + + echo "Re-running workflows:" + echo "$WORKFLOW_RUNS" | while IFS="|" read -r RUN_ID NAME CONCLUSION STATUS; do + if [ "$STATUS" = "completed" ]; then + echo "Re-running workflow: $NAME (ID: $RUN_ID)" + RERUN_RESULT=$(gh run rerun $RUN_ID) + echo "Result: $RERUN_RESULT" + if [[ "$RERUN_RESULT" == *"Requested rerun of run"* ]]; then + RERUN_COUNT=$((RERUN_COUNT+1)) + fi + elif [ "$STATUS" = "in_progress" ]; then + echo "Workflow $NAME (ID: $RUN_ID) is already running, skipping" + else + echo "Cannot rerun workflow $NAME (ID: $RUN_ID) with status: $STATUS" + fi + done + + if [ $RERUN_COUNT -gt 0 ]; then + RERUN_SUCCEEDED="true" + STATUS_MESSAGE="✅ Successfully requested rerun of $RERUN_COUNT workflows." + gh pr comment $PR_NUM -b "$STATUS_MESSAGE" + echo "rerun_succeeded=true" >> $GITHUB_OUTPUT + else + gh pr comment $PR_NUM -b "❌ Could not rerun any workflows. Please check the action run for details." + echo "All methods failed to rerun checks for PR #$PR_NUM" + exit 1 fi env: GH_TOKEN: ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN }} + PR_NUM: ${{ github.event.issue.number }} + USER_EMAIL: 107717825+opentelemetrybot@users.noreply.github.com + USER_NAME: opentelemetrybot - - name: Report success and ask to run full checks + - name: Report final status if: ${{ !failure() && !cancelled() }} run: | + STATUS="⚠️ The /nudge action completed, but check statuses may not appear directly on the PR." + + if [[ "${{ steps.rerun_checks.outputs.empty_commit_succeeded }}" == "true" ]]; then + STATUS="✅ Successfully triggered PR checks with an empty commit. Check results will appear on the PR automatically." + elif [[ "${{ steps.rerun_checks.outputs.workflow_dispatch_succeeded }}" == "true" ]]; then + STATUS="✅ Successfully triggered workflows via workflow_dispatch. Check the Actions tab for results." + elif [[ "${{ steps.rerun_checks.outputs.rerun_succeeded }}" == "true" ]]; then + STATUS="⚠️ Rerun requested for existing workflow runs, but results may not appear directly on the PR." + fi + gh pr comment $PR_NUM --body "$(cat < Date: Fri, 21 Mar 2025 10:04:31 +0100 Subject: [PATCH 06/14] Simplify to use empty commits --- .github/workflows/pr-actions.yml | 360 ++++++++----------------------- 1 file changed, 88 insertions(+), 272 deletions(-) diff --git a/.github/workflows/pr-actions.yml b/.github/workflows/pr-actions.yml index c2c271663ef8..80ce8c294009 100644 --- a/.github/workflows/pr-actions.yml +++ b/.github/workflows/pr-actions.yml @@ -1,5 +1,4 @@ name: PR actions -# cSpell:ignore esac htmltest refcache nvmrc opentelemetrybot on: issue_comment: @@ -15,6 +14,7 @@ jobs: pr-action: name: Run PR action runs-on: ubuntu-latest + if: | github.event.issue.pull_request && startsWith(github.event.comment.body, '/fix:') @@ -26,19 +26,12 @@ jobs: DEPTH: --depth 999 # submodule clone depth steps: - - name: Context info - run: | - echo $PR_NUM - echo $COMMENT - - - uses: actions/checkout@v4 - - name: Extract action name id: extract_action_name run: | - PR_ACTION=$(echo $COMMENT | grep -oP '/fix:\K[:-_0-9a-z]+') + PR_ACTION=$(echo $COMMENT | grep -oP '/fix:\K[-_0-9a-z]+') echo "Action is $PR_ACTION" - ACTION_NAMES="all|dict|expired|filenames|format|htmltest-config|i18n|markdown|refcache(:refresh)?|submodules?|text" + ACTION_NAMES="all|dict|filenames|format|htmltest-config|i18n|markdown|refcache|submodules?|text" if [[ ! "$PR_ACTION" =~ ^($ACTION_NAMES)$ ]]; then echo "Invalid action name: $PR_ACTION" echo "Action name should be one of: $ACTION_NAMES" @@ -46,327 +39,150 @@ jobs: fi echo "PR_ACTION=$PR_ACTION" >> "$GITHUB_ENV" + - name: Context info + run: | + echo $PR_NUM + echo $COMMENT + + - uses: actions/checkout@v4 + - name: Write start comment run: | - gh pr comment $PR_NUM -b "You triggered /nudge action run at $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" + gh pr comment $PR_NUM -b "You triggered fix:${PR_ACTION} action run at $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" + env: + GH_TOKEN: ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN }} + + - run: gh pr checkout $PR_NUM -b "pr-action-${RANDOM}" env: GH_TOKEN: ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN }} - PR_NUM: ${{ github.event.issue.number }} - - name: Rerun PR checks - id: rerun_checks + - name: Create NPM cache-hash input file run: | - # Get the PR head SHA and branch name - PR_HEAD_SHA=$(gh pr view $PR_NUM --json headRefOid -q .headRefOid) - PR_BRANCH=$(gh pr view $PR_NUM --json headRefName -q .headRefName) - PR_REPO=$(gh pr view $PR_NUM --json headRepositoryName -q .headRepositoryName) - PR_OWNER=$(gh pr view $PR_NUM --json headRepositoryOwner -q .headRepositoryOwner.login) - - echo "PR #$PR_NUM" - echo "Head SHA: $PR_HEAD_SHA" - echo "Branch: $PR_BRANCH" - echo "Repo: $PR_OWNER/$PR_REPO" - - # Set default status values - EMPTY_COMMIT_SUCCEEDED="false" - WORKFLOW_DISPATCH_SUCCEEDED="false" - RERUN_SUCCEEDED="false" - STATUS_MESSAGE="" - - # Method 1: Try to trigger workflows by making an empty commit on the PR branch - # This will only work if we have write access to the PR's branch - if gh pr checkout $PR_NUM; then - echo "Checked out PR #$PR_NUM branch: $PR_BRANCH" - - # Update PR comment - gh pr comment $PR_NUM -b "📡 /nudge: Attempting to trigger checks by creating an empty commit on the PR branch..." - - # Try to push an empty commit to trigger the checks - git config --local user.email "$USER_EMAIL" - git config --local user.name "$USER_NAME" - - if git commit --allow-empty -m "Trigger PR checks via /nudge command"; then - echo "Created empty commit to trigger checks" - if git push; then - echo "Pushed commit, checks should now be triggered on the PR" - EMPTY_COMMIT_SUCCEEDED="true" - STATUS_MESSAGE="✅ Successfully triggered checks by creating an empty commit on the PR branch." - gh pr comment $PR_NUM -b "$STATUS_MESSAGE" - echo "empty_commit_succeeded=true" >> $GITHUB_OUTPUT - exit 0 - else - echo "Failed to push commit" - gh pr comment $PR_NUM -b "⚠️ Created empty commit but failed to push to PR branch. Trying alternative methods..." - fi - else - echo "Failed to create empty commit, trying alternative method" - gh pr comment $PR_NUM -b "⚠️ Failed to create empty commit on PR branch. Trying alternative methods..." - fi - else - echo "Could not checkout PR branch, likely due to permissions. Trying alternative method." - gh pr comment $PR_NUM -b "⚠️ Could not checkout PR branch (likely due to permissions). Trying alternative methods..." - fi - - # Method 2: Find workflow files and try to manually dispatch them if possible - echo "Finding workflow runs for PR #$PR_NUM..." - gh pr comment $PR_NUM -b "📡 /nudge: Attempting to trigger workflow_dispatch events for workflows that support it..." - - # Try to trigger workflow_dispatch events for workflows that support it - echo "Attempting to trigger workflow_dispatch events..." - - # List all workflows in the repo - WORKFLOWS=$(gh workflow list --all --json id,name,state --jq '.[] | "\(.id)|\(.name)|\(.state)"') - DISPATCH_COUNT=0 - - echo "Available workflows:" - echo "$WORKFLOWS" | while IFS="|" read -r WF_ID WF_NAME WF_STATE; do - echo "- $WF_NAME (ID: $WF_ID): State=$WF_STATE" - - if [ "$WF_STATE" = "active" ]; then - # Try to dispatch this workflow with the PR branch as ref - echo "Attempting to dispatch workflow: $WF_NAME (ID: $WF_ID) for branch: $PR_BRANCH" - if gh workflow run $WF_ID --ref $PR_BRANCH; then - echo "Successfully dispatched workflow: $WF_NAME" - DISPATCH_COUNT=$((DISPATCH_COUNT+1)) - else - echo "Could not dispatch workflow: $WF_NAME - It may not support workflow_dispatch event" - fi - fi - done - - if [ $DISPATCH_COUNT -gt 0 ]; then - WORKFLOW_DISPATCH_SUCCEEDED="true" - STATUS_MESSAGE="✅ Successfully triggered $DISPATCH_COUNT workflows via workflow_dispatch." - gh pr comment $PR_NUM -b "$STATUS_MESSAGE" - echo "workflow_dispatch_succeeded=true" >> $GITHUB_OUTPUT - exit 0 - else - gh pr comment $PR_NUM -b "⚠️ Could not trigger any workflows via workflow_dispatch. Trying fallback method..." - fi - - # Method 3: As a fallback, just rerun existing workflow runs as we did before - echo "Falling back to rerunning existing workflow runs..." - gh pr comment $PR_NUM -b "📡 /nudge: Falling back to rerunning existing workflow runs..." - - WORKFLOW_RUNS=$(gh run list --limit 30 --branch $PR_BRANCH --json name,databaseId,conclusion,status \ - --jq '.[] | "\(.databaseId)|\(.name)|\(.conclusion)|\(.status)"') - - if [ -z "$WORKFLOW_RUNS" ]; then - echo "No workflow runs found for this PR branch: $PR_BRANCH" - echo "Unable to rerun checks for PR #$PR_NUM" - gh pr comment $PR_NUM -b "❌ No workflow runs found for branch: $PR_BRANCH. Unable to rerun checks." - exit 1 - fi - - echo "Found the following workflow runs:" - RERUN_COUNT=0 - - echo "$WORKFLOW_RUNS" | while IFS="|" read -r RUN_ID NAME CONCLUSION STATUS; do - echo "- $NAME (ID: $RUN_ID): Status=$STATUS, Conclusion=$CONCLUSION" - done - - echo "Re-running workflows:" - echo "$WORKFLOW_RUNS" | while IFS="|" read -r RUN_ID NAME CONCLUSION STATUS; do - if [ "$STATUS" = "completed" ]; then - echo "Re-running workflow: $NAME (ID: $RUN_ID)" - RERUN_RESULT=$(gh run rerun $RUN_ID) - echo "Result: $RERUN_RESULT" - if [[ "$RERUN_RESULT" == *"Requested rerun of run"* ]]; then - RERUN_COUNT=$((RERUN_COUNT+1)) - fi - elif [ "$STATUS" = "in_progress" ]; then - echo "Workflow $NAME (ID: $RUN_ID) is already running, skipping" - else - echo "Cannot rerun workflow $NAME (ID: $RUN_ID) with status: $STATUS" - fi - done - - if [ $RERUN_COUNT -gt 0 ]; then - RERUN_SUCCEEDED="true" - STATUS_MESSAGE="✅ Successfully requested rerun of $RERUN_COUNT workflows." - gh pr comment $PR_NUM -b "$STATUS_MESSAGE" - echo "rerun_succeeded=true" >> $GITHUB_OUTPUT + mkdir -p tmp + jq '{devDependencies, dependencies, engines, gitHubActionCacheKey}' package.json > tmp/package-ci.json + + - uses: actions/setup-node@v4 + with: + node-version-file: .nvmrc + cache: npm + cache-dependency-path: tmp/package-ci.json + + - run: | + case $PR_ACTION in + all|refcache) + npm install --omit=optional + ;& + dict|filenames|format|htmltest-config|markdown|submodule*) + npm run fix:$PR_ACTION + ;; + esac + git status + git branch -v + + - name: Commit and push changes, if any + run: | + git config --local user.email "$USER_EMAIL" + git config --local user.name "$USER_NAME" + if [[ $(git status --porcelain) ]]; then + git add -A + current_branch=$(git rev-parse --abbrev-ref HEAD) + echo current_branch=$current_branch + # gh pr checkout sets some git configs that we can use to make sure + # we push to the right repo & to the right branch + remote_repo=$(git config --get branch.${current_branch}.remote) + echo remote_repo=$remote_repo + remote_branch=$(git config --get branch.${current_branch}.merge) + echo remote_branch=$remote_branch + git commit -m "Results from /fix:${PR_ACTION}" + git push ${remote_repo} HEAD:${remote_branch} else - gh pr comment $PR_NUM -b "❌ Could not rerun any workflows. Please check the action run for details." - echo "All methods failed to rerun checks for PR #$PR_NUM" - exit 1 + echo "No changes to commit" fi env: GH_TOKEN: ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN }} - PR_NUM: ${{ github.event.issue.number }} - USER_EMAIL: 107717825+opentelemetrybot@users.noreply.github.com - USER_NAME: opentelemetrybot - - name: Report final status + - name: Report success and ask to run full checks if: ${{ !failure() && !cancelled() }} run: | - STATUS="⚠️ The /nudge action completed, but check statuses may not appear directly on the PR." - - if [[ "${{ steps.rerun_checks.outputs.empty_commit_succeeded }}" == "true" ]]; then - STATUS="✅ Successfully triggered PR checks with an empty commit. Check results will appear on the PR automatically." - elif [[ "${{ steps.rerun_checks.outputs.workflow_dispatch_succeeded }}" == "true" ]]; then - STATUS="✅ Successfully triggered workflows via workflow_dispatch. Check the Actions tab for results." - elif [[ "${{ steps.rerun_checks.outputs.rerun_succeeded }}" == "true" ]]; then - STATUS="⚠️ Rerun requested for existing workflow runs, but results may not appear directly on the PR." - fi - gh pr comment $PR_NUM --body "$(cat < Date: Fri, 21 Mar 2025 10:09:22 +0100 Subject: [PATCH 07/14] Restore --- .github/workflows/pr-actions.yml | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/.github/workflows/pr-actions.yml b/.github/workflows/pr-actions.yml index 80ce8c294009..24b2bad958e9 100644 --- a/.github/workflows/pr-actions.yml +++ b/.github/workflows/pr-actions.yml @@ -14,7 +14,6 @@ jobs: pr-action: name: Run PR action runs-on: ubuntu-latest - if: | github.event.issue.pull_request && startsWith(github.event.comment.body, '/fix:') @@ -26,12 +25,19 @@ jobs: DEPTH: --depth 999 # submodule clone depth steps: + - name: Context info + run: | + echo $PR_NUM + echo $COMMENT + + - uses: actions/checkout@v4 + - name: Extract action name id: extract_action_name run: | - PR_ACTION=$(echo $COMMENT | grep -oP '/fix:\K[-_0-9a-z]+') + PR_ACTION=$(echo $COMMENT | grep -oP '/fix:\K[:-_0-9a-z]+') echo "Action is $PR_ACTION" - ACTION_NAMES="all|dict|filenames|format|htmltest-config|i18n|markdown|refcache|submodules?|text" + ACTION_NAMES="all|dict|expired|filenames|format|htmltest-config|i18n|markdown|refcache(:refresh)?|submodules?|text" if [[ ! "$PR_ACTION" =~ ^($ACTION_NAMES)$ ]]; then echo "Invalid action name: $PR_ACTION" echo "Action name should be one of: $ACTION_NAMES" @@ -39,13 +45,6 @@ jobs: fi echo "PR_ACTION=$PR_ACTION" >> "$GITHUB_ENV" - - name: Context info - run: | - echo $PR_NUM - echo $COMMENT - - - uses: actions/checkout@v4 - - name: Write start comment run: | gh pr comment $PR_NUM -b "You triggered fix:${PR_ACTION} action run at $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" @@ -69,10 +68,10 @@ jobs: - run: | case $PR_ACTION in - all|refcache) + all|refcache*|text) npm install --omit=optional ;& - dict|filenames|format|htmltest-config|markdown|submodule*) + *) npm run fix:$PR_ACTION ;; esac From 4b5a92749ae446d158d76cd50eb7b11e698e1d84 Mon Sep 17 00:00:00 2001 From: Fabrizio Ferri Benedetti Date: Fri, 21 Mar 2025 10:10:14 +0100 Subject: [PATCH 08/14] Restore cSpell --- .github/workflows/pr-actions.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/pr-actions.yml b/.github/workflows/pr-actions.yml index 24b2bad958e9..795bd9dc0408 100644 --- a/.github/workflows/pr-actions.yml +++ b/.github/workflows/pr-actions.yml @@ -1,4 +1,5 @@ name: PR actions +# cSpell:ignore esac htmltest refcache nvmrc opentelemetrybot on: issue_comment: From 13d6b289af1eecd4368eb2f169b215c7467dbfbf Mon Sep 17 00:00:00 2001 From: Fabrizio Ferri Benedetti Date: Fri, 21 Mar 2025 10:14:13 +0100 Subject: [PATCH 09/14] Prettify --- .github/workflows/pr-actions.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pr-actions.yml b/.github/workflows/pr-actions.yml index 795bd9dc0408..8e05b40c824c 100644 --- a/.github/workflows/pr-actions.yml +++ b/.github/workflows/pr-actions.yml @@ -156,14 +156,14 @@ jobs: echo "Creating an empty commit to trigger CI checks" git config --local user.email "$USER_EMAIL" git config --local user.name "$USER_NAME" - + current_branch=$(git rev-parse --abbrev-ref HEAD) echo "current_branch=$current_branch" remote_repo=$(git config --get branch.${current_branch}.remote) echo "remote_repo=$remote_repo" remote_branch=$(git config --get branch.${current_branch}.merge) echo "remote_branch=$remote_branch" - + git commit --allow-empty -m "Empty commit to trigger CI checks (via /nudge)" git push ${remote_repo} HEAD:${remote_branch} env: From 35f5eba459112c1d9ba70e914a2b21b99a0a76a1 Mon Sep 17 00:00:00 2001 From: Fabrizio Ferri Benedetti Date: Mon, 24 Mar 2025 10:17:22 +0100 Subject: [PATCH 10/14] Reverse order --- .github/workflows/pr-actions.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pr-actions.yml b/.github/workflows/pr-actions.yml index 8e05b40c824c..4a2b43c56d5c 100644 --- a/.github/workflows/pr-actions.yml +++ b/.github/workflows/pr-actions.yml @@ -137,14 +137,14 @@ jobs: echo "PR Number: $PR_NUM" echo "Comment: $COMMENT" + - uses: actions/checkout@v4 + - name: Write start comment run: | gh pr comment $PR_NUM -b "You triggered /nudge action to restart PR workflows at $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" env: GH_TOKEN: ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN }} - - - uses: actions/checkout@v4 - + - name: Checkout PR run: gh pr checkout $PR_NUM -b "nudge-action-${RANDOM}" env: From ee97fdb668d944d2ee6b4312e02f2e912e3d8ca7 Mon Sep 17 00:00:00 2001 From: Fabrizio Ferri Benedetti Date: Mon, 24 Mar 2025 10:31:27 +0100 Subject: [PATCH 11/14] Edits --- .github/workflows/pr-actions.yml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/pr-actions.yml b/.github/workflows/pr-actions.yml index 4a2b43c56d5c..14de480a079b 100644 --- a/.github/workflows/pr-actions.yml +++ b/.github/workflows/pr-actions.yml @@ -122,23 +122,21 @@ jobs: nudge-action: name: Nudge PR workflows runs-on: ubuntu-latest - if: | github.event.issue.pull_request && startsWith(github.event.comment.body, '/nudge') permissions: contents: write pull-requests: write - actions: write steps: - name: Context info run: | - echo "PR Number: $PR_NUM" - echo "Comment: $COMMENT" + echo $PR_NUM + echo $COMMENT - uses: actions/checkout@v4 - + - name: Write start comment run: | gh pr comment $PR_NUM -b "You triggered /nudge action to restart PR workflows at $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" From 5a79b38613d8c2bc0ebb74ee3ab1c3e8a7c12c2e Mon Sep 17 00:00:00 2001 From: Fabrizio Ferri Benedetti Date: Mon, 24 Mar 2025 10:51:55 +0100 Subject: [PATCH 12/14] New approach --- .github/workflows/pr-actions.yml | 41 ++++++++++++++------------------ 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/.github/workflows/pr-actions.yml b/.github/workflows/pr-actions.yml index 14de480a079b..5d1059768236 100644 --- a/.github/workflows/pr-actions.yml +++ b/.github/workflows/pr-actions.yml @@ -128,12 +128,13 @@ jobs: permissions: contents: write pull-requests: write + actions: write # We need this permission to re-run workflows steps: - name: Context info run: | - echo $PR_NUM - echo $COMMENT + echo "PR Number: $PR_NUM" + echo "Comment: $COMMENT" - uses: actions/checkout@v4 @@ -142,28 +143,22 @@ jobs: gh pr comment $PR_NUM -b "You triggered /nudge action to restart PR workflows at $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" env: GH_TOKEN: ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN }} - - - name: Checkout PR - run: gh pr checkout $PR_NUM -b "nudge-action-${RANDOM}" - env: - GH_TOKEN: ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN }} - - name: Trigger workflow reruns + - name: Rerun failed workflows run: | - # Create an empty commit to trigger all PR workflows - echo "Creating an empty commit to trigger CI checks" - git config --local user.email "$USER_EMAIL" - git config --local user.name "$USER_NAME" - - current_branch=$(git rev-parse --abbrev-ref HEAD) - echo "current_branch=$current_branch" - remote_repo=$(git config --get branch.${current_branch}.remote) - echo "remote_repo=$remote_repo" - remote_branch=$(git config --get branch.${current_branch}.merge) - echo "remote_branch=$remote_branch" - - git commit --allow-empty -m "Empty commit to trigger CI checks (via /nudge)" - git push ${remote_repo} HEAD:${remote_branch} + # Get the PR's latest commit SHA + SHA=$(gh pr view $PR_NUM --json headRefOid -q .headRefOid) + echo "Latest commit SHA: $SHA" + + # List and rerun all workflows for this PR + gh run list --branch $(gh pr view $PR_NUM --json headRefName -q .headRefName) \ + --limit 20 \ + --json status,databaseId,name \ + --jq '.[] | select(.status != "completed" or .status == "completed") | .databaseId' | \ + while read -r run_id; do + echo "Re-running workflow run ID: $run_id" + gh run rerun $run_id + done env: GH_TOKEN: ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN }} @@ -172,7 +167,7 @@ jobs: run: | gh pr comment $PR_NUM --body "$(cat < Date: Mon, 24 Mar 2025 11:27:05 +0100 Subject: [PATCH 13/14] Use rerun-action instead --- .github/workflows/pr-actions.yml | 67 ++++---------------------------- 1 file changed, 8 insertions(+), 59 deletions(-) diff --git a/.github/workflows/pr-actions.yml b/.github/workflows/pr-actions.yml index 5d1059768236..20bc38b8b3a7 100644 --- a/.github/workflows/pr-actions.yml +++ b/.github/workflows/pr-actions.yml @@ -119,63 +119,12 @@ jobs: env: GH_TOKEN: ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN }} - nudge-action: - name: Nudge PR workflows - runs-on: ubuntu-latest - if: | - github.event.issue.pull_request && - startsWith(github.event.comment.body, '/nudge') - permissions: - contents: write - pull-requests: write - actions: write # We need this permission to re-run workflows - + rerun_pr_tests: + name: rerun_pr_tests + if: ${{ github.event.issue.pull_request }} + runs-on: ubuntu-20.04 steps: - - name: Context info - run: | - echo "PR Number: $PR_NUM" - echo "Comment: $COMMENT" - - - uses: actions/checkout@v4 - - - name: Write start comment - run: | - gh pr comment $PR_NUM -b "You triggered /nudge action to restart PR workflows at $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" - env: - GH_TOKEN: ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN }} - - - name: Rerun failed workflows - run: | - # Get the PR's latest commit SHA - SHA=$(gh pr view $PR_NUM --json headRefOid -q .headRefOid) - echo "Latest commit SHA: $SHA" - - # List and rerun all workflows for this PR - gh run list --branch $(gh pr view $PR_NUM --json headRefName -q .headRefName) \ - --limit 20 \ - --json status,databaseId,name \ - --jq '.[] | select(.status != "completed" or .status == "completed") | .databaseId' | \ - while read -r run_id; do - echo "Re-running workflow run ID: $run_id" - gh run rerun $run_id - done - env: - GH_TOKEN: ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN }} - - - name: Report success - if: ${{ !failure() && !cancelled() }} - run: | - gh pr comment $PR_NUM --body "$(cat < Date: Mon, 24 Mar 2025 15:56:01 +0100 Subject: [PATCH 14/14] Fix format again --- .github/workflows/pr-actions.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pr-actions.yml b/.github/workflows/pr-actions.yml index 20bc38b8b3a7..3ff9e55f0795 100644 --- a/.github/workflows/pr-actions.yml +++ b/.github/workflows/pr-actions.yml @@ -124,7 +124,7 @@ jobs: if: ${{ github.event.issue.pull_request }} runs-on: ubuntu-20.04 steps: - - uses: estroz/rerun-actions@main - with: - repo_token: ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN }} - comment_id: ${{ github.event.comment.id }} \ No newline at end of file + - uses: estroz/rerun-actions@main + with: + repo_token: ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN }} + comment_id: ${{ github.event.comment.id }}