-
Notifications
You must be signed in to change notification settings - Fork 43
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(docker): safer argument parsing for GitHub Actions #788
Changes from 36 commits
a82c278
31a276b
66747e1
d021809
b5650d9
1c4b562
7ad9568
ce0dee1
0f8f05f
6cd38a2
7f8d7fa
c3ebc04
b6db9dc
8c47d18
9708f15
cec6fb6
5cbe62d
f900a39
58ab9cd
6138dc7
544981a
ef6a8d6
d27bb7b
518567b
8d81196
360b2fe
cbeb32c
bf11379
ac5cacc
62d4014
282bb56
a91163c
76ee1c7
440495b
ae006db
073ac68
054643f
9fa7b48
d6c3f2f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,4 @@ FROM alpine:3.14 | |
|
||
COPY --from=builder /rdme/exe /exe | ||
|
||
ENTRYPOINT ["sh", "-c", "/exe/rdme $INPUT_RDME"] | ||
ENTRYPOINT ["/exe/rdme"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not only this this a lot cleaner, but we can now use good ol' Footnotes
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah this is better. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,6 @@ outputs: | |
runs: | ||
using: docker | ||
image: docker://ghcr.io/readmeio/rdme:8.6.0 | ||
args: | ||
- docker-gha | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a new internal argument we send to indicate to the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a pretty neat/sufficient solution. Annoying that it's necessary, but it's not too bad. |
||
- ${{ inputs.rdme }} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ import path from 'path'; | |
|
||
import chalk from 'chalk'; | ||
import cliArgs from 'command-line-args'; | ||
import parseArgsStringToArgv from 'string-argv'; | ||
|
||
// We have to do this otherwise `require('config')` loads | ||
// from the cwd where the user is running `rdme` which | ||
|
@@ -33,7 +34,7 @@ import getCurrentConfig from './lib/getCurrentConfig'; | |
* fake CLI calls. | ||
* @return {Promise} | ||
*/ | ||
export default function rdme(processArgv: NodeJS.Process['argv']) { | ||
export default function rdme(rawProcessArgv: NodeJS.Process['argv']) { | ||
const mainArgs = [ | ||
{ name: 'help', alias: 'h', type: Boolean, description: 'Display this usage guide' }, | ||
{ | ||
|
@@ -45,6 +46,29 @@ export default function rdme(processArgv: NodeJS.Process['argv']) { | |
{ name: 'command', type: String, defaultOption: true }, | ||
]; | ||
|
||
let processArgv = rawProcessArgv; | ||
|
||
/** | ||
* We have a weird edge case with our Docker image version of `rdme` where GitHub Actions | ||
* will pass all of the `rdme` arguments as a single string with escaped quotes, | ||
* as opposed to the usual array of strings that we typically expect with `process.argv`. | ||
* | ||
* For example, say the user sends us `rdme openapi "petstore.json"`. | ||
* Instead of `process.argv` being this (i.e., when running the command via CLI): | ||
* ['openapi', 'petstore.json'] | ||
* | ||
* The GitHub Actions runner will send this to the `rdme` Docker image: | ||
* ['openapi "petstore.json"'] | ||
* | ||
* To distinguish these, we have a hidden `docker-gha` argument which we check for to indicate | ||
* when arguments are coming from the GitHub Actions runner. | ||
* This logic checks for that `docker-gha` argument and parses the second string | ||
* into the arguments array that `command-line-args` is expecting. | ||
*/ | ||
if (rawProcessArgv.length === 2 && rawProcessArgv[0] === 'docker-gha') { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We now check for that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hopefully this is something we can remove down the line! But nice fix for now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah sadly I think this will be here to stay so long as we aim to maintain Actions/CLI feature parity and stick with this Docker approach to Actions ๐ซ But who knows, maybe GitHub will ship changes on this front that will allow us to simplify this ๐ค๐ฝ |
||
processArgv = parseArgsStringToArgv(rawProcessArgv[1]); | ||
} | ||
|
||
const argv = cliArgs(mainArgs, { partial: true, argv: processArgv }); | ||
const cmd = argv.command || false; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the previously broken case? Do you have a test for that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, both tests added to this file check for the breakage in the most recent release!