-
Notifications
You must be signed in to change notification settings - Fork 2
/
release.js
53 lines (49 loc) · 1.88 KB
/
release.js
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
/*
* @Author : HCLonely
* @Date : 2022-01-16 19:03:01
* @LastEditTime : 2022-12-10 10:12:35
* @LastEditors : HCLonely
* @FilePath : /auto-task-new/release.js
* @Description : 自动发布Release
*/
/* eslint-disable @typescript-eslint/no-var-requires, camelcase */
const fs = require('fs-extra');
const yaml = require('js-yaml');
const chalk = require('chalk');
const settings = yaml.load(fs.readFileSync('./.github/workflows/Release.yml', 'utf8'));
if (!settings) {
return console.log(`'./.github/workflows/Release.yml' ${chalk.red.bold('not found')}!`);
}
const steps = settings.jobs?.release?.steps;
const releaseStep = steps[steps.length - 1];
if (releaseStep?.name !== 'Release') {
return console.log(`Release action chenged ${chalk.red.bold('failed [no Release step]')}!`);
}
const options = {};
const { version, change } = fs.readJSONSync('./package.json');
if (version === releaseStep.with.name) {
settings.on = 'workflow_dispatch';
fs.writeFileSync('./.github/workflows/Release.yml', yaml.dump(settings));
console.log(`Version ${chalk.yellow.bold('not be changed')}!`);
// return console.log(`Release action changed ${chalk.green.bold('successfully')}!`);
}
settings.on = {
push: {
branches: ['main'],
paths: ['src/**', '.github/workflows/Release.yml']
}
};
options.prerelease = version.includes('-');
options.tag_name = `v${version}`;
options.name = version;
options.body = `- ${change.join('\n- ')}`;
options.files = `dist/auto-task-v4-for-giveawaysu.user.js
dist/auto-task-v4.compatibility.user.js
dist/auto-task-v4.user.js
dist/auto-task-v4-for-giveawaysu.all.user.js
dist/auto-task-v4.compatibility.all.user.js
dist/auto-task-v4.all.user.js`;
options.token = '${{ github.TOKEN }}';
releaseStep.with = options;
fs.writeFileSync('./.github/workflows/Release.yml', yaml.dump(settings));
console.log(`Release action changed ${chalk.green.bold('successfully')}!`);