forked from GoogleChrome/workbox
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpublish-github.js
More file actions
86 lines (73 loc) · 2.53 KB
/
publish-github.js
File metadata and controls
86 lines (73 loc) · 2.53 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
const gulp = require('gulp');
const path = require('path');
const semver = require('semver');
const fs = require('fs-extra');
const publishHelpers = require('./utils/publish-helpers');
const githubHelper = require('./utils/github-helper');
const logHelper = require('../infra/utils/log-helper');
const publishReleaseOnGithub =
async (tagName, releaseInfo, tarPath, zipPath) => {
if (!releaseInfo) {
const releaseData = await githubHelper.createRelease({
tag_name: tagName,
draft: true,
name: `Workbox ${tagName}`,
prerelease: semver.prerelease(tagName) !== null,
});
releaseInfo = releaseData.data;
}
const tarBuffer = await fs.readFile(tarPath);
await githubHelper.uploadAsset({
url: releaseInfo.upload_url,
file: tarBuffer,
contentType: 'application/gzip',
contentLength: tarBuffer.length,
name: path.basename(tarPath),
label: path.basename(tarPath),
});
const zipBuffer = await fs.readFile(zipPath);
await githubHelper.uploadAsset({
url: releaseInfo.upload_url,
file: zipBuffer,
contentType: 'application/zip',
contentLength: zipBuffer.length,
name: path.basename(zipPath),
label: path.basename(zipPath),
});
};
const handleGithubRelease = async (tagName, gitBranch, releaseInfo) => {
logHelper.log(`Creating GitHub release ${logHelper.highlight(tagName)}.`);
const {tarPath, zipPath} =
await publishHelpers.createBundles(tagName, gitBranch);
return publishReleaseOnGithub(tagName, releaseInfo, tarPath, zipPath);
};
const 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;
});
};
gulp.task('publish-github:generate-from-tags', async () => {
// Get all of the tags in the repo.
const allTags = await githubHelper.getTags();
const taggedReleases = await githubHelper.getTaggedReleases();
const tagsToBuild = await filterTagsWithReleaseBundles(
allTags, taggedReleases);
if (tagsToBuild.length === 0) {
logHelper.log(`No tags missing from GitHub.`);
return;
}
for (let tagInfo of tagsToBuild) {
await handleGithubRelease(
tagInfo.name, tagInfo.name, taggedReleases[tagInfo.name]);
}
});
gulp.task('publish-github', gulp.series(
'publish-github:generate-from-tags',
));