aboutsummaryrefslogtreecommitdiffstats
path: root/packages/monorepo-scripts/src/utils/github_release_utils.ts
blob: 9b5b26d7e3109efd900fc17f61322c400f03509c (plain) (blame)
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import * as promisify from 'es6-promisify';
import { readFileSync } from 'fs';
import * as _ from 'lodash';
import * as path from 'path';
import { exec as execAsync } from 'promisify-child-process';
import * as publishRelease from 'publish-release';

import { constants } from '../constants';
import { Package } from '../types';

import { utils } from './utils';

const publishReleaseAsync = promisify(publishRelease);
// tslint:disable-next-line:completed-docs
export async function publishReleaseNotesAsync(updatedPublishPackages: Package[], isDryRun: boolean): Promise<void> {
    // Git push a tag representing this publish (publish-{commit-hash}) (truncate hash)
    const result = await execAsync('git log -n 1 --pretty=format:"%H"', { cwd: constants.monorepoRootPath });
    const latestGitCommit = result.stdout;
    const prefixLength = 7;
    const shortenedGitCommit = latestGitCommit.slice(0, prefixLength);
    const tagName = `monorepo@${shortenedGitCommit}`;

    if (!isDryRun) {
        try {
            await execAsync(`git tag ${tagName}`);
        } catch (err) {
            if (_.includes(err.message, 'already exists')) {
                // Noop tag creation since already exists
            } else {
                throw err;
            }
        }
        const { stdout } = await execAsync(`git ls-remote --tags origin refs/tags/${tagName}`);
        if (_.isEmpty(stdout)) {
            await execAsync(`git push origin ${tagName}`);
        }
    }

    const releaseName = `0x monorepo - ${shortenedGitCommit}`;

    let assets: string[] = [];
    let aggregateNotes = '';
    _.each(updatedPublishPackages, pkg => {
        const notes = getReleaseNotesForPackage(pkg.packageJson.name, pkg.packageJson.version);
        if (_.isEmpty(notes)) {
            return; // don't include it
        }
        aggregateNotes += `### ${pkg.packageJson.name}@${pkg.packageJson.version}\n${notes}\n\n`;

        const packageAssets = _.get(pkg.packageJson, 'config.postpublish.assets');
        if (!_.isUndefined(packageAssets)) {
            assets = [...assets, ...packageAssets];
        }
    });
    const finalAssets = adjustAssetPaths(assets);

    const publishReleaseConfigs = {
        token: constants.githubPersonalAccessToken,
        owner: '0xProject',
        tag: tagName,
        repo: '0x-monorepo',
        name: releaseName,
        notes: aggregateNotes,
        draft: false,
        prerelease: false,
        reuseRelease: true,
        reuseDraftOnly: false,
        assets: finalAssets,
    };

    if (isDryRun) {
        utils.log(`Dry run: stopping short of publishing release notes to github`);
        utils.log(`Would publish with configs:\n${JSON.stringify(publishReleaseConfigs, null, '\t')}`);
        return;
    }

    utils.log('Publishing release notes ', releaseName, '...');
    // TODO: Currently publish-release doesn't let you specify the labels for each asset uploaded
    // Ideally we would like to name the assets after the package they are from
    // Source: https://github.com/remixz/publish-release/issues/39
    await publishReleaseAsync(publishReleaseConfigs);
}

// Asset paths should described from the monorepo root. This method prefixes
// the supplied path with the absolute path to the monorepo root.
function adjustAssetPaths(assets: string[]): string[] {
    const finalAssets: string[] = [];
    _.each(assets, (asset: string) => {
        const finalAsset = `${constants.monorepoRootPath}/${asset}`;
        finalAssets.push(finalAsset);
    });
    return finalAssets;
}

