-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
38 lines (33 loc) · 991 Bytes
/
index.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
const AWS = require('aws-sdk');
const trigger = process.env.INPUT_TRIGGERED_BY || 'default-trigger';
let ref = process.env.REF || 'refs/heads/dev';
let tag = '';
let message;
if (ref === 'refs/heads/dev') {
ref = 'dev';
message = {"Message": trigger};
} else {
tag = ref;
ref = 'staging';
message = {"Message": trigger + ':' + tag};
}
const topicArn = (ref === 'dev') ? process.env.AWS_SNS_ARN_DEV : process.env.AWS_SNS_ARN_STAGING;
const params = {
Message: JSON.stringify(message),
TopicArn: topicArn,
MessageGroupId: 'github-repo-update',
};
AWS.config.update({
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
region: 'ca-central-1',
});
const sns = new AWS.SNS({apiVersion: '2010-03-31'});
console.log("params: ", params);
sns.publish(params, function(err, data) {
if (err) {
console.error("Error sending message: ", err);
} else {
console.log("Message sent successfully: ", data.MessageId);
}
});