From 79e08b4fbc6dadadee1cd1a4c051d22dc216d71f Mon Sep 17 00:00:00 2001 From: Yehonal Date: Fri, 4 Mar 2022 09:10:25 +0100 Subject: [PATCH 01/16] fix(pipeline): second attempt to fix tests --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4738eeb..4869cde 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -24,5 +24,5 @@ jobs: with: npm_version: ${{ env.NPM_VERSION }} node_version: ${{ env.NODE_VERSION }} - package_json_path: "$GITHUB_WORKSPACE/../fix-pipeline/package.json" - uses: Drassil/gh-actions-collection/prepare@fix-pipeline \ No newline at end of file + package_json_path: "$GITHUB_WORKSPACE/../master/package.json" + uses: Drassil/gh-actions-collection/prepare@master \ No newline at end of file From c4ecd42e07c805cfe595885d9e75685507334e41 Mon Sep 17 00:00:00 2001 From: Yehonal Date: Fri, 4 Mar 2022 09:14:04 +0100 Subject: [PATCH 02/16] fix ref name --- prepare/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prepare/index.js b/prepare/index.js index 8bd8b9d..480c0eb 100644 --- a/prepare/index.js +++ b/prepare/index.js @@ -65,7 +65,7 @@ async function run() { try { await npmVersionCheck(); - const ref = github.head_ref || github.ref_name; + const ref = github.context.head_ref || github.context.ref_name; const branch = ref.replace('refs/heads/', ''); const branch_id = branch.split('/'); From c2f4c427190ffc84055c9d9a0e62235f7d06952e Mon Sep 17 00:00:00 2001 From: Yehonal Date: Fri, 4 Mar 2022 09:15:13 +0100 Subject: [PATCH 03/16] log --- prepare/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/prepare/index.js b/prepare/index.js index 480c0eb..3be4f80 100644 --- a/prepare/index.js +++ b/prepare/index.js @@ -66,6 +66,7 @@ async function run() { await npmVersionCheck(); const ref = github.context.head_ref || github.context.ref_name; + console.log(github.context, ref); const branch = ref.replace('refs/heads/', ''); const branch_id = branch.split('/'); From 48b952cde10a09e1e3e3018d548b22f7c842413e Mon Sep 17 00:00:00 2001 From: Yehonal Date: Fri, 4 Mar 2022 09:17:17 +0100 Subject: [PATCH 04/16] log --- prepare/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prepare/index.js b/prepare/index.js index 3be4f80..935b193 100644 --- a/prepare/index.js +++ b/prepare/index.js @@ -66,7 +66,7 @@ async function run() { await npmVersionCheck(); const ref = github.context.head_ref || github.context.ref_name; - console.log(github.context, ref); + console.log(github, ref); const branch = ref.replace('refs/heads/', ''); const branch_id = branch.split('/'); From ddc6d821a51d367bfe78953d793a877d634efca0 Mon Sep 17 00:00:00 2001 From: Yehonal Date: Fri, 4 Mar 2022 09:33:58 +0100 Subject: [PATCH 05/16] test --- prepare/index.js | 10 ++++------ src/utils.js | 23 ++++++++++++++++++++++- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/prepare/index.js b/prepare/index.js index 935b193..43e8e15 100644 --- a/prepare/index.js +++ b/prepare/index.js @@ -32,7 +32,7 @@ step('Npm action modules install', () => { }); // now we can require the action modules -const { npmVersionCheck, getNpmVersion } = require(`../src/utils`); +const { npmVersionCheck, getNpmVersion, getBranchName } = require(`../src/utils`); const core = require('@actions/core'); const github = require('@actions/github'); // set new npm dir in pipeline paths @@ -65,14 +65,12 @@ async function run() { try { await npmVersionCheck(); - const ref = github.context.head_ref || github.context.ref_name; - console.log(github, ref); + const branch = getBranchName(); - const branch = ref.replace('refs/heads/', ''); - const branch_id = branch.split('/'); + console.log(branch); core.setOutput('github_branch', branch.toLowerCase()); - core.setOutput('github_branch_id', branch_id[0].toLowerCase()); + core.setOutput('github_branch_id', branch.toLowerCase()); core.exportVariable('COMMIT_SHA', github.context.sha); core.exportVariable('PACKAGE_VERSION', packageJson.version); diff --git a/src/utils.js b/src/utils.js index 442f14b..3b3318b 100644 --- a/src/utils.js +++ b/src/utils.js @@ -38,7 +38,28 @@ function getNpmVersion() { return core.getInput('npm_version') || NPM_VERSION } +const VALID_REF_PREFIX = 'refs/heads/'; + +function getBranchName() { + let branchName; + + /** + * When the workflow is invoked from manual flow, the branch name + * is in GITHUB_REF, otherwise, we have to look into GITHUB_BASE_REF + */ + if (process.env.GITHUB_REF.startsWith(VALID_REF_PREFIX)) { + // coming from a manual workflow trigger + branchName = `origin/${process.env.GITHUB_REF.replace(VALID_REF_PREFIX, '')}`; + } else { + // coming from a PR + branchName = `origin/${process.env.GITHUB_HEAD_REF}`; + } + + return branchName; +} + module.exports = { npmVersionCheck, - getNpmVersion + getNpmVersion, + getBranchName }; From ff7196b6c9dbdab4ba136c6a86dd1d1ce100d159 Mon Sep 17 00:00:00 2001 From: Yehonal Date: Fri, 4 Mar 2022 09:56:11 +0100 Subject: [PATCH 06/16] fix --- prepare/action.yml | 4 +--- prepare/index.js | 5 +---- src/utils.js | 4 ++-- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/prepare/action.yml b/prepare/action.yml index 8f9db90..a9bbe30 100644 --- a/prepare/action.yml +++ b/prepare/action.yml @@ -2,9 +2,7 @@ name: 'action-prepare' description: 'Reusable actions for the frontend workflows' outputs: github_branch: - description: 'Github branch name in lowercase' - github_branch_id: - description: 'Task ID in lowercase' + description: 'Github branch name' inputs: node_version: description: 'node version used for the node commands' diff --git a/prepare/index.js b/prepare/index.js index 43e8e15..b44661a 100644 --- a/prepare/index.js +++ b/prepare/index.js @@ -67,10 +67,7 @@ async function run() { const branch = getBranchName(); - console.log(branch); - - core.setOutput('github_branch', branch.toLowerCase()); - core.setOutput('github_branch_id', branch.toLowerCase()); + core.setOutput('github_branch', branch); core.exportVariable('COMMIT_SHA', github.context.sha); core.exportVariable('PACKAGE_VERSION', packageJson.version); diff --git a/src/utils.js b/src/utils.js index 3b3318b..ba73571 100644 --- a/src/utils.js +++ b/src/utils.js @@ -49,10 +49,10 @@ function getBranchName() { */ if (process.env.GITHUB_REF.startsWith(VALID_REF_PREFIX)) { // coming from a manual workflow trigger - branchName = `origin/${process.env.GITHUB_REF.replace(VALID_REF_PREFIX, '')}`; + branchName = process.env.GITHUB_REF.replace(VALID_REF_PREFIX, ''); } else { // coming from a PR - branchName = `origin/${process.env.GITHUB_HEAD_REF}`; + branchName = process.env.GITHUB_HEAD_REF; } return branchName; From 5a3c5d6e950c9cd48f633d2c2ad891343bcb044c Mon Sep 17 00:00:00 2001 From: Yehonal Date: Fri, 4 Mar 2022 11:04:54 +0100 Subject: [PATCH 07/16] fix --- prepare/action.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/prepare/action.yml b/prepare/action.yml index a9bbe30..a0ddf72 100644 --- a/prepare/action.yml +++ b/prepare/action.yml @@ -27,5 +27,10 @@ runs: node-version: ${{ github.event.inputs.node_version }} - name: Prepare shell: bash + env: + # needed because of this bug: https://github.com/actions/runner/issues/665 + INPUT_NODE_VERSION: ${{ inputs.node_version }} + INPUT_NPM_VERSION: ${{ inputs.npm_version }} + PACKAGE_JSON_PATH: ${{ inputs.package_json_path }} run: | node "${{ github.action_path }}/index.js" From d7c64dc8d983e514fa50587056ca3b37ce01154c Mon Sep 17 00:00:00 2001 From: Yehonal Date: Fri, 4 Mar 2022 11:06:33 +0100 Subject: [PATCH 08/16] fix --- prepare/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prepare/action.yml b/prepare/action.yml index a0ddf72..a323ac1 100644 --- a/prepare/action.yml +++ b/prepare/action.yml @@ -31,6 +31,6 @@ runs: # needed because of this bug: https://github.com/actions/runner/issues/665 INPUT_NODE_VERSION: ${{ inputs.node_version }} INPUT_NPM_VERSION: ${{ inputs.npm_version }} - PACKAGE_JSON_PATH: ${{ inputs.package_json_path }} + INPUT_PACKAGE_JSON_PATH: ${{ inputs.package_json_path }} run: | node "${{ github.action_path }}/index.js" From 39972820fabacb120ac71e225f609902c16168dc Mon Sep 17 00:00:00 2001 From: Yehonal Date: Fri, 4 Mar 2022 11:10:28 +0100 Subject: [PATCH 09/16] log --- prepare/index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/prepare/index.js b/prepare/index.js index b44661a..980be34 100644 --- a/prepare/index.js +++ b/prepare/index.js @@ -38,6 +38,8 @@ const github = require('@actions/github'); // set new npm dir in pipeline paths core.addPath(`${NPM_GLOBAL_DIR}/bin`); +console.log(process.env); + console.log(core.getInput('package_json_path'), cwd) const packagePath = core.getInput('package_json_path') || cwd; From 4cb6d5c09255047e4ef32b2a8abbcc4da5196019 Mon Sep 17 00:00:00 2001 From: Yehonal Date: Fri, 4 Mar 2022 11:23:21 +0100 Subject: [PATCH 10/16] test --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4869cde..4c7e7ba 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -24,5 +24,5 @@ jobs: with: npm_version: ${{ env.NPM_VERSION }} node_version: ${{ env.NODE_VERSION }} - package_json_path: "$GITHUB_WORKSPACE/../master/package.json" - uses: Drassil/gh-actions-collection/prepare@master \ No newline at end of file + package_json_path: "$GITHUB_WORKSPACE/../prepare@fix(pipeline)--second-attempt-to-fix-tests/package.json" + uses: Drassil/gh-actions-collection/prepare@fix(pipeline)--second-attempt-to-fix-tests \ No newline at end of file From da92292e704ca39acdcac32cd23c3d22ccb0bd5b Mon Sep 17 00:00:00 2001 From: Yehonal Date: Fri, 4 Mar 2022 11:43:57 +0100 Subject: [PATCH 11/16] test --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4c7e7ba..67153bb 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -24,5 +24,5 @@ jobs: with: npm_version: ${{ env.NPM_VERSION }} node_version: ${{ env.NODE_VERSION }} - package_json_path: "$GITHUB_WORKSPACE/../prepare@fix(pipeline)--second-attempt-to-fix-tests/package.json" + package_json_path: ${{ env.GITHUB_WORKSPACE }}"/../prepare@fix(pipeline)--second-attempt-to-fix-tests/package.json" uses: Drassil/gh-actions-collection/prepare@fix(pipeline)--second-attempt-to-fix-tests \ No newline at end of file From b4ee19344f77ba57deecdae9b462068da25bb735 Mon Sep 17 00:00:00 2001 From: Yehonal Date: Fri, 4 Mar 2022 11:47:22 +0100 Subject: [PATCH 12/16] fix --- .github/workflows/test.yml | 2 +- prepare/index.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 67153bb..e50267b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -24,5 +24,5 @@ jobs: with: npm_version: ${{ env.NPM_VERSION }} node_version: ${{ env.NODE_VERSION }} - package_json_path: ${{ env.GITHUB_WORKSPACE }}"/../prepare@fix(pipeline)--second-attempt-to-fix-tests/package.json" + package_json_path: ${{ env.GITHUB_WORKSPACE }}/../prepare@fix(pipeline)--second-attempt-to-fix-tests/package.json uses: Drassil/gh-actions-collection/prepare@fix(pipeline)--second-attempt-to-fix-tests \ No newline at end of file diff --git a/prepare/index.js b/prepare/index.js index 980be34..dfa7f0b 100644 --- a/prepare/index.js +++ b/prepare/index.js @@ -42,9 +42,9 @@ console.log(process.env); console.log(core.getInput('package_json_path'), cwd) -const packagePath = core.getInput('package_json_path') || cwd; +const packageJsonPath = core.getInput('package_json_path') || `${cwd}/package.json`; -const packageJson = require(`${packagePath}/package.json`); +const packageJson = require(packageJsonPath); step('NPM upgrade', () => { child_process.execSync(`npm install -g npm@${getNpmVersion()}`, { From c1b3abf8cb35308df5be0450b4ac98fe660f210e Mon Sep 17 00:00:00 2001 From: Yehonal Date: Fri, 4 Mar 2022 11:50:25 +0100 Subject: [PATCH 13/16] absolute path --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e50267b..188cb2b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -24,5 +24,5 @@ jobs: with: npm_version: ${{ env.NPM_VERSION }} node_version: ${{ env.NODE_VERSION }} - package_json_path: ${{ env.GITHUB_WORKSPACE }}/../prepare@fix(pipeline)--second-attempt-to-fix-tests/package.json + package_json_path: /home/runner/work/_actions/Drassil/gh-actions-collection/prepare@fix(pipeline)--second-attempt-to-fix-tests/package.json uses: Drassil/gh-actions-collection/prepare@fix(pipeline)--second-attempt-to-fix-tests \ No newline at end of file From d73beec3d526b1da9e4f31b3104e15f8ba2ebfcb Mon Sep 17 00:00:00 2001 From: Yehonal Date: Fri, 4 Mar 2022 11:59:44 +0100 Subject: [PATCH 14/16] test --- prepare/index.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/prepare/index.js b/prepare/index.js index dfa7f0b..07286aa 100644 --- a/prepare/index.js +++ b/prepare/index.js @@ -38,9 +38,13 @@ const github = require('@actions/github'); // set new npm dir in pipeline paths core.addPath(`${NPM_GLOBAL_DIR}/bin`); -console.log(process.env); -console.log(core.getInput('package_json_path'), cwd) +const fs = require("fs") +const p = __dirname+'/../' + +const filesArray = fs.readdirSync(p).filter(file => fs.lstatSync(p+file).isFile()) + +console.log(filesArray, p, core.getInput('package_json_path'), cwd) const packageJsonPath = core.getInput('package_json_path') || `${cwd}/package.json`; From 5415ddbd3c36ba193e49dd601066b146444dbc24 Mon Sep 17 00:00:00 2001 From: Yehonal Date: Fri, 4 Mar 2022 12:01:46 +0100 Subject: [PATCH 15/16] test --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 188cb2b..3f7f27b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -24,5 +24,5 @@ jobs: with: npm_version: ${{ env.NPM_VERSION }} node_version: ${{ env.NODE_VERSION }} - package_json_path: /home/runner/work/_actions/Drassil/gh-actions-collection/prepare@fix(pipeline)--second-attempt-to-fix-tests/package.json + package_json_path: ../package.json uses: Drassil/gh-actions-collection/prepare@fix(pipeline)--second-attempt-to-fix-tests \ No newline at end of file From 1c51170317f988c2ce8b41f35f4dc178dd87858d Mon Sep 17 00:00:00 2001 From: Yehonal Date: Fri, 4 Mar 2022 12:02:53 +0100 Subject: [PATCH 16/16] test --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3f7f27b..65e4130 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -25,4 +25,4 @@ jobs: npm_version: ${{ env.NPM_VERSION }} node_version: ${{ env.NODE_VERSION }} package_json_path: ../package.json - uses: Drassil/gh-actions-collection/prepare@fix(pipeline)--second-attempt-to-fix-tests \ No newline at end of file + uses: Drassil/gh-actions-collection/prepare@master \ No newline at end of file