diff --git a/.github/workflows/branch-builder.yml b/.github/workflows/branch-builder.yml new file mode 100644 index 0000000..312cada --- /dev/null +++ b/.github/workflows/branch-builder.yml @@ -0,0 +1,30 @@ +name: Branch Builder + +on: + pull_request: + types: [opened, reopened, synchronize] + push: + branches: [ main ] + tags-ignore: "**" + workflow_dispatch: +env: + BRANCH_NAME: ${{ github.head_ref || github.ref_name }} # github.head_ref for pull_request event and github.ref_name for push event + SLACK_BOT_TOKEN: ${{ secrets.SLACK_TEST_TOKEN }} + SLACK_CHANNEL_ID: ${{ secrets.SLACK_TEST_CHANNEL_ID }} +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Test Slack message with default settings + id: basic-message + uses: ./ + with: + channel: ${{ env.SLACK_CHANNEL_ID }} + text: 'Test message from :\n\nMessage sent from: \nWorkflow Log: ' + - name: Test Slack reply message + uses: ./ + with: + channel: ${{ env.SLACK_CHANNEL_ID }} + thread_ts: ${{ steps.basic-message.outputs.ts }} + text: 'Test reply with a link to unfurl: ' diff --git a/action.yml b/action.yml index efacb2f..8206ef3 100644 --- a/action.yml +++ b/action.yml @@ -13,6 +13,10 @@ inputs: text: description: "The message text to post" required: true + unfurl_links: + description: "Whether links in the message should be unfurled" + type: boolean + default: true outputs: ts: description: "The timestamp ID of the message that was just posted" @@ -22,12 +26,26 @@ branding: runs: using: 'composite' steps: - - run: | + - name: Validate required inputs + shell: bash + run: | + [[ "${{ inputs.channel }}" ]] || { echo "required input 'channel' not specified" ; exit 1; } + [[ "${{ inputs.text }}" ]] || { echo "required input 'text' not specified" ; exit 1; } + - name: POST to chat.postMessage API + shell: bash + run: | + response=$(curl --fail-with-body --silent --show-error \ + --request POST \ + --header "Authorization: Bearer ${{ env.SLACK_BOT_TOKEN || inputs.token }}" \ + --header "Content-Type: application/json; charset=utf-8" \ + --url https://slack.com/api/chat.postMessage \ + --data '{"channel": "${{ inputs.channel }}", "thread_ts": "${{ inputs.thread_ts }}", "unfurl_links": ${{ inputs.unfurl_links }}, "text": "${{ inputs.text }}"}' \ + ) + echo "Slack API response:\n$response" + ts=$(echo "$response" | jq --raw-output '.ts') + echo "ts of Slack message: $ts" { - echo "ts=<> "$GITHUB_OUTPUT" - shell: bash