From 19e9dfd0fa70feaeb307c6cb0ea27a22a13f27ae Mon Sep 17 00:00:00 2001 From: Sergei Petrosian Date: Fri, 2 Aug 2024 12:15:38 +0200 Subject: [PATCH 1/4] Fixes for PENDING_RUN and GITHUB_ORG --- .github/workflows/tft.yml | 2 +- .github/workflows/tft_citest_bad.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tft.yml b/.github/workflows/tft.yml index 9fec535..942d787 100644 --- a/.github/workflows/tft.yml +++ b/.github/workflows/tft.yml @@ -157,7 +157,7 @@ jobs: pipeline_settings: '{ "type": "tmt-multihost" }' variables: "ANSIBLE_VER=${{ matrix.ansible_version }};\ REPO_NAME=${{ github.event.repository.name }};\ - GITHUB_ORG=linux-system-roles;\ + GITHUB_ORG=${{ github.repository_owner }};\ PR_NUM=${{ github.event.issue.number }};\ ARTIFACTS_DIR=${{ steps.set_vars.outputs.ARTIFACTS_DIR }};\ ARTIFACTS_URL=${{ steps.set_vars.outputs.ARTIFACTS_URL }};\ diff --git a/.github/workflows/tft_citest_bad.yml b/.github/workflows/tft_citest_bad.yml index 41d314e..5cee060 100644 --- a/.github/workflows/tft_citest_bad.yml +++ b/.github/workflows/tft_citest_bad.yml @@ -26,7 +26,7 @@ jobs: run: | PENDING_RUN=$(gh api "repos/$REPO/actions/workflows/tft.yml/runs?event=issue_comment" \ | jq -r '[.workflow_runs[] | select(.display_title="$PR_TITLE") | select(.status == "pending" or .status == "queued" or .status == "in_progress") | .id][0]') - if [ "$RUN_ID" = "null" ]; then # if pending run don't exist, take the last run with failure state + if [ "$PENDING_RUN" = "null" ]; then # if pending run don't exist, take the last run with failure state RUN_ID=$(gh api "repos/$REPO/actions/workflows/tft.yml/runs?event=issue_comment" \ | jq -r '[.workflow_runs[] | select( .conclusion == "failure" ) | select ( .display_title="$PR_TITLE" ) | .id][0]') echo "Re-running workflow $RUN_ID" From d267ba4946dd17a6a4b5b74c1565f76665d361ed Mon Sep 17 00:00:00 2001 From: Sergei Petrosian Date: Fri, 2 Aug 2024 12:55:32 +0200 Subject: [PATCH 2/4] Fix jq's select --- .github/workflows/tft_citest_bad.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tft_citest_bad.yml b/.github/workflows/tft_citest_bad.yml index 5cee060..bb6d977 100644 --- a/.github/workflows/tft_citest_bad.yml +++ b/.github/workflows/tft_citest_bad.yml @@ -25,10 +25,11 @@ jobs: PR_TITLE: ${{ github.event.issue.title }} run: | PENDING_RUN=$(gh api "repos/$REPO/actions/workflows/tft.yml/runs?event=issue_comment" \ - | jq -r '[.workflow_runs[] | select(.display_title="$PR_TITLE") | select(.status == "pending" or .status == "queued" or .status == "in_progress") | .id][0]') + | jq -r "[.workflow_runs[] | select( .display_title == \"$PR_TITLE\") | \ + select(.status == \"pending\" or .status == \"queued\" or .status == \"in_progress\") | .id][0]") if [ "$PENDING_RUN" = "null" ]; then # if pending run don't exist, take the last run with failure state RUN_ID=$(gh api "repos/$REPO/actions/workflows/tft.yml/runs?event=issue_comment" \ - | jq -r '[.workflow_runs[] | select( .conclusion == "failure" ) | select ( .display_title="$PR_TITLE" ) | .id][0]') + | jq -r "[.workflow_runs[] | select( .display_title == \"$PR_TITLE\" ) | select( .conclusion == \"failure\" ) | .id][0]") echo "Re-running workflow $RUN_ID" gh api --method POST repos/$REPO/actions/runs/$RUN_ID/rerun-failed-jobs else From de00b1ee1becab3f51a9e5926722605488af580e Mon Sep 17 00:00:00 2001 From: Sergei Petrosian Date: Fri, 2 Aug 2024 13:16:15 +0200 Subject: [PATCH 3/4] Move concurrency to the first job --- .github/workflows/tft.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/tft.yml b/.github/workflows/tft.yml index 942d787..83088d3 100644 --- a/.github/workflows/tft.yml +++ b/.github/workflows/tft.yml @@ -8,14 +8,14 @@ permissions: contents: read # This is required for the ability to create/update the Pull request status statuses: write -# The concurrency key is used to prevent multiple workflows from running at the same time -concurrency: - # group name contains reponame-pr_num to allow simualteneous runs in different PRs - group: testing-farm-${{ github.event.repository.name }}-${{ github.event.issue.number }} - cancel-in-progress: true jobs: prepare_vars: name: Get info from role and PR to determine if and how to test + # The concurrency key is used to prevent multiple workflows from running at the same time + concurrency: + # group name contains reponame-pr_num to allow simualteneous runs in different PRs + group: testing-farm-${{ github.event.repository.name }}-${{ github.event.issue.number }} + cancel-in-progress: true # Let's schedule tests only on user request. NOT automatically. # Only repository owner or member can schedule tests if: | From f15967a97b1326b7d1bf5d65c47db31235780a83 Mon Sep 17 00:00:00 2001 From: Sergei Petrosian Date: Fri, 2 Aug 2024 15:06:39 +0200 Subject: [PATCH 4/4] Improve rerunning workflows --- .github/workflows/tft_citest_bad.yml | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/.github/workflows/tft_citest_bad.yml b/.github/workflows/tft_citest_bad.yml index bb6d977..7bd42f5 100644 --- a/.github/workflows/tft_citest_bad.yml +++ b/.github/workflows/tft_citest_bad.yml @@ -27,11 +27,16 @@ jobs: PENDING_RUN=$(gh api "repos/$REPO/actions/workflows/tft.yml/runs?event=issue_comment" \ | jq -r "[.workflow_runs[] | select( .display_title == \"$PR_TITLE\") | \ select(.status == \"pending\" or .status == \"queued\" or .status == \"in_progress\") | .id][0]") - if [ "$PENDING_RUN" = "null" ]; then # if pending run don't exist, take the last run with failure state - RUN_ID=$(gh api "repos/$REPO/actions/workflows/tft.yml/runs?event=issue_comment" \ - | jq -r "[.workflow_runs[] | select( .display_title == \"$PR_TITLE\" ) | select( .conclusion == \"failure\" ) | .id][0]") - echo "Re-running workflow $RUN_ID" - gh api --method POST repos/$REPO/actions/runs/$RUN_ID/rerun-failed-jobs - else + # if pending run don't exist, take the last run with failure state + if [ "$PENDING_RUN" != "null" ]; then echo "The workflow $PENDING_RUN is still running, wait for it to finish to re-run" + exit 1 fi + RUN_ID=$(gh api "repos/$REPO/actions/workflows/tft.yml/runs?event=issue_comment" \ + | jq -r "[.workflow_runs[] | select( .display_title == \"$PR_TITLE\" ) | select( .conclusion == \"failure\" ) | .id][0]") + if [ "$RUN_ID" = "null" ]; then + echo "Failed workflow not found, exitting" + exit 1 + fi + echo "Re-running workflow $RUN_ID" + gh api --method POST repos/$REPO/actions/runs/$RUN_ID/rerun-failed-jobs