Skip to content

Commit a3e3e79

Browse files
authored
Merge pull request #7 from jdiebold/handle-multiple-functions
tag repo for every handler in serverless stack
2 parents f3f9e11 + 6ebad55 commit a3e3e79

File tree

3 files changed

+1722
-20
lines changed

3 files changed

+1722
-20
lines changed

index.js

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,33 +34,35 @@ class ServerlessPlugin {
3434
if (!this.shouldRun()) {
3535
return;
3636
}
37-
const arn = await this.getArn();
38-
if (arn === undefined) {
37+
const arns = await this.getArns();
38+
if (arns.length === 0) {
3939
throw new Error('Serverless Version Tracker error: cannot retrieve deployed ARN');
4040
}
41-
const regex = /([-\w]*):(\d*)$/;
42-
const name = arn.match(regex)[1];
43-
const version = arn.match(regex)[2];
44-
const tag = `${name}-${version}`;
45-
this.serverless.cli.log(`Creating local git tag '${tag}'...`);
46-
const { stdout, stderr } = await exec(`git tag ${tag}`);
47-
if (stdout || stderr) {
48-
throw new Error(`stdout: ${stdout}; stderr: ${stderr}`);
49-
}
41+
arns.forEach(async (arn) => {
42+
const regex = /([-\w]*):(\d*)$/;
43+
const name = arn.match(regex)[1];
44+
const version = arn.match(regex)[2];
45+
const tag = `${name}-${version}`;
46+
this.serverless.cli.log(`Creating local git tag '${tag}'...`);
47+
const { stdout, stderr } = await exec(`git tag ${tag}`);
48+
if (stdout || stderr) {
49+
throw new Error(`stdout: ${stdout}; stderr: ${stderr}`);
50+
}
51+
});
5052
}
5153

52-
async getArn() {
54+
async getArns() {
5355
const resp = await this.provider.request('CloudFormation', 'describeStacks', { StackName: this.provider.naming.getStackName(this.stage) });
5456
const output = resp.Stacks[0].Outputs;
55-
let arn;
56-
let arns;
57+
let arns = [];
58+
let filteredOutputs;
5759
try {
58-
arns = output.filter(entry => entry.OutputKey.match('LambdaFunctionQualifiedArn'));
60+
filteredOutputs = output.filter(entry => entry.OutputKey.match('LambdaFunctionQualifiedArn'));
5961
} catch (error) {
60-
return arn;
62+
return arns;
6163
}
62-
arns.forEach((entry) => { arn = entry.OutputValue; });
63-
return arn;
64+
filteredOutputs.forEach((entry) => { arns.push(entry.OutputValue) });
65+
return arns
6466
}
6567

6668
shouldRun() {

0 commit comments

Comments
 (0)