Skip to content

Commit 872e79e

Browse files
committed
Fail gracefully with an error message when appspec.yml is missing
1 parent 1874ac5 commit 872e79e

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

create-deployment.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
'use strict';
22

3-
function fetchBranchConfig(branchName) {
3+
function fetchBranchConfig(branchName, core) {
44
const fs = require('fs');
55
const yaml = require('js-yaml');
66

7-
let fileContents = fs.readFileSync('./appspec.yml', 'utf8');
7+
try {
8+
let fileContents = fs.readFileSync('./appspec.yml', 'utf8');
9+
} catch (e) {
10+
if (e.code == 'ENOENT') {
11+
core.setFailed('🙄 appspec.yml file not found. Hint: Did you run actions/checkout?');
12+
process.exit();
13+
} else {
14+
throw e;
15+
}
16+
}
817
let data = yaml.safeLoad(fileContents);
918

1019
for (var prop in data.branch_config) {
@@ -24,7 +33,7 @@ function fetchBranchConfig(branchName) {
2433
}
2534

2635
exports.createDeployment = async function(applicationName, fullRepositoryName, branchName, commitId, runNumber, skipSequenceCheck, core) {
27-
const branchConfig = fetchBranchConfig(branchName);
36+
const branchConfig = fetchBranchConfig(branchName, core);
2837
const safeBranchName = branchName.replace(/[^a-z0-9-/]+/gi, '-').replace(/\/+/, '--');
2938
const deploymentGroupName = branchConfig.deploymentGroupName ? branchConfig.deploymentGroupName.replace('$BRANCH', safeBranchName) : safeBranchName;
3039
const deploymentGroupConfig = branchConfig.deploymentGroupConfig;

0 commit comments

Comments
 (0)