Skip to content

Conversation

@robertbrignull
Copy link
Contributor

@robertbrignull robertbrignull commented Sep 15, 2020

This is partially an alternative PR to #208 but I thought I'd open it anyway. This PR also goes further by:

  • Creates actions-util.ts that allows us to place higher standards on util.ts to work on actions and the runner and makes it easier to see the division of what code runs where.
  • Adding a CodeQL query to detect use of core.input and point to the correct custom function.
  • An extra CodeQL query that detects inconsistent definitions of inputs between actions.

Merge / deployment checklist

  • Confirm this change is backwards compatible with existing workflows.
  • Confirm the readme has been updated if necessary.

@robertbrignull robertbrignull force-pushed the robertbrignull/consistent_inputs branch from a5748ab to c1cee53 Compare September 15, 2020 17:48
Copy link
Contributor

@marcogario marcogario left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

The CodeQL queries are 💖 , but I would suggest you get someone with more experience to review them.

if (value === undefined || value.length === 0) {
throw new Error(`${paramName} environment variable must be set`);
}
core.debug(`${paramName}=${value}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a false positive.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree I think this is. It's happening because in getCodeQLActionRepository we abort early when not in actions mode and the query doesn't understand this. I will fix that but perhaps would be best in a separate PR. I'll open an issue for it as I don't think there is one now. For this PR I think it's enough to see there's 1 new and 1 fixed alert of this type.

@robertbrignull
Copy link
Contributor Author

I was wondering why this wasn't opening alerts for the uses of core.getInput in getRequiredInput and getOptionalInput themselves. Turns out it's because the query relies on the parameter being a string literal, so it skips these cases. This is unintentional behaviour but it ends up doing the right thing, so I'm tempted to leave it. I'll add a comment into the query explaining this though.

@robertbrignull
Copy link
Contributor Author

The alert changes now look correct. One new and one fixed alert because we've moved some code to a different file.

Copy link
Contributor

@joshhale joshhale left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not familiar with the javascript QL library, but the queries lgtm.

exists(YAMLMapping value |
value = getRootNode().(YAMLMapping).lookup("inputs").(YAMLMapping).lookup(input) and
(exists(value.lookup("default")) or
value.lookup("required").(YAMLBool).getBoolValue() = true))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need = true here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes unfortunately. This is not a predicate that exists or doesn't, but rather it "returns" a true or false boolean value. In CodeQL I think you need to explicitly use = true.

}

/**
* The function that is the entrypoint to this action.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically, I guess it's the typescript source for the function that is the entrypoint to the action.

...not sure if it's important to make that distinction explicit though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure either. I think I'll just leave it. I think it's implicit that these queries are on the typescript source code instead of the compiled javascript, assuming that's what you meant as the alternative source for the function.

@robertbrignull robertbrignull merged commit c9b0611 into main Sep 17, 2020
@robertbrignull robertbrignull deleted the robertbrignull/consistent_inputs branch September 17, 2020 09:06
@github-actions github-actions bot mentioned this pull request Sep 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants