From 872e79eec5f691fbe9377998678de74b95312971 Mon Sep 17 00:00:00 2001 From: Matthias Pigulla Date: Wed, 29 Jun 2022 20:41:37 +0000 Subject: [PATCH 1/2] Fail gracefully with an error message when appspec.yml is missing --- create-deployment.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/create-deployment.js b/create-deployment.js index 237b37f..b1f9721 100644 --- a/create-deployment.js +++ b/create-deployment.js @@ -1,10 +1,19 @@ 'use strict'; -function fetchBranchConfig(branchName) { +function fetchBranchConfig(branchName, core) { const fs = require('fs'); const yaml = require('js-yaml'); - let fileContents = fs.readFileSync('./appspec.yml', 'utf8'); + try { + let fileContents = fs.readFileSync('./appspec.yml', 'utf8'); + } catch (e) { + if (e.code == 'ENOENT') { + core.setFailed('🙄 appspec.yml file not found. Hint: Did you run actions/checkout?'); + process.exit(); + } else { + throw e; + } + } let data = yaml.safeLoad(fileContents); for (var prop in data.branch_config) { @@ -24,7 +33,7 @@ function fetchBranchConfig(branchName) { } exports.createDeployment = async function(applicationName, fullRepositoryName, branchName, commitId, runNumber, skipSequenceCheck, core) { - const branchConfig = fetchBranchConfig(branchName); + const branchConfig = fetchBranchConfig(branchName, core); const safeBranchName = branchName.replace(/[^a-z0-9-/]+/gi, '-').replace(/\/+/, '--'); const deploymentGroupName = branchConfig.deploymentGroupName ? branchConfig.deploymentGroupName.replace('$BRANCH', safeBranchName) : safeBranchName; const deploymentGroupConfig = branchConfig.deploymentGroupConfig; From defbeb8f38cd5d3675872185d3dbc45bcf8ec437 Mon Sep 17 00:00:00 2001 From: Matthias Pigulla Date: Wed, 29 Jun 2022 20:43:05 +0000 Subject: [PATCH 2/2] Update dist/ --- dist/index.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/dist/index.js b/dist/index.js index c24dd6a..77cfb46 100644 --- a/dist/index.js +++ b/dist/index.js @@ -16,11 +16,20 @@ module.exports = JSON.parse("{\"name\":\"@octokit/rest\",\"version\":\"16.43.2\" "use strict"; -function fetchBranchConfig(branchName) { +function fetchBranchConfig(branchName, core) { const fs = __webpack_require__(5747); const yaml = __webpack_require__(1917); - let fileContents = fs.readFileSync('./appspec.yml', 'utf8'); + try { + let fileContents = fs.readFileSync('./appspec.yml', 'utf8'); + } catch (e) { + if (e.code == 'ENOENT') { + core.setFailed('🙄 appspec.yml file not found. Hint: Did you run actions/checkout?'); + process.exit(); + } else { + throw e; + } + } let data = yaml.safeLoad(fileContents); for (var prop in data.branch_config) { @@ -40,7 +49,7 @@ function fetchBranchConfig(branchName) { } exports.createDeployment = async function(applicationName, fullRepositoryName, branchName, commitId, runNumber, skipSequenceCheck, core) { - const branchConfig = fetchBranchConfig(branchName); + const branchConfig = fetchBranchConfig(branchName, core); const safeBranchName = branchName.replace(/[^a-z0-9-/]+/gi, '-').replace(/\/+/, '--'); const deploymentGroupName = branchConfig.deploymentGroupName ? branchConfig.deploymentGroupName.replace('$BRANCH', safeBranchName) : safeBranchName; const deploymentGroupConfig = branchConfig.deploymentGroupConfig;