name: Release Actions

on:
  release:
    types: [published]

jobs:
  discord_release:
    if: github.repository_owner == 'zed-industries'
    runs-on: ubuntu-latest
    steps:
      - name: Get release URL
        id: get-release-url
        run: |
          if [ "${{ github.event.release.prerelease }}" == "true" ]; then
            URL="https://zed.dev/releases/preview/latest"
          else
            URL="https://zed.dev/releases/stable/latest"
          fi
          echo "::set-output name=URL::$URL"
      - name: Get content
        uses: 2428392/gh-truncate-string-action@b3ff790d21cf42af3ca7579146eedb93c8fb0757 # v1.4.1
        id: get-content
        with:
          stringToTruncate: |
            📣 Zed [${{ github.event.release.tag_name }}](<${{ steps.get-release-url.outputs.URL }}>) was just released!

            ${{ github.event.release.body }}
          maxLength: 2000
          truncationSymbol: "..."
      - name: Discord Webhook Action
        uses: tsickert/discord-webhook@86dc739f3f165f16dadc5666051c367efa1692f4 # v6.0.0
        with:
          webhook-url: ${{ secrets.DISCORD_WEBHOOK_URL }}
          content: ${{ steps.get-content.outputs.string }}
          flags: 4 # suppress embeds - https://discord.com/developers/docs/resources/message#message-object-message-flags
