1
+ use crate :: discourse:: Discourse ;
1
2
use crate :: github:: Github ;
2
3
use crate :: Context ;
3
4
use anyhow:: { Context as _, Error } ;
@@ -113,6 +114,27 @@ pub(crate) struct Config {
113
114
/// Should be a org/repo code, e.g., rust-lang/rust.
114
115
pub ( crate ) rustc_tag_repository : Option < String > ,
115
116
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. Expected to be in YYYY-MM-DD format.
127
+ ///
128
+ /// This is used to produce the expected release date in blog posts and to
129
+ /// generate the release notes URL (targeting stable branch on
130
+ /// rust-lang/rust).
131
+ pub ( crate ) scheduled_release_date : Option < chrono:: NaiveDate > ,
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
+
116
138
/// This is a github app private key, used for the release steps which
117
139
/// require action on GitHub (e.g., kicking off a new thanks GHA build,
118
140
/// opening pull requests against the blog for dev releases, promoting
@@ -151,6 +173,10 @@ impl Config {
151
173
upload_dir : require_env ( "UPLOAD_DIR" ) ?,
152
174
wip_recompress : bool_env ( "WIP_RECOMPRESS" ) ?,
153
175
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
+ discourse_api_user : maybe_env ( "DISCOURSE_API_USER" ) ?,
179
+ discourse_api_key : maybe_env ( "DISCOURSE_API_KEY" ) ?,
154
180
github_app_key : maybe_env ( "GITHUB_APP_KEY" ) ?,
155
181
github_app_id : maybe_env ( "GITHUB_APP_ID" ) ?,
156
182
} )
@@ -163,6 +189,70 @@ impl Config {
163
189
None
164
190
}
165
191
}
192
+ pub ( crate ) fn discourse ( & self ) -> Option < Discourse > {
193
+ if let ( Some ( key) , Some ( user) ) = ( & self . discourse_api_key , & self . discourse_api_user ) {
194
+ Some ( Discourse :: new (
195
+ "https://internals.rust-lang.org" . to_owned ( ) ,
196
+ user. clone ( ) ,
197
+ key. clone ( ) ,
198
+ ) )
199
+ } else {
200
+ None
201
+ }
202
+ }
203
+
204
+ pub ( crate ) fn blog_contents (
205
+ & self ,
206
+ release : & str ,
207
+ archive_date : & str ,
208
+ for_blog : bool ,
209
+ internals_url : Option < & str > ,
210
+ ) -> Option < String > {
211
+ let scheduled_release_date = self . scheduled_release_date ?;
212
+ let release_notes_url = format ! (
213
+ "https://github.com/rust-lang/rust/blob/stable/RELEASES.md#version-{}-{}" ,
214
+ release. replace( '.' , "" ) ,
215
+ scheduled_release_date. format( "%Y-%m-%d" ) ,
216
+ ) ;
217
+ let human_date = scheduled_release_date. format ( "%B %d" ) ;
218
+ let internals = internals_url
219
+ . map ( |url| format ! ( "You can leave feedback on the [internals thread]({url})." ) )
220
+ . unwrap_or_default ( ) ;
221
+ let prefix = if for_blog {
222
+ format ! (
223
+ r#"---
224
+ layout: post
225
+ title: "{} pre-release testing"
226
+ author: Release automation
227
+ team: The Release Team <https://www.rust-lang.org/governance/teams/release>
228
+ ---{}"# ,
229
+ release, "\n \n " ,
230
+ )
231
+ } else {
232
+ String :: new ( )
233
+ } ;
234
+ Some ( format ! (
235
+ "{prefix}The {release} pre-release is ready for testing. The release is scheduled for
236
+ {human_date}. [Release notes can be found here.][relnotes]
237
+
238
+ You can try it out locally by running:
239
+
240
+ ```plain
241
+ RUSTUP_DIST_SERVER=https://dev-static.rust-lang.org rustup update stable
242
+ ```
243
+
244
+ The index is <https://dev-static.rust-lang.org/dist/{archive_date}/index.html>.
245
+
246
+ {internals}
247
+
248
+ The release team is also thinking about changes to our pre-release process:
249
+ we'd love your feedback [on this GitHub issue][feedback].
250
+
251
+ [relnotes]: {release_notes_url}
252
+ [feedback]: https://github.com/rust-lang/release-team/issues/16
253
+ "
254
+ ) )
255
+ }
166
256
}
167
257
168
258
fn maybe_env < R > ( name : & str ) -> Result < Option < R > , Error >
0 commit comments