-
Notifications
You must be signed in to change notification settings - Fork 373
/
Copy pathterraform-module.ts
115 lines (107 loc) · 3.25 KB
/
terraform-module.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
// Copyright 2020 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.
// Generic
import {Changelog} from '../updaters/changelog';
// Terraform specific.
import {ReadMe} from '../updaters/terraform/readme';
import {ModuleVersion} from '../updaters/terraform/module-version';
import {MetadataVersion} from '../updaters/terraform/metadata-version';
import {BaseStrategy, BuildUpdatesOptions} from './base';
import {Update} from '../update';
import {Version} from '../version';
export class TerraformModule extends BaseStrategy {
protected async buildUpdates(
options: BuildUpdatesOptions
): Promise<Update[]> {
const updates: Update[] = [];
const version = options.newVersion;
updates.push({
path: this.addPath(this.changelogPath),
createIfMissing: true,
updater: new Changelog({
version,
changelogEntry: options.changelogEntry,
}),
});
// Update version in README to current candidate version.
// A module may have submodules, so find all submodules.
const readmeFiles = await Promise.all([
this.github.findFilesByFilenameAndRef(
'readme.md',
this.targetBranch,
this.path
),
this.github.findFilesByFilenameAndRef(
'README.md',
this.targetBranch,
this.path
),
]).then(([v, vt]) => {
return v.concat(vt);
});
readmeFiles.forEach(path => {
updates.push({
path: this.addPath(path),
createIfMissing: false,
updater: new ReadMe({
version,
}),
});
});
// Update versions.tf to current candidate version.
// A module may have submodules, so find all versions.tfand versions.tf.tmpl to update.
const versionFiles = await Promise.all([
this.github.findFilesByFilenameAndRef(
'versions.tf',
this.targetBranch,
this.path
),
this.github.findFilesByFilenameAndRef(
'versions.tf.tmpl',
this.targetBranch,
this.path
),
]).then(([v, vt]) => {
return v.concat(vt);
});
versionFiles.forEach(path => {
updates.push({
path: this.addPath(path),
createIfMissing: false,
updater: new ModuleVersion({
version,
}),
});
});
// Update metadata.yaml to current candidate version.
const metadataFiles = await this.github.findFilesByFilenameAndRef(
'metadata.yaml',
this.targetBranch,
this.path
);
metadataFiles.forEach(path => {
updates.push({
path: this.addPath(path),
createIfMissing: false,
updater: new MetadataVersion({
version,
}),
});
});
return updates;
}
protected initialReleaseVersion(): Version {
return Version.parse('0.1.0');
}
}