Skip to content

Commit 61769b3

Browse files
authored
Add a workflow to send release tweet (#6692)
1 parent 7b6e99d commit 61769b3

File tree

2 files changed

+112
-0
lines changed

2 files changed

+112
-0
lines changed

.github/workflows/release-tweet.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Send Release Tweet
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: 'Version number'
8+
type: string
9+
required: true
10+
force:
11+
description: 'Force publish'
12+
type: boolean
13+
default: false
14+
required: true
15+
16+
jobs:
17+
tweet:
18+
name: Send Release Tweet
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Poll release notes page on devsite
22+
run: node scripts/ci/poll_release_notes.js
23+
env:
24+
VERSION: ${{ github.event.inputs.version }}
25+
FORCE_PUBLISH: ${{ github.event.inputs.force }}
26+
- name: Post to Twitter
27+
uses: firebase/firebase-admin-node/.github/actions/send-tweet
28+
with:
29+
status: >
30+
v${{github.event.inputs.version}} of @Firebase JavaScript client for Web / Node.js is available.
31+
Release notes: https://firebase.google.com/support/release-notes/js#${{github.event.inputs.version}}
32+
consumer-key: ${{ secrets.TWITTER_CONSUMER_KEY }}
33+
consumer-secret: ${{ secrets.TWITTER_CONSUMER_SECRET }}
34+
access-token: ${{ secrets.TWITTER_ACCESS_TOKEN }}
35+
access-token-secret: ${{ secrets.TWITTER_ACCESS_TOKEN_SECRET }}

scripts/ci/poll_release_notes.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/**
2+
* @license
3+
* Copyright 2022 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
const https = require('https');
19+
20+
const MAX_ATTEMPTS = 10;
21+
const MINUTE = 60 * 1000;
22+
const RETRY_DELAY_MINUTES = 15;
23+
24+
async function pollReleaseNotes() {
25+
if (!process.env.VERSION) {
26+
console.log(`Couldn't find version.`);
27+
return;
28+
}
29+
30+
const version = process.env.VERSION;
31+
32+
const options = {
33+
method: 'GET'
34+
};
35+
36+
const getData = () =>
37+
new Promise((resolve, reject) => {
38+
const req = https.request(
39+
`https://firebase.google.com/support/release-notes/js`,
40+
options,
41+
res => {
42+
let content = '';
43+
res.on('data', d => (content += d));
44+
res.on('end', () => resolve(content));
45+
}
46+
);
47+
48+
req.on('error', error => reject(error));
49+
req.end();
50+
});
51+
let siteContent = '';
52+
for (let i = 0; i < MAX_ATTEMPTS; i++) {
53+
siteContent = await getData();
54+
const matches = siteContent.match(/<a name="\d+\.\d+.\d+">/g);
55+
if (matches[0] === version) {
56+
return;
57+
}
58+
if (matches.includes(`<a name="${version}">`) && !process.env.FORCE) {
59+
console.warn(
60+
`${version} was found but is not the latest version. ` +
61+
`Set the force option to true to publish anyway.`
62+
);
63+
process.exit(1);
64+
}
65+
console.log(`Didn't find ${version} on release notes page.`);
66+
if (i < MAX_ATTEMPTS - 1) {
67+
console.log(`Trying again in ${RETRY_DELAY_MINUTES} minutes.`);
68+
await new Promise(resolve =>
69+
setTimeout(resolve, RETRY_DELAY_MINUTES * MINUTE)
70+
);
71+
}
72+
}
73+
console.log(`Was not able to find ${version}. Ending process.`);
74+
process.exit(1);
75+
}
76+
77+
pollReleaseNotes();

0 commit comments

Comments
 (0)