1+ use crate :: discourse:: Discourse ;
12use crate :: github:: Github ;
23use crate :: Context ;
34use anyhow:: { Context as _, Error } ;
@@ -113,6 +114,27 @@ pub(crate) struct Config {
113114 /// Should be a org/repo code, e.g., rust-lang/rust.
114115 pub ( crate ) rustc_tag_repository : Option < String > ,
115116
117+ /// Where to publish new blog PRs.
118+ ///
119+ /// We create a new PR announcing releases in this repository; currently we
120+ /// don't automatically merge it (but that might change in the future).
121+ ///
122+ /// Should be a org/repo code, e.g., rust-lang/blog.rust-lang.org.
123+ pub ( crate ) blog_repository : Option < String > ,
124+
125+ /// The expected release date, for the blog post announcing dev-static
126+ /// releases. This is trimmed & inserted verbatim into the blog post, format
127+ /// is up to the user to decide.
128+ pub ( crate ) scheduled_release_date : Option < String > ,
129+
130+ /// Verbatim URL for insertion into the pre-release blog post. Not otherwise used.
131+ pub ( crate ) release_notes_url : Option < String > ,
132+
133+ /// These are Discourse configurations for where to post dev-static
134+ /// announcements. Currently we only post dev release announcements.
135+ pub ( crate ) discourse_api_key : Option < String > ,
136+ pub ( crate ) discourse_api_user : Option < String > ,
137+
116138 /// This is a github app private key, used for the release steps which
117139 /// require action on GitHub (e.g., kicking off a new thanks GHA build,
118140 /// opening pull requests against the blog for dev releases, promoting
@@ -151,6 +173,11 @@ impl Config {
151173 upload_dir : require_env ( "UPLOAD_DIR" ) ?,
152174 wip_recompress : bool_env ( "WIP_RECOMPRESS" ) ?,
153175 rustc_tag_repository : maybe_env ( "RUSTC_TAG_REPOSITORY" ) ?,
176+ blog_repository : maybe_env ( "BLOG_REPOSITORY" ) ?,
177+ scheduled_release_date : maybe_env ( "BLOG_SCHEDULED_RELEASE_DATE" ) ?,
178+ release_notes_url : maybe_env ( "BLOG_RELEASE_NOTES_URL" ) ?,
179+ discourse_api_user : maybe_env ( "DISCOURSE_API_USER" ) ?,
180+ discourse_api_key : maybe_env ( "DISCOURSE_API_KEY" ) ?,
154181 github_app_key : maybe_env ( "GITHUB_APP_KEY" ) ?,
155182 github_app_id : maybe_env ( "GITHUB_APP_ID" ) ?,
156183 } )
@@ -163,6 +190,65 @@ impl Config {
163190 None
164191 }
165192 }
193+ pub ( crate ) fn discourse ( & self ) -> Option < Discourse > {
194+ if let ( Some ( key) , Some ( user) ) = ( & self . discourse_api_key , & self . discourse_api_user ) {
195+ Some ( Discourse :: new (
196+ "https://internals.rust-lang.org" . to_owned ( ) ,
197+ user. clone ( ) ,
198+ key. clone ( ) ,
199+ ) )
200+ } else {
201+ None
202+ }
203+ }
204+
205+ pub ( crate ) fn blog_contents (
206+ & self ,
207+ release : & str ,
208+ archive_date : & str ,
209+ for_blog : bool ,
210+ internals_url : Option < & str > ,
211+ ) -> Option < String > {
212+ let human_date = self . scheduled_release_date . as_ref ( ) ?;
213+ let release_notes_url = self . release_notes_url . as_ref ( ) ?;
214+ let internals = internals_url
215+ . map ( |url| format ! ( "You can leave feedback on the [internals thread]({url})." ) )
216+ . unwrap_or_default ( ) ;
217+ let prefix = if for_blog {
218+ format ! (
219+ r#"---
220+ layout: post
221+ title: "{} pre-release testing"
222+ author: promote-release
223+ team: The Release Team <https://www.rust-lang.org/governance/teams/release>
224+ ---{}"# ,
225+ release, "\n \n " ,
226+ )
227+ } else {
228+ String :: new ( )
229+ } ;
230+ Some ( format ! (
231+ "{prefix}The {release} pre-release is ready for testing. The release is scheduled for
232+ {human_date}. [Release notes can be found here.][relnotes]
233+
234+ You can try it out locally by running:
235+
236+ ```plain
237+ RUSTUP_DIST_SERVER=https://dev-static.rust-lang.org rustup update stable
238+ ```
239+
240+ The index is <https://dev-static.rust-lang.org/dist/{archive_date}/index.html>.
241+
242+ {internals}
243+
244+ The release team is also thinking about changes to our pre-release process:
245+ we'd love your feedback [on this GitHub issue][feedback].
246+
247+ [relnotes]: {release_notes_url}
248+ [feedback]: https://github.com/rust-lang/release-team/issues/16
249+ "
250+ ) )
251+ }
166252}
167253
168254fn maybe_env < R > ( name : & str ) -> Result < Option < R > , Error >
0 commit comments