forked from atom/atom
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupload-artifacts.js
More file actions
172 lines (153 loc) · 4.96 KB
/
Copy pathupload-artifacts.js
File metadata and controls
172 lines (153 loc) · 4.96 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
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
'use strict';
const fs = require('fs');
const os = require('os');
const path = require('path');
const glob = require('glob');
const spawnSync = require('../lib/spawn-sync');
const publishRelease = require('publish-release');
const releaseNotes = require('./lib/release-notes');
const uploadToS3 = require('./lib/upload-to-s3');
const uploadLinuxPackages = require('./lib/upload-linux-packages');
const CONFIG = require('../config');
const yargs = require('yargs');
const argv = yargs
.usage('Usage: $0 [options]')
.help('help')
.describe(
'assets-path',
'Path to the folder where all release assets are stored'
)
.describe(
's3-path',
'Indicates the S3 path in which the assets should be uploaded'
)
.describe(
'create-github-release',
'Creates a GitHub release for this build, draft if release branch or public if Nightly'
)
.describe(
'linux-repo-name',
'If specified, uploads Linux packages to the given repo name on packagecloud'
)
.wrap(yargs.terminalWidth()).argv;
const releaseVersion = CONFIG.computedAppVersion;
const isNightlyRelease = CONFIG.channel === 'nightly';
const assetsPath = argv.assetsPath || CONFIG.buildOutputPath;
const assetsPattern =
'/**/*(*.exe|*.zip|*.nupkg|*.tar.gz|*.rpm|*.deb|RELEASES*|atom-api.json)';
const assets = glob.sync(assetsPattern, { root: assetsPath, nodir: true });
const bucketPath = argv.s3Path || `releases/v${releaseVersion}/`;
if (!assets || assets.length === 0) {
console.error(`No assets found under specified path: ${assetsPath}`);
process.exit(1);
}
async function uploadArtifacts() {
let releaseForVersion = await releaseNotes.getRelease(
releaseVersion,
process.env.GITHUB_TOKEN
);
if (releaseForVersion.exists && !releaseForVersion.isDraft) {
console.log(
`Published release already exists for ${releaseVersion}, skipping upload.`
);
return;
}
console.log(
`Uploading ${
assets.length
} release assets for ${releaseVersion} to S3 under '${bucketPath}'`
);
await uploadToS3(
process.env.ATOM_RELEASES_S3_KEY,
process.env.ATOM_RELEASES_S3_SECRET,
process.env.ATOM_RELEASES_S3_BUCKET,
bucketPath,
assets
);
if (argv.linuxRepoName) {
await uploadLinuxPackages(
argv.linuxRepoName,
process.env.PACKAGE_CLOUD_API_KEY,
releaseVersion,
assets
);
} else {
console.log(
'\nNo Linux package repo name specified, skipping Linux package upload.'
);
}
const oldReleaseNotes = releaseForVersion.releaseNotes;
if (oldReleaseNotes) {
const oldReleaseNotesPath = path.resolve(
os.tmpdir(),
'OLD_RELEASE_NOTES.md'
);
console.log(
`Saving existing ${releaseVersion} release notes to ${oldReleaseNotesPath}`
);
fs.writeFileSync(oldReleaseNotesPath, oldReleaseNotes, 'utf8');
// This line instructs VSTS to upload the file as an artifact
console.log(
`##vso[artifact.upload containerfolder=OldReleaseNotes;artifactname=OldReleaseNotes;]${oldReleaseNotesPath}`
);
}
if (argv.createGithubRelease) {
console.log(`\nGenerating new release notes for ${releaseVersion}`);
let newReleaseNotes = '';
if (isNightlyRelease) {
newReleaseNotes = await releaseNotes.generateForNightly(
releaseVersion,
process.env.GITHUB_TOKEN,
oldReleaseNotes
);
} else {
newReleaseNotes = await releaseNotes.generateForVersion(
releaseVersion,
process.env.GITHUB_TOKEN,
oldReleaseNotes
);
}
console.log(`New release notes:\n\n${newReleaseNotes}`);
const releaseSha = !isNightlyRelease
? spawnSync('git', ['rev-parse', 'HEAD'])
.stdout.toString()
.trimEnd()
: 'master'; // Nightly tags are created in atom/atom-nightly-releases so the SHA is irrelevant
console.log(`Creating GitHub release v${releaseVersion}`);
const release = await publishReleaseAsync({
token: process.env.GITHUB_TOKEN,
owner: 'atom',
repo: !isNightlyRelease ? 'atom' : 'atom-nightly-releases',
name: CONFIG.computedAppVersion,
notes: newReleaseNotes,
target_commitish: releaseSha,
tag: `v${CONFIG.computedAppVersion}`,
draft: !isNightlyRelease,
prerelease: CONFIG.channel !== 'stable',
editRelease: true,
reuseRelease: true,
skipIfPublished: true,
assets
});
console.log('Release published successfully: ', release.html_url);
} else {
console.log('Skipping GitHub release creation');
}
}
async function publishReleaseAsync(options) {
return new Promise((resolve, reject) => {
publishRelease(options, (err, release) => {
if (err) {
reject(err);
} else {
resolve(release);
}
});
});
}
// Wrap the call the async function and catch errors from its promise because
// Node.js doesn't yet allow use of await at the script scope
uploadArtifacts().catch(err => {
console.error('An error occurred while uploading the release:\n\n', err);
process.exit(1);
});