forked from fengmk2/github-actions
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathindex.js
More file actions
68 lines (59 loc) · 2.41 KB
/
index.js
File metadata and controls
68 lines (59 loc) · 2.41 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
const path = require('path');
const fs = require('fs');
const core = require('@actions/core');
const semanticRelease = require('semantic-release').default;
const { request } = require('undici');
async function run() {
const mainRepoPath = process.cwd();
const pkgInfo = require(`${mainRepoPath}/package.json`);
const registry = pkgInfo.publishConfig?.registry || 'https://registry.npmjs.org';
core.setOutput('name', pkgInfo.name);
core.setOutput('registry', registry);
try {
const configFiles = [
path.join(__dirname, 'release.config.js'),
path.join(mainRepoPath, 'release.config.js'),
].filter(file => fs.existsSync(file));
core.info(`Using config files: ${configFiles.join(', ')}`);
const result = await semanticRelease({
dryRun: process.env.DRYRUN === 'true',
extends: configFiles,
});
const { nextRelease, lastRelease } = result;
if (!nextRelease) {
core.notice('No release need to be published.');
core.summary.addRaw('No release need to be published.');
await core.summary.write();
} else {
core.info(`Published release: ${nextRelease.version}`);
core.setOutput('release_version', nextRelease.version);
// cnpm sync
try {
const res = await request(`https://registry-direct.npmmirror.com/-/package/${pkgInfo.name}/syncs`, {
method: 'PUT',
timeout: 30000,
});
const { id } = await res.body.json();
const logUrl = `https://registry.npmmirror.com/-/package/${pkgInfo.name}/syncs/${id}/log`;
core.setOutput('cnpm_sync_url', logUrl);
core.info(`cnpm sync log url: ${logUrl}`);
// write summary
core.summary.addRaw(`## [${pkgInfo.name}](https://github.com/${process.env.GITHUB_REPOSITORY})\n`);
core.summary.addRaw(`- Release: ${lastRelease?.version ?? ''} -> ${nextRelease.version}\n`);
core.summary.addRaw(`- Registry: ${registry}\n`);
core.summary.addRaw(`- CNPM Sync: ${logUrl}\n`);
core.summary.addRaw(`- DryRun: ${process.env.DRYRUN}\n`);
} catch (err) {
core.info(`cnpm sync ${pkgInfo.name} fail, ${err.message}`);
core.summary.addRaw(`- CNPM Sync ${pkgInfo.name} error: ${err.message}\n`);
}
core.summary.addRaw(nextRelease.notes);
await core.summary.write();
}
console.log('Result:', result);
} catch (error) {
console.error(error);
core.setFailed(error);
}
}
run();