Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update rerun workflow #2089

Merged
merged 5 commits into from
Apr 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 31 additions & 14 deletions .github/workflows/rerun-flaky-workflows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,34 @@ jobs:
actions: write
steps:
- name: Display Workflow Run Information
env:
WORKFLOW_RUN_ID: ${{ github.event.workflow_run.id }}
WORKFLOW_RUN_NAME: ${{ github.event.workflow_run.name }}
WORKFLOW_RUN_ATTEMPT: ${{ github.event.workflow_run.run_attempt }}
WORKFLOW_RUN_HTML_URL: ${{ github.event.workflow_run.html_url }}
GITHUB_JOB: ${{ github.job }}
GITHUB_RUN_ATTEMPT: ${{ github.run_attempt }}
AUTHOR_NAME: ${{ github.event.workflow_run.head_commit.author.name }}
GITHUB_ACTOR: ${{ github.actor }}
run: |
echo "The Workflow Run ${{ github.event.workflow_run.name }} has failed! " >> $GITHUB_STEP_SUMMARY
echo "View the failed run attempt (#${{ github.event.workflow_run.run_attempt }}) here: ${{ github.event.workflow_run.html_url }}" >> $GITHUB_STEP_SUMMARY
echo "Workflow Run ID: ${{ github.event.workflow_run.id }}"
echo "Job ID: ${{ github.job }}"
echo "Current run: ${{ github.run_attempt }}"
echo "Author: ${{ github.event.workflow_run.head_commit.author.name }}"
echo "Actor: ${{ github.actor }}"
echo "The Workflow Run ${{ env.WORKFLOW_RUN_NAME }} has failed! " >> $GITHUB_STEP_SUMMARY
echo "View the failed run attempt (#${{ env.WORKFLOW_RUN_ATTEMPT }}) here: ${{ env.WORKFLOW_RUN_HTML_URL }}" >> $GITHUB_STEP_SUMMARY
echo "Workflow Run ID: ${{ env.WORKFLOW_RUN_ID }}"
echo "Job ID: ${{ env.GITHUB_JOB }}"
echo "Current run: ${{ env.GITHUB_RUN_ATTEMPT }}"
echo "Author: ${{ env.AUTHOR_NAME }}"
echo "Actor: ${{ env.GITHUB_ACTOR }}"
- name: Rerun failed jobs in the current workflow
env:
GH_TOKEN: ${{ github.token }}
WORKFLOW_RUN_ATTEMPT: ${{ github.event.workflow_run.run_attempt }}
WORKFLOW_RUN_ID: ${{ github.event.workflow_run.id }}
GITHUB_REPOSITORY: ${{ github.repository }}
run: |
MAX_RUNS=2
CURRENT_RUN=${{ github.event.workflow_run.run_attempt }}
CURRENT_RUN=${{ env.WORKFLOW_RUN_ATTEMPT }}
if [ $CURRENT_RUN -lt $MAX_RUNS ]; then
gh run rerun ${{ github.event.workflow_run.id }} --repo ${{ github.repository }} --failed
gh run rerun ${{ env.WORKFLOW_RUN_ID }} --repo ${{ env.GITHUB_REPOSITORY }} --failed
else
exit 1
fi
Expand All @@ -40,33 +52,38 @@ jobs:

- name: Update env vars
if: ${{ !cancelled() && failure() }} # Run only if the previous step failed
env:
WORKFLOW_RUN_HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
run: |
commit_short=$(git rev-parse --short ${{ github.event.workflow_run.head_sha }})
commit_short=$(git rev-parse --short ${{ env.WORKFLOW_RUN_HEAD_SHA }})
echo "BREAKING_COMMIT_SHORT=$commit_short" >> $GITHUB_ENV

- name: Slack Notification
uses: ./.github/actions/slack-notification
if: ${{ !cancelled() && failure() && github.event_name != 'pull_request' }} # Run only if the previous step failed
if: ${{ !cancelled() && failure() && github.event.workflow_run.head_branch == 'main'}} # Run only if the previous step failed
continue-on-error: true
env:
BREAKING_COMMIT: "${{ github.event.workflow_run.head_sha }}"
RUN_URL: "${{ github.event.workflow_run.html_url }}"
RUN_NAME: "${{ github.event.workflow_run.name }}"
BRANCH: "${{ github.event.workflow_run.head_branch }}"
REPO: "${{ github.repository }}"
WORKFLOW_NAME: "${{ github.event.workflow.name }}"
WORKFLOW_HEAD_BRANCH: "${{ github.event.workflow_run.head_branch }}"
GITHUB_ACTOR: "${{ github.actor }}"
with:
vault-url: ${{ secrets.VAULT_ADDR }}
vault-role-id: ${{ secrets.CSP_VAULT_ROLE_ID }}
vault-secret-id: ${{ secrets.CSP_VAULT_SECRET_ID }}
slack-payload: |
{
"text": ":alert: CI ${{ github.event.workflow.name }} is failing on ${{ github.event.workflow_run.head_branch }} :alert:",
"text": ":alert: CI ${{ env.WORKFLOW_NAME }} is failing on ${{ env.WORKFLOW_HEAD_BRANCH }} :alert:",
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": ":alert: CI ${{ github.event.workflow.name }} is failing on ${{ github.event.workflow_run.head_branch }} :alert:",
"text": ":alert: CI ${{ env.WORKFLOW_NAME }} is failing on ${{ env.WORKFLOW_HEAD_BRANCH }} :alert:",
"emoji": true
}
}
Expand All @@ -79,7 +96,7 @@ jobs:
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Commit <https://github.com/elastic/cloudbeat/commit/${{env.BREAKING_COMMIT}}|${{env.BREAKING_COMMIT_SHORT}}> by ${{github.actor}} has failing tests on the `${{env.BRANCH}}` branch."
"text": "Commit <https://github.com/elastic/cloudbeat/commit/${{env.BREAKING_COMMIT}}|${{env.BREAKING_COMMIT_SHORT}}> by ${{env.GITHUB_ACTOR}} has failing tests on the `${{env.BRANCH}}` branch."
}
},
{
Expand Down
Loading