From e3ade7e2799ee44433281a58eb52270efd8f9bce Mon Sep 17 00:00:00 2001 From: JP Simard Date: Tue, 23 Aug 2022 15:10:41 -0400 Subject: [PATCH] ci: use 'jpsim/retest' GitHub Action for `/retest` command (#2491) Defined here: https://github.com/jpsim/retest It has a number of advantages over the previous in-repo implementation: 1. Runs faster because it runs in a node.js environment and doesn't require pulling and running a Docker container 2. Written in Typescript instead of bash/jq 3. Has unit tests 4. _Potentially_ will be better maintained if it ends up being used & improved by other people unrelated to their relationship with Envoy Mobile Otherwise should be at feature parity with the previous implementation. Signed-off-by: JP Simard --- .github/actions/retest-action/Dockerfile | 7 --- .github/actions/retest-action/action.yml | 11 ---- .github/actions/retest-action/entrypoint.sh | 69 --------------------- .github/workflows/commands.yml | 8 +-- 4 files changed, 3 insertions(+), 92 deletions(-) delete mode 100644 .github/actions/retest-action/Dockerfile delete mode 100644 .github/actions/retest-action/action.yml delete mode 100755 .github/actions/retest-action/entrypoint.sh diff --git a/.github/actions/retest-action/Dockerfile b/.github/actions/retest-action/Dockerfile deleted file mode 100644 index 187be63729..0000000000 --- a/.github/actions/retest-action/Dockerfile +++ /dev/null @@ -1,7 +0,0 @@ -FROM alpine:3.10 - -RUN apk add --no-cache bash curl jq - -COPY entrypoint.sh /entrypoint.sh - -ENTRYPOINT ["/entrypoint.sh"] diff --git a/.github/actions/retest-action/action.yml b/.github/actions/retest-action/action.yml deleted file mode 100644 index b77683dcf1..0000000000 --- a/.github/actions/retest-action/action.yml +++ /dev/null @@ -1,11 +0,0 @@ -name: 'Re-Test' -description: 'Re-Runs the failing jobs from the last workflow for a PR' -inputs: - token: - description: 'GitHub API Token' - required: true -runs: - using: 'docker' - image: 'Dockerfile' - env: - GITHUB_TOKEN: ${{ inputs.token }} diff --git a/.github/actions/retest-action/entrypoint.sh b/.github/actions/retest-action/entrypoint.sh deleted file mode 100755 index 8dcb98b5c1..0000000000 --- a/.github/actions/retest-action/entrypoint.sh +++ /dev/null @@ -1,69 +0,0 @@ -#!/bin/bash - -set -euo pipefail - -# Check if this is a PR event - -if ! jq -e '.issue.pull_request' "${GITHUB_EVENT_PATH}"; then - echo "Not a PR... Exiting." - exit 0 -fi - -# Check if the comment is "/retest" - -if [ "$(jq -r '.comment.body' "${GITHUB_EVENT_PATH}")" != "/retest" ]; then - echo "Nothing to do... Exiting." - exit 0 -fi - -# Get the PR details - -PR_URL=$(jq -r '.issue.pull_request.url' "${GITHUB_EVENT_PATH}") - -curl --silent --request GET \ - --url "${PR_URL}" \ - --header "authorization: Bearer ${GITHUB_TOKEN}" \ - --header "content-type: application/json" > pr.json - -# Extract useful PR info - -PR_NUMBER=$(jq -r '.number' pr.json) -PR_BRANCH=$(jq -r '.head.ref' pr.json) -PR_COMMIT=$(jq -r '.head.sha' pr.json) - -echo "Running /retest command for PR #${PR_NUMBER}" -echo "PR branch: ${PR_BRANCH}" -echo "Latest PR commit: ${PR_COMMIT}" - -# Get failed Workflow runs for the latest PR commit - -curl --silent --request GET \ - --url "https://api.github.com/repos/envoyproxy/envoy-mobile/actions/runs?branch=${PR_BRANCH}" \ - --header "authorization: Bearer ${GITHUB_TOKEN}" \ - --header "content-type: application/json" > runs.json -jq ".workflow_runs[] | select(.head_sha == \"${PR_COMMIT}\") | select((.conclusion == \"cancelled\") or (.conclusion == \"failure\") or (.conclusion == \"timed_out\"))" runs.json > failed_runs.json -jq -c ". | {name: .name, url: .url}" failed_runs.json > failed_runs_compact.json - -# Iterate over each failed run and retry its failed jobs - -while read -r failed_run; do - echo "$failed_run" > line.json - RUN_NAME="$(jq -r '.name' line.json)" - echo "Retrying failed job: ${RUN_NAME}" - RUN_URL="$(jq -r '.url' line.json)" - curl --silent --request POST \ - --url "${RUN_URL}/rerun-failed-jobs" \ - --header "authorization: Bearer ${GITHUB_TOKEN}" \ - --header "content-type: application/json" -done < failed_runs_compact.json - -# Add a rocket emoji reaction to the "/retest" comment to inform that this script finished running - -REACTION_URL="$(jq -r '.comment.url' "${GITHUB_EVENT_PATH}")/reactions" - -curl --silent --request POST \ - --url "${REACTION_URL}" \ - --header "authorization: Bearer ${GITHUB_TOKEN}" \ - --header "accept: application/vnd.github.squirrel-girl-preview+json" \ - --header "content-type: application/json" \ - --data '{ "content" : "rocket" }' diff --git a/.github/workflows/commands.yml b/.github/workflows/commands.yml index eb10f33bff..2231550a7f 100644 --- a/.github/workflows/commands.yml +++ b/.github/workflows/commands.yml @@ -5,12 +5,10 @@ on: jobs: retest: + name: Retest runs-on: ubuntu-latest steps: - - name: Check out code - uses: actions/checkout@v2 - - - name: Re-Test Action - uses: ./.github/actions/retest-action + # jpsim/retest@v1 + - uses: jpsim/retest@c158dec0a7f67cb85f8367468dc8a9a75308bb7f with: token: ${{ secrets.GITHUB_TOKEN }}