Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(pipeline): second attempt to fix tests #2

Merged
merged 16 commits into from
Mar 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
package_json_path: ../package.json
uses: Drassil/gh-actions-collection/prepare@master
9 changes: 6 additions & 3 deletions prepare/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -29,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 }}
INPUT_PACKAGE_JSON_PATH: ${{ inputs.package_json_path }}
run: |
node "${{ github.action_path }}/index.js"
22 changes: 12 additions & 10 deletions prepare/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,23 @@ 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
core.addPath(`${NPM_GLOBAL_DIR}/bin`);

console.log(core.getInput('package_json_path'), cwd)

const packagePath = core.getInput('package_json_path') || cwd;
const fs = require("fs")
const p = __dirname+'/../'

const packageJson = require(`${packagePath}/package.json`);
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`;

const packageJson = require(packageJsonPath);

step('NPM upgrade', () => {
child_process.execSync(`npm install -g npm@${getNpmVersion()}`, {
Expand All @@ -65,13 +71,9 @@ async function run() {
try {
await npmVersionCheck();

const ref = github.head_ref || github.ref_name;

const branch = ref.replace('refs/heads/', '');
const branch_id = branch.split('/');
const branch = getBranchName();

core.setOutput('github_branch', branch.toLowerCase());
core.setOutput('github_branch_id', branch_id[0].toLowerCase());
core.setOutput('github_branch', branch);

core.exportVariable('COMMIT_SHA', github.context.sha);
core.exportVariable('PACKAGE_VERSION', packageJson.version);
Expand Down
23 changes: 22 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = process.env.GITHUB_REF.replace(VALID_REF_PREFIX, '');
} else {
// coming from a PR
branchName = process.env.GITHUB_HEAD_REF;
}

return branchName;
}

module.exports = {
npmVersionCheck,
getNpmVersion
getNpmVersion,
getBranchName
};