-
Notifications
You must be signed in to change notification settings - Fork 323
/
python.ts
117 lines (104 loc) · 3.48 KB
/
python.ts
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
// Copyright 2019 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import {ReleasePR, ReleaseCandidate} from '../release-pr';
import {ConventionalCommits} from '../conventional-commits';
import {GitHubTag} from '../github';
import {checkpoint, CheckpointType} from '../util/checkpoint';
import {Update} from '../updaters/update';
import {Commit} from '../graphql-to-commits';
// Generic
import {Changelog} from '../updaters/changelog';
// Python specific.
import {SetupPy} from '../updaters/python/setup-py';
import {SetupCfg} from '../updaters/python/setup-cfg';
const CHANGELOG_SECTIONS = [
{type: 'feat', section: 'Features'},
{type: 'fix', section: 'Bug Fixes'},
{type: 'docs', section: 'Documentation'},
{type: 'chore', section: 'Miscellaneous Chores', hidden: true},
{type: 'refactor', section: 'Code Refactoring', hidden: true},
{type: 'test', section: 'Tests', hidden: true},
{type: 'build', section: 'Build System', hidden: true},
{type: 'ci', section: 'Continuous Integration', hidden: true},
];
export class Python extends ReleasePR {
static releaserName = 'python';
protected async _run() {
const latestTag: GitHubTag | undefined = await this.gh.latestTag();
const commits: Commit[] = await this.commits(
latestTag ? latestTag.sha : undefined
);
const cc = new ConventionalCommits({
commits,
githubRepoUrl: this.repoUrl,
bumpMinorPreMajor: this.bumpMinorPreMajor,
changelogSections: CHANGELOG_SECTIONS,
});
const candidate: ReleaseCandidate = await this.coerceReleaseCandidate(
cc,
latestTag
);
const changelogEntry: string = await cc.generateChangelogEntry({
version: candidate.version,
currentTag: `v${candidate.version}`,
previousTag: candidate.previousTag,
});
// don't create a release candidate until user facing changes
// (fix, feat, BREAKING CHANGE) have been made; a CHANGELOG that's
// one line is a good indicator that there were no interesting commits.
if (this.changelogEmpty(changelogEntry)) {
checkpoint(
`no user facing commits found since ${
latestTag ? latestTag.sha : 'beginning of time'
}`,
CheckpointType.Failure
);
return;
}
const updates: Update[] = [];
updates.push(
new Changelog({
path: 'CHANGELOG.md',
changelogEntry,
version: candidate.version,
packageName: this.packageName,
})
);
updates.push(
new SetupCfg({
path: 'setup.cfg',
changelogEntry,
version: candidate.version,
packageName: this.packageName,
})
);
updates.push(
new SetupPy({
path: 'setup.py',
changelogEntry,
version: candidate.version,
packageName: this.packageName,
})
);
await this.openPR(
commits[0].sha!,
`${changelogEntry}\n---\n`,
updates,
candidate.version
);
}
protected defaultInitialVersion(): string {
return '0.1.0';
}
}