Skip to content

Commit ba5d416

Browse files
authored
Fail gracefully with an error message when appspec.yml is missing (#19)
Fail gracefully when the `appspec.yml` file was not found. Might be a common mistake to forget running `actions/checkout` before this action here. Closes #10.
1 parent 1874ac5 commit ba5d416

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
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;

dist/index.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,20 @@ module.exports = JSON.parse("{\"name\":\"@octokit/rest\",\"version\":\"16.43.2\"
1616
"use strict";
1717

1818

19-
function fetchBranchConfig(branchName) {
19+
function fetchBranchConfig(branchName, core) {
2020
const fs = __webpack_require__(5747);
2121
const yaml = __webpack_require__(1917);
2222

23-
let fileContents = fs.readFileSync('./appspec.yml', 'utf8');
23+
try {
24+
let fileContents = fs.readFileSync('./appspec.yml', 'utf8');
25+
} catch (e) {
26+
if (e.code == 'ENOENT') {
27+
core.setFailed('🙄 appspec.yml file not found. Hint: Did you run actions/checkout?');
28+
process.exit();
29+
} else {
30+
throw e;
31+
}
32+
}
2433
let data = yaml.safeLoad(fileContents);
2534

2635
for (var prop in data.branch_config) {
@@ -40,7 +49,7 @@ function fetchBranchConfig(branchName) {
4049
}
4150

4251
exports.createDeployment = async function(applicationName, fullRepositoryName, branchName, commitId, runNumber, skipSequenceCheck, core) {
43-
const branchConfig = fetchBranchConfig(branchName);
52+
const branchConfig = fetchBranchConfig(branchName, core);
4453
const safeBranchName = branchName.replace(/[^a-z0-9-/]+/gi, '-').replace(/\/+/, '--');
4554
const deploymentGroupName = branchConfig.deploymentGroupName ? branchConfig.deploymentGroupName.replace('$BRANCH', safeBranchName) : safeBranchName;
4655
const deploymentGroupConfig = branchConfig.deploymentGroupConfig;

0 commit comments

Comments
 (0)