diff --git a/.github/workflows/branch-builder.yml b/.github/workflows/branch-builder.yml new file mode 100644 index 0000000..155b94d --- /dev/null +++ b/.github/workflows/branch-builder.yml @@ -0,0 +1,31 @@ +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 message with optional inputs specified (reply message + unfurl_links disabled) + uses: ./ + with: + channel: ${{ env.SLACK_CHANNEL_ID }} + thread_ts: ${{ steps.basic-message.outputs.ts }} + text: 'Test reply with a link to unfurl (that should _not_ unfurl): ' + unfurl_links: false diff --git a/action.yml b/action.yml index efacb2f..e1b2cfd 100644 --- a/action.yml +++ b/action.yml @@ -13,21 +13,37 @@ 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" + value: ${{steps.slack-post-message.outputs.ts}} branding: icon: 'tag' color: 'blue' runs: using: 'composite' steps: - - run: | - { - echo "ts=<> "$GITHUB_OUTPUT" + - 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 + id: slack-post-message + 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 message API response:\n$response" + ts=$(echo "$response" | jq --raw-output '.ts') + echo "Setting ts output to $ts" + echo "ts=$ts" >> $GITHUB_OUTPUT