Files
workbox/gulp-tasks/publish-github.js
T
Jeffrey PosnickandGitHub 9d88f2abae The contents of v3, reconciled with master (#1357)
* The contents of v3, reconciled with master.

* Remove a few stray files.

* Another extra file.

* Two more deletions.

* Setting up for stable release

* v3.0.0

* Updating CDN and versions

* Doc repair for wf (#1358)

* Changing doc structure to work with WF

* Changing doc structure to work with WF
2018-03-13 15:20:33 -04:00

87 lines
2.5 KiB
JavaScript

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',
));