From 18eeef8f90294a596d37e9e50c2681942deb224a Mon Sep 17 00:00:00 2001 From: frederico leal Date: Mon, 23 Sep 2024 16:07:42 +0200 Subject: [PATCH] Adding the github env info to env variables --- .github/workflows/rit.yml | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/.github/workflows/rit.yml b/.github/workflows/rit.yml index 67060d6fe2c..18294e061f1 100644 --- a/.github/workflows/rit.yml +++ b/.github/workflows/rit.yml @@ -111,9 +111,22 @@ jobs: powpeg-node-branch: ${{ env.POWPEG_BRANCH }} rit-branch: ${{ env.RIT_BRANCH }} + - name: Sanitize Branch Name + id: sanitize-branch-name + env: + GITHUB_HEAD_REF: ${{ github.head_ref }} + run: | + # Replace non-alphanumeric characters with underscores and limit to 255 chars + SAFE_BRANCH_NAME=$(echo "${GITHUB_HEAD_REF}" | tr -cd '[:alnum:]_-' | cut -c1-255) + echo "SAFE_BRANCH_NAME=$SAFE_BRANCH_NAME" >> $GITHUB_ENV + - name: Send Slack Notification on Success if: success() && github.event.pull_request.head.repo.owner.login == 'rsksmart' uses: slackapi/slack-github-action@37ebaef184d7626c5f204ab8d3baff4262dd30f0 # v1.27.0 + env: + SLACK_BOT_TOKEN: ${{ secrets.GHA_SLACK_NOTIFICATION_TOKEN }} + safe_branch_name: ${{ env.SAFE_BRANCH_NAME }} + github_run_number: ${{ github.run_number }} with: channel-id: ${{ vars.GHA_SLACK_NOTIFICATION_CHANNEL }} payload: | @@ -121,16 +134,19 @@ jobs: "attachments": [ { "color": "good", - "text": "OK: :+1: Pull request: ${{ github.head_ref }} - [#${{ github.run_number }}] - (${{ env.BUILD_URL }}) - *Branches used* [rskj:`rsksmart#${{ env.RSKJ_BRANCH }}`] [fed:`${{ env.POWPEG_BRANCH }}`] [rootstock-integration-tests:`${{ env.RIT_BRANCH }}`]" + "text": "OK: :+1: Pull request: ${{ safe_branch_name }} - [#${{ github_run_number }}] - (${{ env.BUILD_URL }}) - *Branches used* [rskj:`rsksmart#${{ env.RSKJ_BRANCH }}`] [fed:`${{ env.POWPEG_BRANCH }}`] [rootstock-integration-tests:`${{ env.RIT_BRANCH }}`]" } ] } - env: - SLACK_BOT_TOKEN: ${{ secrets.GHA_SLACK_NOTIFICATION_TOKEN }} + - name: Send Slack Notification on Failure if: failure() && github.event.pull_request.head.repo.owner.login == 'rsksmart' uses: slackapi/slack-github-action@37ebaef184d7626c5f204ab8d3baff4262dd30f0 # v1.27.0 + env: + SLACK_BOT_TOKEN: ${{ secrets.GHA_SLACK_NOTIFICATION_TOKEN }} + safe_branch_name: ${{ env.SAFE_BRANCH_NAME }} + github_run_number: ${{ github.run_number }} with: channel-id: ${{ vars.GHA_SLACK_NOTIFICATION_CHANNEL }} payload: | @@ -138,9 +154,7 @@ jobs: "attachments": [ { "color": "danger", - "text": "FAILED: :robot_face: *Pull request*: ${{ github.head_ref }} - [#${{ github.run_number }}] - (${{ env.BUILD_URL }}) - *Branches used* [rskj:`rsksmart#${{ env.RSKJ_BRANCH }}`] [fed:`${{ env.POWPEG_BRANCH }}`] [rootstock-integration-tests:`${{ env.RIT_BRANCH }}`]" + "text": "FAILED: :robot_face: *Pull request*: ${{ safe_branch_name }} - [#${{ github_run_number }}] - (${{ env.BUILD_URL }}) - *Branches used* [rskj:`rsksmart#${{ env.RSKJ_BRANCH }}`] [fed:`${{ env.POWPEG_BRANCH }}`] [rootstock-integration-tests:`${{ env.RIT_BRANCH }}`]" } ] } - env: - SLACK_BOT_TOKEN: ${{ secrets.GHA_SLACK_NOTIFICATION_TOKEN }}