1use gh_workflow::*;
2
3use crate::tasks::workflows::{
4 release::{self, notify_on_failure},
5 runners,
6 steps::{NamedJob, checkout_repo, dependant_job, named},
7 vars::{self, StepOutput},
8};
9
10pub fn after_release() -> Workflow {
11 let refresh_zed_dev = rebuild_releases_page();
12 let post_to_discord = post_to_discord(&[&refresh_zed_dev]);
13 let publish_winget = publish_winget();
14 let create_sentry_release = create_sentry_release();
15 let notify_on_failure = notify_on_failure(&[
16 &refresh_zed_dev,
17 &post_to_discord,
18 &publish_winget,
19 &create_sentry_release,
20 ]);
21
22 named::workflow()
23 .on(Event::default().release(Release::default().types(vec![ReleaseType::Published])))
24 .add_job(refresh_zed_dev.name, refresh_zed_dev.job)
25 .add_job(post_to_discord.name, post_to_discord.job)
26 .add_job(publish_winget.name, publish_winget.job)
27 .add_job(create_sentry_release.name, create_sentry_release.job)
28 .add_job(notify_on_failure.name, notify_on_failure.job)
29}
30
31fn rebuild_releases_page() -> NamedJob {
32 fn refresh_cloud_releases() -> Step<Run> {
33 named::bash(
34 "curl -fX POST https://cloud.zed.dev/releases/refresh?expect_tag=${{ github.event.release.tag_name }}",
35 )
36 }
37
38 fn redeploy_zed_dev() -> Step<Run> {
39 named::bash("npm exec --yes -- vercel@37 --token=\"$VERCEL_TOKEN\" --scope zed-industries redeploy https://zed.dev")
40 .add_env(("VERCEL_TOKEN", vars::VERCEL_TOKEN))
41 }
42
43 named::job(
44 Job::default()
45 .runs_on(runners::LINUX_SMALL)
46 .cond(Expression::new(
47 "github.repository_owner == 'zed-industries'",
48 ))
49 .add_step(refresh_cloud_releases())
50 .add_step(redeploy_zed_dev()),
51 )
52}
53
54fn post_to_discord(deps: &[&NamedJob]) -> NamedJob {
55 fn get_release_url() -> Step<Run> {
56 named::bash(indoc::indoc! {r#"
57 if [ "${{ github.event.release.prerelease }}" == "true" ]; then
58 URL="https://zed.dev/releases/preview"
59 else
60 URL="https://zed.dev/releases/stable"
61 fi
62
63 echo "URL=$URL" >> "$GITHUB_OUTPUT"
64 "#})
65 .id("get-release-url")
66 }
67
68 fn get_content() -> Step<Use> {
69 named::uses(
70 "2428392",
71 "gh-truncate-string-action",
72 "b3ff790d21cf42af3ca7579146eedb93c8fb0757", // v1.4.1
73 )
74 .id("get-content")
75 .add_with((
76 "stringToTruncate",
77 indoc::indoc! {r#"
78 📣 Zed [${{ github.event.release.tag_name }}](<${{ steps.get-release-url.outputs.URL }}>) was just released!
79
80 ${{ github.event.release.body }}
81 "#},
82 ))
83 .add_with(("maxLength", 2000))
84 .add_with(("truncationSymbol", "..."))
85 }
86
87 fn discord_webhook_action() -> Step<Use> {
88 named::uses(
89 "tsickert",
90 "discord-webhook",
91 "c840d45a03a323fbc3f7507ac7769dbd91bfb164", // v5.3.0
92 )
93 .add_with(("webhook-url", vars::DISCORD_WEBHOOK_RELEASE_NOTES))
94 .add_with(("content", "${{ steps.get-content.outputs.string }}"))
95 }
96 let job = dependant_job(deps)
97 .runs_on(runners::LINUX_SMALL)
98 .cond(Expression::new(
99 "github.repository_owner == 'zed-industries'",
100 ))
101 .add_step(get_release_url())
102 .add_step(get_content())
103 .add_step(discord_webhook_action());
104 named::job(job)
105}
106
107fn publish_winget() -> NamedJob {
108 fn set_package_name() -> (Step<Run>, StepOutput) {
109 let step = named::pwsh(indoc::indoc! {r#"
110 if ("${{ github.event.release.prerelease }}" -eq "true") {
111 $PACKAGE_NAME = "ZedIndustries.Zed.Preview"
112 } else {
113 $PACKAGE_NAME = "ZedIndustries.Zed"
114 }
115
116 echo "PACKAGE_NAME=$PACKAGE_NAME" >> $env:GITHUB_OUTPUT
117 "#})
118 .id("set-package-name");
119
120 let output = StepOutput::new(&step, "PACKAGE_NAME");
121 (step, output)
122 }
123
124 fn winget_releaser(package_name: &StepOutput) -> Step<Use> {
125 named::uses(
126 "vedantmgoyal9",
127 "winget-releaser",
128 "19e706d4c9121098010096f9c495a70a7518b30f", // v2
129 )
130 .add_with(("identifier", package_name.to_string()))
131 .add_with(("max-versions-to-keep", 5))
132 .add_with(("token", vars::WINGET_TOKEN))
133 }
134
135 let (set_package_name, package_name) = set_package_name();
136
137 named::job(
138 Job::default()
139 .runs_on(runners::WINDOWS_DEFAULT)
140 .add_step(set_package_name)
141 .add_step(winget_releaser(&package_name)),
142 )
143}
144
145fn create_sentry_release() -> NamedJob {
146 let job = Job::default()
147 .runs_on(runners::LINUX_SMALL)
148 .cond(Expression::new(
149 "github.repository_owner == 'zed-industries'",
150 ))
151 .add_step(checkout_repo())
152 .add_step(release::create_sentry_release());
153 named::job(job)
154}