From 85ade5c878ae5a8ff7d2b50cbb2de106d9b44081 Mon Sep 17 00:00:00 2001 From: Silvano Cerza <3314350+silvanocerza@users.noreply.github.com> Date: Wed, 29 Mar 2023 09:24:41 +0200 Subject: [PATCH] Fix Slack messages formatting on job failure (#4520) --- .../config/failure-message-slack-payload.json | 48 +++ .github/workflows/compliance.yml | 44 +- .github/workflows/examples-tests.yml | 66 ++- .github/workflows/rest_api_tests.yml | 44 +- .github/workflows/tests.yml | 384 ++---------------- 5 files changed, 102 insertions(+), 484 deletions(-) create mode 100644 .github/config/failure-message-slack-payload.json diff --git a/.github/config/failure-message-slack-payload.json b/.github/config/failure-message-slack-payload.json new file mode 100644 index 000000000..1a947777d --- /dev/null +++ b/.github/config/failure-message-slack-payload.json @@ -0,0 +1,48 @@ +{ + "blocks": [ + { + "type": "context", + "elements": [ + { + "type": "image", + "image_url": "https://avatars.githubusercontent.com/u/${{ github.author_id }}?v=4", + "alt_text": "Actor" + }, + { + "type": "mrkdwn", + "text": "**" + } + ] + }, + { + "type": "section", + "text": { + "type": "mrkdwn", + "text": "Job ${{ github.job }} in workflow " + } + }, + { + "type": "context", + "elements": [ + { + "type": "mrkdwn", + "text": "Triggered by ${{ github.event_name }} for ${{ github.ref_type }} `${{ github.ref_name }}`" + } + ] + }, + { + "type": "context", + "elements": [ + { + "type": "image", + "image_url": "https://github.githubassets.com/favicons/favicon.png", + "alt_text": "Github logo" + }, + { + "type": "mrkdwn", + "text": " Run " + } + ] + } + ] +} diff --git a/.github/workflows/compliance.yml b/.github/workflows/compliance.yml index 5c09b6a5b..27d841ef4 100644 --- a/.github/workflows/compliance.yml +++ b/.github/workflows/compliance.yml @@ -52,27 +52,7 @@ jobs: - uses: slackapi/slack-github-action@v1.23.0 if: failure() && github.ref == 'refs/heads/main' with: - payload: | - { - "text": ":x: Job ${{ env.GITHUB_JOB }} failed for ${{ github.ref_type }} ${{ github.ref_name }}", - "blocks": [ - { - "type": "header", - "text": { - "type": "plain_text", - "text": ":x: Job ${{ env.GITHUB_JOB }} failed for ${{ github.ref_type }} ${{ github.ref_name }}", - "emoji": true - } - }, - { - "type": "section", - "text": { - "type": "mrkdwn", - "text": "Click ** for more details " - } - } - ] - } + payload-file-path: .github/config/failure-message-slack-payload.json check-license-compliance-gpu: if: ${{ !github.event.pull_request.head.repo.fork }} @@ -112,24 +92,4 @@ jobs: - uses: slackapi/slack-github-action@v1.23.0 if: failure() && github.ref == 'refs/heads/main' with: - payload: | - { - "text": ":x: Job ${{ env.GITHUB_JOB }} failed for ${{ github.ref_type }} ${{ github.ref_name }}", - "blocks": [ - { - "type": "header", - "text": { - "type": "plain_text", - "text": ":x: Job ${{ env.GITHUB_JOB }} failed for ${{ github.ref_type }} ${{ github.ref_name }}", - "emoji": true - } - }, - { - "type": "section", - "text": { - "type": "mrkdwn", - "text": "Click ** for more details " - } - } - ] - } + payload-file-path: .github/config/failure-message-slack-payload.json diff --git a/.github/workflows/examples-tests.yml b/.github/workflows/examples-tests.yml index 2230c7457..2118b6d09 100644 --- a/.github/workflows/examples-tests.yml +++ b/.github/workflows/examples-tests.yml @@ -21,51 +21,31 @@ env: jobs: tests: - name: Examples - runs-on: ubuntu-latest - services: - elasticsearch: - image: elasticsearch:7.17.6 - env: - discovery.type: "single-node" - ES_JAVA_OPTS: "-Xms128m -Xmx256m" - ports: - - 9200:9200 + name: Examples + runs-on: ubuntu-latest + services: + elasticsearch: + image: elasticsearch:7.17.6 + env: + discovery.type: "single-node" + ES_JAVA_OPTS: "-Xms128m -Xmx256m" + ports: + - 9200:9200 - steps: - - uses: actions/checkout@v3 + steps: + - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 - with: - python-version: ${{ env.PYTHON_VERSION }} + - uses: actions/setup-python@v4 + with: + python-version: ${{ env.PYTHON_VERSION }} - - name: Install Haystack - run: pip install .[all] + - name: Install Haystack + run: pip install .[all] - - name: Run - run: pytest examples/ + - name: Run + run: pytest examples/ - - uses: slackapi/slack-github-action@v1.23.0 - if: failure() && github.ref == 'refs/heads/main' - with: - payload: | - { - "text": ":x: Job ${{ env.GITHUB_JOB }} failed for ${{ github.ref_type }} ${{ github.ref_name }}", - "blocks": [ - { - "type": "header", - "text": { - "type": "plain_text", - "text": ":x: Job ${{ env.GITHUB_JOB }} failed for ${{ github.ref_type }} ${{ github.ref_name }}", - "emoji": true - } - }, - { - "type": "section", - "text": { - "type": "mrkdwn", - "text": "Click ** for more details " - } - } - ] - } + - uses: slackapi/slack-github-action@v1.23.0 + if: failure() && github.ref == 'refs/heads/main' + with: + payload-file-path: .github/config/failure-message-slack-payload.json diff --git a/.github/workflows/rest_api_tests.yml b/.github/workflows/rest_api_tests.yml index 58e3c7115..a48671211 100644 --- a/.github/workflows/rest_api_tests.yml +++ b/.github/workflows/rest_api_tests.yml @@ -66,27 +66,7 @@ jobs: - uses: slackapi/slack-github-action@v1.23.0 if: failure() && github.ref == 'refs/heads/main' with: - payload: | - { - "text": ":x: Job ${{ env.GITHUB_JOB }} failed for ${{ github.ref_type }} ${{ github.ref_name }}", - "blocks": [ - { - "type": "header", - "text": { - "type": "plain_text", - "text": ":x: Job ${{ env.GITHUB_JOB }} failed for ${{ github.ref_type }} ${{ github.ref_name }}", - "emoji": true - } - }, - { - "type": "section", - "text": { - "type": "mrkdwn", - "text": "Click ** for more details " - } - } - ] - } + payload-file-path: .github/config/failure-message-slack-payload.json rest_api: needs: black @@ -118,24 +98,4 @@ jobs: - uses: slackapi/slack-github-action@v1.23.0 if: failure() && github.ref == 'refs/heads/main' with: - payload: | - { - "text": ":x: Job ${{ env.GITHUB_JOB }} failed for ${{ github.ref_type }} ${{ github.ref_name }}", - "blocks": [ - { - "type": "header", - "text": { - "type": "plain_text", - "text": ":x: Job ${{ env.GITHUB_JOB }} failed for ${{ github.ref_type }} ${{ github.ref_name }}", - "emoji": true - } - }, - { - "type": "section", - "text": { - "type": "mrkdwn", - "text": "Click ** for more details " - } - } - ] - } + payload-file-path: .github/config/failure-message-slack-payload.json diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 76ad6e00f..50d09882b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -80,27 +80,7 @@ jobs: - uses: slackapi/slack-github-action@v1.23.0 if: failure() && github.ref == 'refs/heads/main' with: - payload: | - { - "text": ":x: Job ${{ env.GITHUB_JOB }} failed for ${{ github.ref_type }} ${{ github.ref_name }}", - "blocks": [ - { - "type": "header", - "text": { - "type": "plain_text", - "text": ":x: Job ${{ env.GITHUB_JOB }} failed for ${{ github.ref_type }} ${{ github.ref_name }}", - "emoji": true - } - }, - { - "type": "section", - "text": { - "type": "mrkdwn", - "text": "Click ** for more details " - } - } - ] - } + payload-file-path: .github/config/failure-message-slack-payload.json unit-tests: name: Unit / ${{ matrix.topic }} / ${{ matrix.os }} @@ -134,27 +114,8 @@ jobs: - uses: slackapi/slack-github-action@v1.23.0 if: failure() && github.ref == 'refs/heads/main' with: - payload: | - { - "text": ":x: Job ${{ env.GITHUB_JOB }} failed for ${{ github.ref_type }} ${{ github.ref_name }}", - "blocks": [ - { - "type": "header", - "text": { - "type": "plain_text", - "text": ":x: Job ${{ env.GITHUB_JOB }} failed for ${{ github.ref_type }} ${{ github.ref_name }}", - "emoji": true - } - }, - { - "type": "section", - "text": { - "type": "mrkdwn", - "text": "Click ** for more details " - } - } - ] - } + payload-file-path: .github/config/failure-message-slack-payload.json + integration-tests-elasticsearch: name: Integration / Elasticsearch / ${{ matrix.os }} @@ -190,27 +151,8 @@ jobs: - uses: slackapi/slack-github-action@v1.23.0 if: failure() && github.ref == 'refs/heads/main' with: - payload: | - { - "text": ":x: Job ${{ env.GITHUB_JOB }} failed for ${{ github.ref_type }} ${{ github.ref_name }}", - "blocks": [ - { - "type": "header", - "text": { - "type": "plain_text", - "text": ":x: Job ${{ env.GITHUB_JOB }} failed for ${{ github.ref_type }} ${{ github.ref_name }}", - "emoji": true - } - }, - { - "type": "section", - "text": { - "type": "mrkdwn", - "text": "Click ** for more details " - } - } - ] - } + payload-file-path: .github/config/failure-message-slack-payload.json + integration-tests-sql: name: Integration / SQL / ${{ matrix.os }} @@ -238,27 +180,8 @@ jobs: - uses: slackapi/slack-github-action@v1.23.0 if: failure() && github.ref == 'refs/heads/main' with: - payload: | - { - "text": ":x: Job ${{ env.GITHUB_JOB }} failed for ${{ github.ref_type }} ${{ github.ref_name }}", - "blocks": [ - { - "type": "header", - "text": { - "type": "plain_text", - "text": ":x: Job ${{ env.GITHUB_JOB }} failed for ${{ github.ref_type }} ${{ github.ref_name }}", - "emoji": true - } - }, - { - "type": "section", - "text": { - "type": "mrkdwn", - "text": "Click ** for more details " - } - } - ] - } + payload-file-path: .github/config/failure-message-slack-payload.json + integration-tests-opensearch: name: Integration / Opensearch / ${{ matrix.os }} @@ -294,27 +217,8 @@ jobs: - uses: slackapi/slack-github-action@v1.23.0 if: failure() && github.ref == 'refs/heads/main' with: - payload: | - { - "text": ":x: Job ${{ env.GITHUB_JOB }} failed for ${{ github.ref_type }} ${{ github.ref_name }}", - "blocks": [ - { - "type": "header", - "text": { - "type": "plain_text", - "text": ":x: Job ${{ env.GITHUB_JOB }} failed for ${{ github.ref_type }} ${{ github.ref_name }}", - "emoji": true - } - }, - { - "type": "section", - "text": { - "type": "mrkdwn", - "text": "Click ** for more details " - } - } - ] - } + payload-file-path: .github/config/failure-message-slack-payload.json + integration-tests-dc: name: Integration / dC / ${{ matrix.os }} @@ -342,27 +246,8 @@ jobs: - uses: slackapi/slack-github-action@v1.23.0 if: failure() && github.ref == 'refs/heads/main' with: - payload: | - { - "text": ":x: Job ${{ env.GITHUB_JOB }} failed for ${{ github.ref_type }} ${{ github.ref_name }}", - "blocks": [ - { - "type": "header", - "text": { - "type": "plain_text", - "text": ":x: Job ${{ env.GITHUB_JOB }} failed for ${{ github.ref_type }} ${{ github.ref_name }}", - "emoji": true - } - }, - { - "type": "section", - "text": { - "type": "mrkdwn", - "text": "Click ** for more details " - } - } - ] - } + payload-file-path: .github/config/failure-message-slack-payload.json + integration-tests-faiss: name: Integration / faiss / ${{ matrix.os }} @@ -390,27 +275,8 @@ jobs: - uses: slackapi/slack-github-action@v1.23.0 if: failure() && github.ref == 'refs/heads/main' with: - payload: | - { - "text": ":x: Job ${{ env.GITHUB_JOB }} failed for ${{ github.ref_type }} ${{ github.ref_name }}", - "blocks": [ - { - "type": "header", - "text": { - "type": "plain_text", - "text": ":x: Job ${{ env.GITHUB_JOB }} failed for ${{ github.ref_type }} ${{ github.ref_name }}", - "emoji": true - } - }, - { - "type": "section", - "text": { - "type": "mrkdwn", - "text": "Click ** for more details " - } - } - ] - } + payload-file-path: .github/config/failure-message-slack-payload.json + integration-tests-weaviate: name: Integration / Weaviate / ${{ matrix.os }} @@ -448,27 +314,8 @@ jobs: - uses: slackapi/slack-github-action@v1.23.0 if: failure() && github.ref == 'refs/heads/main' with: - payload: | - { - "text": ":x: Job ${{ env.GITHUB_JOB }} failed for ${{ github.ref_type }} ${{ github.ref_name }}", - "blocks": [ - { - "type": "header", - "text": { - "type": "plain_text", - "text": ":x: Job ${{ env.GITHUB_JOB }} failed for ${{ github.ref_type }} ${{ github.ref_name }}", - "emoji": true - } - }, - { - "type": "section", - "text": { - "type": "mrkdwn", - "text": "Click ** for more details " - } - } - ] - } + payload-file-path: .github/config/failure-message-slack-payload.json + integration-tests-pinecone: name: Integration / pinecone / ${{ matrix.os }} @@ -498,27 +345,7 @@ jobs: - uses: slackapi/slack-github-action@v1.23.0 if: failure() && github.ref == 'refs/heads/main' with: - payload: | - { - "text": ":x: Job ${{ env.GITHUB_JOB }} failed for ${{ github.ref_type }} ${{ github.ref_name }}", - "blocks": [ - { - "type": "header", - "text": { - "type": "plain_text", - "text": ":x: Job ${{ env.GITHUB_JOB }} failed for ${{ github.ref_type }} ${{ github.ref_name }}", - "emoji": true - } - }, - { - "type": "section", - "text": { - "type": "mrkdwn", - "text": "Click ** for more details " - } - } - ] - } + payload-file-path: .github/config/failure-message-slack-payload.json integration-tests-milvus: name: Integration / Milvus / ${{ matrix.os }} @@ -557,27 +384,7 @@ jobs: - uses: slackapi/slack-github-action@v1.23.0 if: failure() && github.ref == 'refs/heads/main' with: - payload: | - { - "text": ":x: Job ${{ env.GITHUB_JOB }} failed for ${{ github.ref_type }} ${{ github.ref_name }}", - "blocks": [ - { - "type": "header", - "text": { - "type": "plain_text", - "text": ":x: Job ${{ env.GITHUB_JOB }} failed for ${{ github.ref_type }} ${{ github.ref_name }}", - "emoji": true - } - }, - { - "type": "section", - "text": { - "type": "mrkdwn", - "text": "Click ** for more details " - } - } - ] - } + payload-file-path: .github/config/failure-message-slack-payload.json integration-tests-memory: name: Integration / memory / ${{ matrix.os }} @@ -605,27 +412,8 @@ jobs: - uses: slackapi/slack-github-action@v1.23.0 if: failure() && github.ref == 'refs/heads/main' with: - payload: | - { - "text": ":x: Job ${{ env.GITHUB_JOB }} failed for ${{ github.ref_type }} ${{ github.ref_name }}", - "blocks": [ - { - "type": "header", - "text": { - "type": "plain_text", - "text": ":x: Job ${{ env.GITHUB_JOB }} failed for ${{ github.ref_type }} ${{ github.ref_name }}", - "emoji": true - } - }, - { - "type": "section", - "text": { - "type": "mrkdwn", - "text": "Click ** for more details " - } - } - ] - } + payload-file-path: .github/config/failure-message-slack-payload.json + integration-tests-promptnode: name: Integration / PromptNode / ${{ matrix.os }} @@ -653,27 +441,8 @@ jobs: - uses: slackapi/slack-github-action@v1.23.0 if: failure() && github.ref == 'refs/heads/main' with: - payload: | - { - "text": ":x: Job ${{ env.GITHUB_JOB }} failed for ${{ github.ref_type }} ${{ github.ref_name }}", - "blocks": [ - { - "type": "header", - "text": { - "type": "plain_text", - "text": ":x: Job ${{ env.GITHUB_JOB }} failed for ${{ github.ref_type }} ${{ github.ref_name }}", - "emoji": true - } - }, - { - "type": "section", - "text": { - "type": "mrkdwn", - "text": "Click ** for more details " - } - } - ] - } + payload-file-path: .github/config/failure-message-slack-payload.json + integration-tests-agents: name: Integration / Agents / ${{ matrix.os }} @@ -701,27 +470,8 @@ jobs: - uses: slackapi/slack-github-action@v1.23.0 if: failure() && github.ref == 'refs/heads/main' with: - payload: | - { - "text": ":x: Job ${{ env.GITHUB_JOB }} failed for ${{ github.ref_type }} ${{ github.ref_name }}", - "blocks": [ - { - "type": "header", - "text": { - "type": "plain_text", - "text": ":x: Job ${{ env.GITHUB_JOB }} failed for ${{ github.ref_type }} ${{ github.ref_name }}", - "emoji": true - } - }, - { - "type": "section", - "text": { - "type": "mrkdwn", - "text": "Click ** for more details " - } - } - ] - } + payload-file-path: .github/config/failure-message-slack-payload.json + # @@ -769,27 +519,7 @@ jobs: - uses: slackapi/slack-github-action@v1.23.0 if: failure() && github.ref == 'refs/heads/main' with: - payload: | - { - "text": ":x: Job ${{ env.GITHUB_JOB }} failed for ${{ github.ref_type }} ${{ github.ref_name }}", - "blocks": [ - { - "type": "header", - "text": { - "type": "plain_text", - "text": ":x: Job ${{ env.GITHUB_JOB }} failed for ${{ github.ref_type }} ${{ github.ref_name }}", - "emoji": true - } - }, - { - "type": "section", - "text": { - "type": "mrkdwn", - "text": "Click ** for more details " - } - } - ] - } + payload-file-path: .github/config/failure-message-slack-payload.json unit-tests-windows: needs: black @@ -828,27 +558,7 @@ jobs: - uses: slackapi/slack-github-action@v1.23.0 if: failure() && github.ref == 'refs/heads/main' with: - payload: | - { - "text": ":x: Job ${{ env.GITHUB_JOB }} failed for ${{ github.ref_type }} ${{ github.ref_name }}", - "blocks": [ - { - "type": "header", - "text": { - "type": "plain_text", - "text": ":x: Job ${{ env.GITHUB_JOB }} failed for ${{ github.ref_type }} ${{ github.ref_name }}", - "emoji": true - } - }, - { - "type": "section", - "text": { - "type": "mrkdwn", - "text": "Click ** for more details " - } - } - ] - } + payload-file-path: .github/config/failure-message-slack-payload.json integration-tests-linux: needs: @@ -939,27 +649,7 @@ jobs: - uses: slackapi/slack-github-action@v1.23.0 if: failure() && github.ref == 'refs/heads/main' with: - payload: | - { - "text": ":x: Job ${{ env.GITHUB_JOB }} failed for ${{ github.ref_type }} ${{ github.ref_name }}", - "blocks": [ - { - "type": "header", - "text": { - "type": "plain_text", - "text": ":x: Job ${{ env.GITHUB_JOB }} failed for ${{ github.ref_type }} ${{ github.ref_name }}", - "emoji": true - } - }, - { - "type": "section", - "text": { - "type": "mrkdwn", - "text": "Click ** for more details " - } - } - ] - } + payload-file-path: .github/config/failure-message-slack-payload.json integration-tests-windows: needs: @@ -1012,27 +702,7 @@ jobs: - uses: slackapi/slack-github-action@v1.23.0 if: failure() && github.ref == 'refs/heads/main' with: - payload: | - { - "text": ":x: Job ${{ env.GITHUB_JOB }} failed for ${{ github.ref_type }} ${{ github.ref_name }}", - "blocks": [ - { - "type": "header", - "text": { - "type": "plain_text", - "text": ":x: Job ${{ env.GITHUB_JOB }} failed for ${{ github.ref_type }} ${{ github.ref_name }}", - "emoji": true - } - }, - { - "type": "section", - "text": { - "type": "mrkdwn", - "text": "Click ** for more details " - } - } - ] - } + payload-file-path: .github/config/failure-message-slack-payload.json catch-all: name: Catch-all check