From 5529ad7b9b881c7ec74df58ef618347eaddc9e4a Mon Sep 17 00:00:00 2001 From: Wim Date: Thu, 2 May 2024 10:13:42 +0200 Subject: [PATCH 1/2] feat: allow usage of custom message in the slack message --- .github/workflows/notify-slack-end.yml | 5 ++++- .github/workflows/notify-slack-start.yml | 5 ++++- README.md | 2 ++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/workflows/notify-slack-end.yml b/.github/workflows/notify-slack-end.yml index c72f60c..f472cfa 100644 --- a/.github/workflows/notify-slack-end.yml +++ b/.github/workflows/notify-slack-end.yml @@ -2,6 +2,9 @@ name: Release on: workflow_call: inputs: + message: + required: false + type: string channel: required: true type: string @@ -47,7 +50,7 @@ jobs: "type": "section", "text": { "type": "mrkdwn", - "text": "*${{ github.event.repository.name }} - Action - ${{ github.workflow }}* \n <${{ github.event.repository.url }}/commit/${{ github.sha }} | ${{ env.cut_sha }}> (<${{ github.event.repository.url }}/actions/runs/${{ github.run_id }} | open>)" + "text": "*${{ inputs.message && inputs.message || github.event.repository.name }} - ${{ github.workflow }}* \n <${{ github.event.repository.url }}/commit/${{ github.sha }} | ${{ env.cut_sha }}> (<${{ github.event.repository.url }}/actions/runs/${{ github.run_id }} | open>)" } }, { diff --git a/.github/workflows/notify-slack-start.yml b/.github/workflows/notify-slack-start.yml index 82c8a78..6bf4aae 100644 --- a/.github/workflows/notify-slack-start.yml +++ b/.github/workflows/notify-slack-start.yml @@ -2,6 +2,9 @@ name: Release on: workflow_call: inputs: + message: + required: false + type: string channel: required: true type: string @@ -45,7 +48,7 @@ jobs: "type": "section", "text": { "type": "mrkdwn", - "text": "*${{ github.event.repository.name }} - Action - ${{ github.workflow }}* 🚀 \n <${{ github.event.repository.url }}/commit/${{ github.sha }} | ${{ env.cut_sha }}> (<${{ github.event.repository.url }}/actions/runs/${{ github.run_id }} | open>)" + "text": "*${{ inputs.message && inputs.message || github.event.repository.name }} - ${{ github.workflow }}* 🚀 \n <${{ github.event.repository.url }}/commit/${{ github.sha }} | ${{ env.cut_sha }}> (<${{ github.event.repository.url }}/actions/runs/${{ github.run_id }} | open>)" } }, { diff --git a/README.md b/README.md index 1f3d7fe..ea7569b 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,7 @@ jobs: secrets: slackToken: ${{ secrets.SLACK_BOT_RELEASE_TOKEN}} with: + message: CUSTOM_MESSAGE (optional if no message is provided, the repository name will be used) channel: YOUR_CHANNEL_TO_POST_MESSAGES notifyOnlyOnFailure: boolean @@ -39,6 +40,7 @@ jobs: with: time: ${{ needs.notify-start.outputs.time }} result: ${{ needs.release.result }} + message: CUSTOM_MESSAGE (optional if no message is provided, the repository name will be used) channel: YOUR_CHANNEL_TO_POST_MESSAGES notifyOnlyOnFailure: boolean ``` From 7bf805b170c4d3a6b1b48dc3f08c38789479bdd3 Mon Sep 17 00:00:00 2001 From: Wim Date: Mon, 15 Jul 2024 16:37:45 +0200 Subject: [PATCH 2/2] feat: add new workflow to test slack messages --- .github/workflows/test-slack.yml | 41 ++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 .github/workflows/test-slack.yml diff --git a/.github/workflows/test-slack.yml b/.github/workflows/test-slack.yml new file mode 100644 index 0000000..97d1f47 --- /dev/null +++ b/.github/workflows/test-slack.yml @@ -0,0 +1,41 @@ +name: Test message + +on: + workflow_dispatch: + +concurrency: + group: deploy + cancel-in-progress: true + +jobs: + notify-start: + name: Notify release start + uses: ho-nl/release-slack-action/.github/workflows/notify-slack-start.yml@main + secrets: + slackToken: ${{ secrets.SLACK_BOT_RELEASE_TOKEN}} + with: + channel: 12gobiking-test + message: Test + notifyOnlyOnFailure: false + + release: + runs-on: ubuntu-latest + name: release + steps: + - name: sleep + run: sleep 10s + shell: bash + + notify-end: + if: always() + name: Notify release end + needs: [ notify-start, activate-pm2 ] + uses: ho-nl/release-slack-action/.github/workflows/notify-slack-end.yml@main + secrets: + slackToken: ${{ secrets.SLACK_BOT_RELEASE_TOKEN}} + with: + time: ${{ needs.notify-start.outputs.time }} + result: ${{ needs.activate-pm2.result }} + channel: 12gobiking-test + message: Test + notifyOnlyOnFailure: false