-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(circleci-orb): improve packing of circleci inline commands
Currently we use `EOF` for reading the script from stdin. It looks like NodeJS on Windows does not properly deal with scripts through piping. We continue using here-doc bash functionality but use the stdin redirection operator which makes the stin node execution work.
- Loading branch information
1 parent
0f3a67f
commit 5770ea7
Showing
6 changed files
with
60 additions
and
13 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
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 |
---|---|---|
@@ -1,20 +1,18 @@ | ||
"""Helper rules for building CircleCI orbs with the help of Bazel.""" | ||
|
||
load("@build_bazel_rules_nodejs//:index.bzl", "npm_package_bin") | ||
|
||
def nodejs_script_to_sh_script(name, output_file, bundle_file): | ||
"""Rule that takes a NodeJS script and wraps it into a Bash script. | ||
This is useful for inclusion in CircleCI `run` commands in Orbs because | ||
there cannot be an external NodeJS script file, or direct NodeJS `run` commands. | ||
""" | ||
native.genrule( | ||
|
||
npm_package_bin( | ||
name = name, | ||
srcs = [bundle_file], | ||
tool = "//circleci-orb:pack_orb_script", | ||
data = [bundle_file], | ||
outs = [output_file], | ||
cmd = """ | ||
touch $@ | ||
echo '(cat <<"EOF" ' >> $@ | ||
cat $< >> $@ | ||
echo 'EOF' >> $@ | ||
echo ') | node' >> $@ | ||
""", | ||
args = ["$(location %s)" % bundle_file, "$@"], | ||
) |
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,29 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import fs from 'fs'; | ||
|
||
async function main(bundleExecpath, outputExecpath) { | ||
const content = await fs.promises.readFile(bundleExecpath, 'utf8'); | ||
// We need to avoid passing it through command line arguments. See: | ||
// https://stackoverflow.com/a/47443446. | ||
const output = ` | ||
node <<"NGEOF" | ||
${content} | ||
NGEOF | ||
`; | ||
await fs.promises.writeFile(outputExecpath, output, 'utf8'); | ||
} | ||
|
||
try { | ||
const [bundleExecpath, outputExecpath] = process.argv.slice(2); | ||
await main(bundleExecpath, outputExecpath); | ||
} catch (e) { | ||
console.error(e); | ||
process.exitCode = 1; | ||
} |
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