From 872e79eec5f691fbe9377998678de74b95312971 Mon Sep 17 00:00:00 2001 From: Matthias Pigulla Date: Wed, 29 Jun 2022 20:41:37 +0000 Subject: [PATCH 1/3] 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/3] 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; From 3188023e8b9087de814958b01aa69fe53a17f136 Mon Sep 17 00:00:00 2001 From: Matthias Pigulla Date: Wed, 29 Jun 2022 21:36:59 +0000 Subject: [PATCH 3/3] Fix variable scoping issue --- create-deployment.js | 2 +- dist/index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/create-deployment.js b/create-deployment.js index b1f9721..9a39f63 100644 --- a/create-deployment.js +++ b/create-deployment.js @@ -5,7 +5,7 @@ function fetchBranchConfig(branchName, core) { const yaml = require('js-yaml'); try { - let fileContents = fs.readFileSync('./appspec.yml', 'utf8'); + var 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?'); diff --git a/dist/index.js b/dist/index.js index 77cfb46..cf1b2fa 100644 --- a/dist/index.js +++ b/dist/index.js @@ -21,7 +21,7 @@ function fetchBranchConfig(branchName, core) { const yaml = __webpack_require__(1917); try { - let fileContents = fs.readFileSync('./appspec.yml', 'utf8'); + var 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?');