function getReleaseNotesForPackage(packageName: string, version: string): string {
    const packageNameWithoutNamespace = packageName.replace('@0xproject/', '');
    const changelogJSONPath = path.join(
        constants.monorepoRootPath,
        'packages',
        packageNameWithoutNamespace,
        'CHANGELOG.json',
    );
    const changelogJSON = readFileSync(changelogJSONPath, 'utf-8');
    const changelogs = JSON.parse(changelogJSON);
    const latestLog = changelogs[0];
    // If only has a `Dependencies updated` changelog, we don't include it in release notes
    if (latestLog.changes.length === 1 && latestLog.changes[0].note === constants.dependenciesUpdatedMessage) {
        return '';
    }
    // We sanity check that the version for the changelog notes we are about to publish to Github
    // correspond to the new version of the package.
    // if (version !== latestLog.version) {
    //     throw new Error('Expected CHANGELOG.json latest entry version to coincide with published version.');
    // }
    let notes = '';
    _.each(latestLog.changes, change => {
        notes += `* ${change.note}`;
        if (change.pr) {
            notes += ` (#${change.pr})`;
        }
        notes += `\n`;
    });
    return notes;
}
='commitgraph'>* Most commonly used build systems support silent builds, when theyDmitry Marakasov2016-09-101-0/+7 * Add support added for LICENSE=NONE, use it when the port doesn'tDmitry Marakasov2016-09-081-7/+16 * Document the deprecation/removal of KNOBS done in r345883 (2014-02-24)Baptiste Daroussin2016-08-271-0/+6 * Add GH_SUBDIR, automatically moves a secondary distfile to the rightMathieu Arnold2016-08-241-2/+29 * Replace Mk/bsd.kde4.mk by Mk/Uses/kde.mk in preparation for KDE Frameworks andTobias C. Berner2016-08-241-0/+14 * CHANGES: Document Uses/grantlee.mk added in r420244.Raphael Kubo da Costa2016-08-211-0/+9 * CHANGES: Fix date of the VAR_regex=regex entry.Raphael Kubo da Costa2016-08-211-1/+1 * Add regexps capacity to PLIST_SUB.Mathieu Arnold2016-08-171-0/+18 * Don't use extension.ini any more, and have each extension install in itsMathieu Arnold2016-08-031-0/+10 * USEify USES=php.Mathieu Arnold2016-06-281-0/+17 * Replace bsd.openssl.mk with USES=sslMathieu Arnold2016-06-271-0/+5 * Add an opt_CMAKE_BOOL options helper.Adam Weinberger2016-06-261-0/+12 * Trim trailing whitespaceDmitry Marakasov2016-06-151-2/+2 * A new stage-qa test has been added, it reports all shared librariesMathieu Arnold2016-05-251-0/+14 * Add an entry about the new @xmlcatmgrBaptiste Daroussin2016-05-251-0/+9 * Fix typo.Thierry Thomas2016-05-131-1/+1 * Move my CHANGES entry from r415078 to the correct locationEd Maste2016-05-131-10/+10 * Record TIMESTAMP in make makesumEd Maste2016-05-131-0/+10 * Add a CHANGES entry about USES=gem.Mathieu Arnold2016-04-281-0/+5 * Commit a forgotten CHANGES entry.Mathieu Arnold2016-04-271-0/+7 * USE_RC_SUBR=yes has not done anything for a long time, remove it fromMathieu Arnold2016-04-141-1/+6 * Add CONFIGURE_OUTSOURCE supportJan Beich2016-04-131-0/+12 * Add a CHANGES entry concerning the change about PORTSDIR in the dependency linesBaptiste Daroussin2016-04-021-0/+14 * Introduce GH_TUPLE.Mathieu Arnold2016-03-021-0/+9 * Move Mk/bsd.gnome.mk and Mk/bsd.mate.mk to Mk/Uses/.Koop Mast2016-02-081-0/+12 * Mention new supported LICENSE valuesDmitry Marakasov2016-01-121-0/+10 * We are actually in 2016 :)Baptiste Daroussin2016-01-111-1/+1 * Introduce 2 new USES: sqlite and firebirdBaptiste Daroussin2016-01-111-0/+6 * Change the meaning of NO_WRKSUBDIR to force a WRKDIR != WRKSRC.Mathieu Arnold2015-11-051-0/+17 * - Add shebangfix documentation bitsDmitry Marakasov2015-10-221-0/+15 * Readd PORTSDIR for now we will only start removing them after 2016Q1 is branchedBaptiste Daroussin2015-10-151-14/+0 * Drop the necessity to add ${PORTSDIR} to dependency lineBaptiste Daroussin2015-10-151-0/+14 * Rewording missed from previous commitDmitry Marakasov2015-09-291-2/+2 * Implemented complete support for test target.Dmitry Marakasov2015-09-291-0/+20 * Extend @sample to accept argumentsBaptiste Daroussin2015-09-261-1/+10 * Document @{pre,post}[un]exec in CHANGESBaptiste Daroussin2015-09-261-0/+12 * Make it so that the default Perl is always called perl5.Mathieu Arnold2015-09-141-0/+6 * Add generic opt_VARS/opt_VARS_OFF.Mathieu Arnold2015-08-281-0/+11 * Document r394572 in CHANGES.Raphael Kubo da Costa2015-08-181-0/+6 * Introduce <opt>_IMPLIES and <opt>_PREVENTS to register dependencies, orMathieu Arnold2015-08-181-0/+14 * Remove UNIQUENAME and LATEST_LINK.Mathieu Arnold2015-08-171-0/+8 * Convert code in bsd.port.mk for USE_GHOSTSCRIPT* to USES=ghostscript.Koop Mast2015-07-171-0/+7 * Introduce target option helpers.Mathieu Arnold2015-07-011-0/+32 * Document the removal of USE_RCORDERBaptiste Daroussin2015-06-231-0/+6 * Introduce USE_GITHUB=nodefault to allow fetching additional distfilesMathieu Arnold2015-05-291-0/+7 * USE_GITHUB can now fetch multiple distfiles. It uses a grouping featureMathieu Arnold2015-05-291-0/+29 * Switch PYTHON_REL from a 3 digits number to a 4 digits number to handleAntoine Brodin2015-05-271-0/+8 * Remove GH_COMMIT support.Mathieu Arnold2015-05-211-0/+5 * Mark USE_AUTOTOOLS deprecated and remove support for libtoolize.Tijl Coosemans2015-04-201-0/+9 * Convert bsd.gnustep.mk to USES=gnustepBaptiste Daroussin2015-04-091-0/+11 * Document the new USES=waf into CHANGESBaptiste Daroussin2015-04-081-0/+20 * USE_BZIP2 and USE_XZ are not used anymore in the ports tree mark them asBaptiste Daroussin2015-04-071-0/+6 * - track subversion http module activation change in the correct fileOlli Hauer2015-04-071-7/+0 * Document recent changesBaptiste Daroussin2015-04-011-0/+16 * - document new subversion httpd module fileOlli Hauer2015-04-011-0/+7 * Document removal of PTHREAD_LIBS/PTHREAD_CFLAGSBryan Drewery2015-03-271-0/+6 * Undocument BSDMAKE from r381977 as I have thought of a better way and willBryan Drewery2015-03-231-7/+0 * Introduce a BSDMAKE?= /usr/bin/make and use it as the default MAKE_CMD.Bryan Drewery2015-03-231-0/+7 * Remove GITHUB_RELEASE MASTER_SITE from r375010 as it is now redundant with GI...Bryan Drewery2015-03-201-0/+8 * Note that GH_TAGNAME can be any length of the git hash.Bryan Drewery2015-03-201-0/+3 * Update USE_GITHUB so it does not require GH_COMMIT.Bryan Drewery2015-03-201-0/+14 * The FreeBSD Xfce team proudly presents Xfce 4.12.Olivier Duchateau2015-03-061-0/+6 * Introduce new USE_QT4 component linguisttools for lrelease/lupdate toolsMax Brazhnikov2015-02-251-0/+9 * Make Perl link all .so it builds with libperl.so.Mathieu Arnold2014-12-171-0/+9 * Split devel/gettext in devel/gettext-runtime and devel/gettext-tools. TheTijl Coosemans2014-11-301-0/+13 * Change the way Perl modules are installed, update the default Perl to 5.18.Mathieu Arnold2014-11-261-0/+29 * Finally retire USE_PGSQLChris Rees2014-11-231-0/+10 * Introduce the SITE_ARCH variable containing SITE_PERL/PERL_ARCH.Mathieu Arnold2014-11-181-0/+6 * - Enable SSP by default.Bryan Drewery2014-11-031-0/+8 * Add an example with @exec too.Mathieu Arnold2014-10-081-0/+3 * Note @cwd being deprecated.Mathieu Arnold2014-10-071-0/+15 * Add BUNDLE_LIBS knob to prevent pkg(8) from automatically add provided shlibsBaptiste Daroussin2014-10-021-0/+7 * Remove support for old autoconf and automake versions from USE_AUTOTOOLS:Tijl Coosemans2014-10-011-0/+6 * If either of OSVERSION or UNAME_r is improperly set when building in aBryan Drewery2014-10-011-0/+30 * Add hint as to where @stopdaemon has gone.Matthias Andree2014-09-251-21/+20 * Proofread the 20140922 CHANGES entry.Raphael Kubo da Costa2014-09-241-4/+4 * Document recent changes in plist handlingBaptiste Daroussin2014-09-221-0/+19 * - Remove last uses of USE_AUTOTOOLS=libtool from bsd.gnome.mkTijl Coosemans2014-09-171-0/+10 * Document r368281.Tijl Coosemans2014-09-171-0/+11 * Remove support for pkg_installBaptiste Daroussin2014-09-011-0/+9 * Remove support for NO_STAGEBaptiste Daroussin2014-09-011-0/+5 * Document r366154Antoine Brodin2014-08-261-0/+5 * - Rename PYTHON_FEATURES to USE_PYTHON to comply to USE_PERL5 and to avoid aMarcus von Appen2014-08-151-3/+3 * - Fix typoSunpoet Po-Chuan Hsieh2014-08-101-2/+2 * Convert the Python framework bits to USES=python.Marcus von Appen2014-08-091-0/+23 * Now that all LIB_DEPENDS has been switched to modern version, remove supportBaptiste Daroussin2014-07-161-0/+5 * Support for installations based on the easy_install setup.py target hasMarcus von Appen2014-07-091-0/+8 * Add a bit about USE_PERL5=fixpacklist here.Mathieu Arnold2014-06-291-0/+7 * Remove the IGNOREFILES feature: it was an unsafe feature allowing to use filesBaptiste Daroussin2014-06-231-0/+7 * Introduce a new PYTHON_CONCURRENT_INSTALL knob to support the parallelMarcus von Appen2014-06-081-0/+27 * - Remove USE_GMAKE support, please use USES=gmake insteadMartin Wilke2014-05-291-0/+5 * Drop compatibility code for USE_DOS2UNIXBaptiste Daroussin2014-05-261-0/+5 * Convert all :U to :tu and :L to :tlBaptiste Daroussin2014-05-051-0/+9 * Document r352514Baptiste Daroussin2014-05-011-0/+9 * When linking a library libA with a library libB using libtool, if libB.laTijl Coosemans2014-04-231-0/+12 * - Rename check-orphans to check-plist. Keep the old for backwards-compat.Bryan Drewery2014-04-191-0/+16 * - Make default target "make stage" if staging supported.Bryan Drewery2014-04-171-0/+6 * - Add a @sample plist keywordBryan Drewery2014-04-121-0/+17 * Two new USES added to finish handling distfiles formats a consistent way:Baptiste Daroussin2014-03-121-0/+14 * Add a note for USES=zip and USES=makeself which were recently added by baptRene Ladan2014-03-081-0/+10 * KDE/FreeBSD team is happy to present Qt 5 in ports!Max Brazhnikov2014-03-041-0/+7 * - Whitespace cleanupMartin Wilke2014-01-291-11/+11 * Add two new options helpers:Mathieu Arnold2014-01-281-0/+11 * New USES=uniquefiles to make files or directories uniqueMarcus von Appen2014-01-121-0/+38 * - Remove lang/python as implicit build and run dependency fromMarcus von Appen2013-12-191-0/+22 * New USES=fortran to replace USE_FORTRAN.Tijl Coosemans2013-12-131-0/+14 * New USES=twisted, to replace the old USE_TWISTED knob.Marcus von Appen2013-12-081-0/+17 * Remove ltverhack's hard depend on USE_AUTOTOOLS=libtool.Koop Mast2013-11-201-0/+15 * Indent 20131031 entry like the rest of the file.Koop Mast2013-11-201-10/+10 * Add a description of USES=kmodRene Ladan2013-10-311-0/+14 * - Remove manual creation and removal of share/applications, as it's now in th...Dmitry Marakasov2013-10-221-0/+6 * - Fix typoSunpoet Po-Chuan Hsieh2013-10-201-1/+1 * New USES=compilerBaptiste Daroussin2013-10-091-0/+18 * - Add new USES= qmake (with staging support)Max Brazhnikov2013-10-091-0/+8 * - PATCHFILES now support an optional :-pX flag that notes which patch stripBryan Drewery2013-10-051-0/+9 * Introduce the new "scons" USES. The goal is to replace the old bsd.scons.mkBaptiste Daroussin2013-10-031-0/+6 * Add an entry about "create packages as a user"Baptiste Daroussin2013-09-241-3/+16 * - add new USES target: zope, and convert the tree to itRuslan Makhmatkhanov2013-09-231-0/+8 * Add support for staging area in the ports treeBaptiste Daroussin2013-09-231-0/+29 * - Rename public name of SSP support to WITH_SSP_PORTS as /usr/srcBryan Drewery2013-09-221-2/+2 * SSP support has been added to ports with WITH_SSP for i386 and amd64Bryan Drewery2013-09-201-0/+22 * - Document the addition of tcl/tk to the USES and DEFAULT_VERSIONS framework.Pietro Cerutti2013-09-191-0/+14 * Remove the old perl framework, that also means all the perl code is not loade...Baptiste Daroussin2013-09-181-0/+11 * - proper formatingAndrej Zverev2013-09-071-1/+4 * - Make ports use the libc provided iconv implementation on 10-CURRENTGuido Falsi2013-09-051-0/+18 * Back to the presentBaptiste Daroussin2013-09-041-1/+1 * Document the removal of USE_GNOME=pkgconfigBaptiste Daroussin2013-09-021-0/+6 * - Add USE_PACKAGE_DEPENDS_ONLY which will try installing dependenciesBryan Drewery2013-08-311-0/+7 * Back to the presentBaptiste Daroussin2013-07-311-1/+1 * TypoBaptiste Daroussin2013-07-311-1/+1 * Document the new USE=perl5Baptiste Daroussin2013-07-311-0/+33 * KDE3 and QT3 expired on 2013-07-01, remove these ports.Rene Ladan2013-07-271-0/+10 * New USES imake to handle the dependency on imake.Baptiste Daroussin2013-06-281-0/+12 * Fix AUTHORS line in the last entryBaptiste Daroussin2013-06-261-1/+2 * Add a new USES: fmakeBaptiste Daroussin2013-06-201-1/+8 * Fix two typos: add two trailing curly braces.Boris Samorodov2013-06-201-2/+2 * Document the fact that _DEPENDS now also has per options helpersBaptiste Daroussin2013-06-141-0/+3 * Add a forgotten helper:Baptiste Daroussin2013-06-141-0/+6 * New macros to help dealing with ports that have options:Baptiste Daroussin2013-06-141-0/+31 * Add a USES display to replace USE_DISPLAY.Baptiste Daroussin2013-06-141-0/+13 * Fix ports using GH_TAGNAME=master to depend on a known hashBryan Drewery2013-06-081-0/+8 * Add WRKSRC_SUBDIR to simplify overriding WRKSRC:Bryan Drewery2013-06-071-0/+12 * WordingBaptiste Daroussin2013-06-061-2/+2 * Remove support for parsing the old OPTIONS macro, the compatibility code to l...Baptiste Daroussin2013-06-061-0/+6 * Document new USES: desktop-file-utils and shared-mime-info.Koop Mast2013-05-091-0/+26 * USE_GETTEXT has totally been replaced by USES=gettext thanks, jgh and akBaptiste Daroussin2013-05-071-0/+2 * Add new USES: shebangfixBaptiste Daroussin2013-05-071-0/+10 * Add new USES: ncurses and readlineBaptiste Daroussin2013-05-061-0/+16 * Introduces USES= iconv to replace USE_ICONV.Marcus von Appen2013-04-271-1/+8 * Remove USE_CDRTOOLS from bsd.port.mkBaptiste Daroussin2013-04-261-0/+1 * Remove USE_FREETYPE from bsd.port.mkBaptiste Daroussin2013-04-261-0/+5 * Introduces USES= gettext to replace USE_GETTEXTJason Helfman2013-04-231-0/+13 * Fix dateBaptiste Daroussin2013-04-231-1/+1 * - Add WITH_CCACHE_BUILD support during 'configure' phaseBryan Drewery2013-04-231-0/+9 * Introduce USES= pkgconfig to replace USE_PKGCONFIGBaptiste Daroussin2013-04-231-0/+12 * - Add New USES macro to handle support for Zenoss ports and Zenpacks:Jason Helfman2013-03-201-0/+7 * Convert USE_CMAKE to USES macro:Max Brazhnikov2013-03-201-0/+15 * Make the ports tree use dialog4ports for make config.Baptiste Daroussin2013-03-191-0/+10 * Document USES=qmailBryan Drewery2013-03-161-0/+11 * Document the introduction of Keywords/info.yaml in CHANGESBaptiste Daroussin2013-03-151-0/+7 * Add a note about the new USES macro and the new USES= pathfix fuseBaptiste Daroussin2013-03-071-0/+9 * - Fix WhitespacesMartin Wilke2013-02-081-1/+1 * - Document that PTHREAD_CFLAGS and PTHREAD_LIBS are unsupportedPietro Cerutti2013-02-071-0/+7 * - introduce a USE_FUSE macroFlorian Smeets2012-12-141-0/+7 * Extend the options framework providing 2 new macros:Baptiste Daroussin2012-12-101-0/+7 * Minor whitespace and formatting fixes.Alexey Dokuchaev2012-11-171-3/+3 * We are in 2012, it is time to activate IPV6 options by default everywhereBaptiste Daroussin2012-10-101-0/+5 * Switching current to use pkgng by defaultBaptiste Daroussin2012-10-101-0/+10 * - Add ccache support for building ports. [1]Beat Gaetzi2012-08-301-0/+16 * - Add support for fetching from GitHub in bsd.sites.mkPietro Cerutti2012-08-201-0/+22 * new devel/pkgconf added to replace devel/pkg-config. new version of pkg-configBaptiste Daroussin2012-07-261-0/+15 * - use UPDATING instead CHANGESOlli Hauer2012-07-231-5/+0 * - use reserverd UID/GIDOlli Hauer2012-07-211-0/+5 * - Keep questions on a public mailing listBeat Gaetzi2012-07-161-1/+1 * - Add a note about the switch to SubversionBeat Gaetzi2012-07-161-0/+15 * - Fix copy-paste errorAlex Kozlov2012-06-251-2/+2 * Give a passing mention of OPTIONSngChris Rees2012-06-241-0/+11 * - Add CHANGES entry on recent LDFLAGS updateDmitry Marakasov2011-09-271-0/+19 * Describe how CPPFLAGS is now passed to both the configure and makeGerald Pfeifer2011-06-071-0/+15 * Autotools update. Read ports/UPDATING 20100915 for details.Ade Lovett2010-09-161-0/+8 * USE_GCC=4.3 is deprecated (and no port uses it anymore). USE_GCC=4.3+Gerald Pfeifer2010-06-071-0/+7 * - Add entry in CHANGES about bsd.licenses*.mk.Alejandro Pulver2010-05-261-0/+9 * - add 1 missing WITH_APACHEXX option to CHANGES thats now deadPhilip M. Gollucci2010-05-261-1/+1 * Bump copyright year to 2010Erwin Lansing2010-01-031-1/+1 * be more specific about WITH_APACHE2 and friendsPhilip M. Gollucci2009-12-261-1/+1