From 44acaf74543a868b5e21d9bb4ce98978b89f54e4 Mon Sep 17 00:00:00 2001 From: hrmny <8845940+ForsakenHarmony@users.noreply.github.com> Date: Tue, 14 May 2024 15:18:20 +0200 Subject: [PATCH] chore(CI): escape PR title for slack webhook --- .github/workflows/escape.yml | 24 ++++++++++++++++++++++++ .github/workflows/retry_test.yml | 10 +++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/escape.yml diff --git a/.github/workflows/escape.yml b/.github/workflows/escape.yml new file mode 100644 index 00000000000000..754f0df67a2f76 --- /dev/null +++ b/.github/workflows/escape.yml @@ -0,0 +1,24 @@ +name: escape + +on: + push: + branches: ['canary'] + pull_request: + types: [opened, synchronize] + +jobs: + escape: + name: escape + runs-on: ubuntu-latest + steps: + - name: escape PR title in js + env: + PR_TITLE: ${{ github.event.pull_request.title }} + shell: bash + run: | + node -e 'console.log(`title=${JSON.stringify({ title: process.env.PR_TITLE })}`)' + + - name: escape PR title via expression + shell: bash + run: | + echo ${{ toJSON({ title: github.event.pull_request.title }) }} diff --git a/.github/workflows/retry_test.yml b/.github/workflows/retry_test.yml index dd66ddf80220d6..9f75eb2859ebf7 100644 --- a/.github/workflows/retry_test.yml +++ b/.github/workflows/retry_test.yml @@ -34,6 +34,14 @@ jobs: if: ${{ github.event.workflow_run.conclusion == 'failure' && github.event.workflow_run.run_attempt >= 3 && !github.event.workflow_run.head_repository.fork }} runs-on: ubuntu-latest steps: + - name: escape PR title + id: title + env: + PR_TITLE: ${{ github.event.workflow_run.display_title }} + shell: bash + run: | + node -e 'console.log(`title=${JSON.stringify(process.env.TITLE)}`)' >> "$GITHUB_OUTPUT" + - name: send webhook uses: slackapi/slack-github-action@v1.25.0 with: @@ -42,7 +50,7 @@ jobs: # (through slightly hacky means). payload: | { - "commit_title": "${{ github.event.workflow_run.display_title }}", + "commit_title": ${{ steps.title.outputs.title }}, "commit_url": "github.com/${{ github.repository }}/commit/${{ github.event.workflow_run.head_sha }}", "workflow_run_url": "github.com/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}/attempts/${{ github.event.workflow_run.run_attempt }}" }