forked from GoogleChrome/workbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpublish-github.js
More file actions
68 lines (56 loc) · 1.81 KB
/
publish-github.js
File metadata and controls
68 lines (56 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
Copyright 2018 Google LLC
Use of this source code is governed by an MIT-style
license that can be found in the LICENSE file or at
https://opensource.org/licenses/MIT.
*/
const semver = require('semver');
const githubHelper = require('./utils/github-helper');
const logHelper = require('../infra/utils/log-helper');
async function publishReleaseOnGithub(tagName, releaseInfo) {
if (!releaseInfo) {
const releaseData = await githubHelper.createRelease({
tag_name: tagName,
draft: true,
name: `Workbox ${tagName}`,
prerelease: semver.prerelease(tagName) !== null,
});
releaseInfo = releaseData.data;
}
}
async function handleGithubRelease(tagName, gitBranch, releaseInfo) {
logHelper.log(`Creating GitHub release ${logHelper.highlight(tagName)}.`);
await publishReleaseOnGithub(tagName, releaseInfo);
}
function filterTagsWithReleaseBundles(allTags, taggedReleases) {
return allTags.filter((tagInfo) => {
const release = taggedReleases[tagInfo.name];
if (release && release.assets.length > 0) {
// If a tag has a release and there is an asset let's assume the
// the release is fine. Note: GitHub's source doesn't count as an
// asset
return false;
}
return true;
});
}
async function publish_github() {
// Get all of the tags in the repo.
const allTags = await githubHelper.getTags();
const taggedReleases = await githubHelper.getTaggedReleases();
const tagsToBuild = filterTagsWithReleaseBundles(allTags, taggedReleases);
if (tagsToBuild.length === 0) {
logHelper.log(`No tags missing from GitHub.`);
return;
}
for (const tagToBuild of tagsToBuild) {
await handleGithubRelease(
tagToBuild.name,
tagToBuild.name,
taggedReleases[tagToBuild.name],
);
}
}
module.exports = {
publish_github,
};