-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use javascript-action instead of platform dependend Shell commands
Instead of a simple "test -x eldev" test, eldev is actually bootstrapped again to verify that the net-installation was indeed successful. The previous shell tests also used the hardcoded path https://raw.github.com/doublep/eldev/master/bin/eldev to download the eldev scripts. So CI newer tested changes introduced in PRs. The utility function getRawUrl generates the correct raw download URL depending on the context (pushing to master or PR) and also adds a platform dependent suffix (.bat on Windows) to the script name to make the script download/testing platform-agnostic.
- Loading branch information
1 parent
99ed26e
commit 77bb883
Showing
2 changed files
with
80 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
const os = require('os'); | ||
const fs = require('fs'); | ||
const {sep, join, basename} = require('path'); | ||
const suffix = (os.type() === 'Windows_NT') ? '.bat' : ''; | ||
|
||
// Get raw download URL for path in this repo or pull-request repo | ||
// (depending on context) automatically adds (.bat) extension to path | ||
// if running on windows to make Github actions steps platform agnostic | ||
function getRawUrl(context, path) { | ||
const {repository, pull_request} = context.payload; | ||
const branch = pull_request ? pull_request.head.ref : repository.default_branch; | ||
const repo_full_name = pull_request ? pull_request.head.repo.full_name : repository.full_name; | ||
return `https://raw.github.com/${repo_full_name}/${branch}/${path}${suffix}`; | ||
} | ||
|
||
// Download script and make it executable (required on Unix) | ||
async function downloadScript(github, context, file, outdir) { | ||
const url = getRawUrl(context, file); | ||
const response = await github.request(url); | ||
const out = join(outdir, basename(file) + suffix); | ||
await fs.promises.writeFile(out, response.data); | ||
console.log(`Downloaded ${url} to ${out}`); | ||
if (os.type() !== 'Windows_NT') { | ||
fs.chmodSync(out, fs.constants.S_IXUSR | fs.constants.S_IRUSR); | ||
} | ||
return out; | ||
} | ||
|
||
// simple tilde expansion | ||
function expandTilde(path) { | ||
return path.replace('~', (os.type() === 'Windows_NT') ? `${process.env.USERPROFILE}${sep}` : `${process.env.HOME}${sep}`); | ||
} | ||
|
||
module.exports = { | ||
downloadScript, | ||
expandTilde | ||
}; |