1# IF YOU UPDATE THE NAME OF ANY GITHUB SECRET, YOU MUST CHERRY PICK THE COMMIT
 2# TO BOTH STABLE AND PREVIEW CHANNELS
 3
 4name: Release Actions
 5
 6on:
 7  release:
 8    types: [published]
 9
10jobs:
11  discord_release:
12    if: github.repository_owner == 'zed-industries'
13    runs-on: ubuntu-latest
14    steps:
15      - name: Get release URL
16        id: get-release-url
17        run: |
18          if [ "${{ github.event.release.prerelease }}" == "true" ]; then
19              URL="https://zed.dev/releases/preview"
20          else
21              URL="https://zed.dev/releases/stable"
22          fi
23
24          echo "URL=$URL" >> "$GITHUB_OUTPUT"
25      - name: Get content
26        uses: 2428392/gh-truncate-string-action@b3ff790d21cf42af3ca7579146eedb93c8fb0757 # v1.4.1
27        id: get-content
28        with:
29          stringToTruncate: |
30            📣 Zed [${{ github.event.release.tag_name }}](<${{ steps.get-release-url.outputs.URL }}>) was just released!
31
32            ${{ github.event.release.body }}
33          maxLength: 2000
34          truncationSymbol: "..."
35      - name: Discord Webhook Action
36        uses: tsickert/discord-webhook@c840d45a03a323fbc3f7507ac7769dbd91bfb164 # v5.3.0
37        with:
38          webhook-url: ${{ secrets.DISCORD_WEBHOOK_RELEASE_NOTES }}
39          content: ${{ steps.get-content.outputs.string }}
40
41  publish-winget:
42    runs-on:
43      - ubuntu-latest
44    steps:
45      - name: Set Package Name
46        id: set-package-name
47        run: |
48          if [ "${{ github.event.release.prerelease }}" == "true" ]; then
49              PACKAGE_NAME=ZedIndustries.Zed.Preview
50          else
51              PACKAGE_NAME=ZedIndustries.Zed
52          fi
53
54          echo "PACKAGE_NAME=$PACKAGE_NAME" >> "$GITHUB_OUTPUT"
55      - uses: vedantmgoyal9/winget-releaser@19e706d4c9121098010096f9c495a70a7518b30f # v2
56        with:
57          identifier: ${{ steps.set-package-name.outputs.PACKAGE_NAME }}
58          max-versions-to-keep: 5
59          token: ${{ secrets.WINGET_TOKEN }}
60
61  send_release_notes_email:
62    if: false && github.repository_owner == 'zed-industries' && !github.event.release.prerelease
63    runs-on: ubuntu-latest
64    steps:
65      - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
66        with:
67          fetch-depth: 0
68
69      - name: Check if release was promoted from preview
70        id: check-promotion-from-preview
71        run: |
72          VERSION="${{ github.event.release.tag_name }}"
73          PREVIEW_TAG="${VERSION}-pre"
74
75          if git rev-parse "$PREVIEW_TAG" > /dev/null 2>&1; then
76              echo "was_promoted_from_preview=true" >> "$GITHUB_OUTPUT"
77          else
78              echo "was_promoted_from_preview=false" >> "$GITHUB_OUTPUT"
79          fi
80
81      - name: Send release notes email
82        if: steps.check-promotion-from-preview.outputs.was_promoted_from_preview == 'true'
83        run: |
84          TAG="${{ github.event.release.tag_name }}"
85          cat << 'EOF' > release_body.txt
86          ${{ github.event.release.body }}
87          EOF
88          jq -n --arg tag "$TAG" --rawfile body release_body.txt '{version: $tag, markdown_body: $body}' \
89            > release_data.json
90          curl -X POST "https://zed.dev/api/send_release_notes_email" \
91            -H "Authorization: Bearer ${{ secrets.RELEASE_NOTES_API_TOKEN }}" \
92            -H "Content-Type: application/json" \
93            -d @release_data.json