From b03dba0fe8bc4b10be69393ac89d088469a45c39 Mon Sep 17 00:00:00 2001 From: Oliver Koenig Date: Wed, 15 May 2024 09:56:35 +0200 Subject: [PATCH] watchdog triggers subsets Signed-off-by: Oliver Koenig --- .github/workflows/_ci.yaml | 9 ++-- .github/workflows/_watchdog.yaml | 89 ++++++++++++++++++++++++++++---- .github/workflows/ci.yaml | 14 ----- 3 files changed, 86 insertions(+), 26 deletions(-) diff --git a/.github/workflows/_ci.yaml b/.github/workflows/_ci.yaml index 55d27df52..acc539ba1 100644 --- a/.github/workflows/_ci.yaml +++ b/.github/workflows/_ci.yaml @@ -53,8 +53,6 @@ permissions: jobs: pre-flight: runs-on: ubuntu-22.04 - env: - VALID_SUBSETS: "base core levanter equinox triton upstream-t5x rosetta-t5x upstream-pax rosetta-pax maxtext grok" outputs: BUILD_TRITON: ${{ steps.run-conditions.outputs.BUILD_TRITON }} BUILD_EQUINOX: ${{ steps.run-conditions.outputs.BUILD_EQUINOX }} @@ -72,10 +70,15 @@ jobs: TEST_ROSETTA_PAX: ${{ steps.run-conditions.outputs.TEST_ROSETTA_PAX }} TEST_ROSETTA_T5X: ${{ steps.run-conditions.outputs.TEST_ROSETTA_T5X }} steps: + - name: Check out the repository under ${GITHUB_WORKSPACE} + uses: actions/checkout@v4 + - name: Validate input `TEST_SUBSET` shell: bash run: | - if [[ " $VALID_SUBSETS " != *" ${{ inputs.TEST_SUBSET }} "* ]]; then + valid_subsets=$(yq '.on.workflow_dispatch.inputs.TEST_SUBSET.options | join(",")' .github/workflows/ci.yaml) + + if [[ "$valid_subsets" != *"${{ inputs.TEST_SUBSET }}"* ]]; then echo "Invalid value for \`TEST_SUBSET\` provided. Expected one of: ($valid_inputs), Actual: ${{ inputs.TEST_SUBSET }}" exit 1 fi diff --git a/.github/workflows/_watchdog.yaml b/.github/workflows/_watchdog.yaml index 5399efc39..8e77b3e00 100644 --- a/.github/workflows/_watchdog.yaml +++ b/.github/workflows/_watchdog.yaml @@ -5,13 +5,64 @@ on: types: [created] jobs: - woof: + pre-woof: runs-on: ubuntu-22.04 if: > github.event_name == 'issue_comment' && github.event.issue.pull_request && startsWith(github.event.comment.body, '/ci') && contains('ko3n1g,nouiz,joker-eph,yhtang,terrykong,hemildesai,chaserileyroberts,CliveUnger,DwarKapex,mingxu1067,kocchop,SahilJain314,ashors1,maanug-nv,hmonishN,gspschmid', format('{0},', github.actor)) + outputs: + test_subset: ${{ steps.state.outputs.test_subset }} + steps: + - name: Check out the repository under ${GITHUB_WORKSPACE} + uses: actions/checkout@v4 + + - name: Verify state + shell: bash + id: state + run: | + test_subset=$(echo "${{ github.event.comment.body }} " | cut -d' ' -f2- | tr -d ' ') + valid_test_subsets=$(yq '.on.workflow_dispatch.inputs.TEST_SUBSET.options | join(",")' .github/workflows/ci.yaml) + + if [[ "$valid_test_subsets" != *"$test_subset"* ]]; then + message="Invalid value for '/ci \$TEST_SUBSET' provided ❌. Expected one of: ($valid_test_subsets), Actual: $test_subset" + echo "message=$message" >> "$GITHUB_OUTPUT" + exit 1 + else + message="About to trigger presubmit CI on '$test_subset'. Stay tuned for the next update ⏳." + echo "message=$message" >> "$GITHUB_OUTPUT" + fi + + echo "test_subset=$test_subset" >> "$GITHUB_OUTPUT" + + - name: Update PR issue comment + shell: bash + if: always() + run: | + message="${{ github.event.comment.body}} + + --- + + Watchdog 🤖: ${{ steps.state.outputs.message }} + + " + + # GitHub needs HTML tags instead of newline chars + message="${message//$'\n'/
}" + + # Fire + curl -L \ + -X PATCH \ + -H "Accept: application/vnd.github+json" \ + -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + https://api.github.com/repos/${{ github.repository }}/issues/comments/${{ github.event.comment.id }} \ + -d '{"body":"'"$message"'"}' + + woof: + runs-on: ubuntu-22.04 + needs: pre-woof steps: - name: Get PR number shell: bash @@ -43,22 +94,42 @@ jobs: token: ${{ secrets.GITHUB_TOKEN }} wait-for-completion: false ref: ${{ steps.get-pr-branch.outputs.result }} - - - name: Update `GITHUB_STEP_SUMMARY` - shell: bash - run: echo "Click [here](${{ steps.trigger.outputs.workflow-url }}) to navigate to the workflow run." >> $GITHUB_STEP_SUMMARY - - - name: Update PR issue comment + inputs: '{ "TEST_SUBSET": "${{ needs.pre-woof.outputs.test_subset }}" }' + + - name: Create result message shell: bash + id: result + if: always() run: | - message="${{ github.event.comment.body}} + if [[ "${{ steps.trigger.outcome }}" == "success" ]]; then + dispatch_result_message="presubmit CI was successfully triggered ✅. Click [here](${{ steps.trigger.outputs.workflow-url }}) to navigate to the workflow run." + else + dispatch_result_message="presubmit CI was not successfully triggered ❌. Click [here](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) for more information." + fi + + dispatch_result_message="Watchdog 🤖: $dispatch_result_message" + + echo "${{ steps.message.outputs.message }}" >> $GITHUB_STEP_SUMMARY + + # Fetch original commit issue message + message="${{ github.event.comment.body}}" + + # Remove previous woof-response + message=$(awk -F '' '{print $1}' <<< "$message") + + # Add new woof-response + message="$message --- - Watchdog 🤖: presubmit CI was automatically triggered. Click [here](${{ steps.trigger.outputs.workflow-url }}) to navigate to the workflow run. + $dispatch_result_message + " + + # GitHub needs HTML tags instead of newline chars message="${message//$'\n'/
}" + # Fire curl -L \ -X PATCH \ -H "Accept: application/vnd.github+json" \ diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index a378dca31..9c1b36953 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -11,8 +11,6 @@ on: - synchronize paths-ignore: - '**.md' - issue_comment: - types: [created] workflow_dispatch: inputs: PUBLISH: @@ -68,20 +66,8 @@ env: DEFAULT_MANIFEST_ARTIFACT_NAME: bumped-manifest jobs: - pre-flight: - runs-on: ubuntu-22.04 - if: > - github.event_name == 'issue_comment' && - github.event.issue.pull_request && - contains(github.event.comment.body, '/cicd') - steps: - - name: Triggered by comment - shell: bash - run: exit 0 - metadata: runs-on: ubuntu-22.04 - needs: pre-flight outputs: BUILD_DATE: ${{ steps.date.outputs.BUILD_DATE }} PUBLISH: ${{ steps.if-publish.outputs.PUBLISH }}