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

Adds support for different allowlists in different workflows. #119

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

ellisonmarks
Copy link
Collaborator

No description provided.

lib/tacos/path_filter.py Outdated Show resolved Hide resolved
lib/tacos/dependent_slices.py Outdated Show resolved Hide resolved
lib/tacos/dependent_slices.py Outdated Show resolved Hide resolved
lib/tacos/dependent_slices.py Outdated Show resolved Hide resolved
lib/tacos/dependent_slices.py Outdated Show resolved Hide resolved
lib/tacos/path_filter.py Outdated Show resolved Hide resolved
.github/workflows/tacos_apply.yml Outdated Show resolved Hide resolved
@bukzor
Copy link
Collaborator

bukzor commented Jan 31, 2024

Good stuff. Thanks :) Ding me for round two.

@@ -61,6 +61,9 @@ jobs:
- name: List Slices
id: list-slices
uses: ./tacos-gha/.github/actions/list-slices
with:
allowlist: >-
Copy link
Collaborator

Choose a reason for hiding this comment

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

surrounding style:

Suggested change
allowlist: >-
allowlist: |-

@@ -26,6 +29,6 @@ runs:
id: list-slices
shell: ${{inputs.shell}}
run: |
"$TACOS_GHA_HOME/"lib/ci/list-slices <<'EOF'
"$TACOS_GHA_HOME/"lib/ci/list-slices ${{inputs.allowlist}} <<'EOF'
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you instead pass this via an environment variable, it avoids the possibility of weird characters making the bash parser confused.

Suggested change
"$TACOS_GHA_HOME/"lib/ci/list-slices ${{inputs.allowlist}} <<'EOF'
env:
allowlist: ${{inputs.allowlist}}
run: |
"$TACOS_GHA_HOME/"lib/ci/list-slices "$allowlist" <<'EOF'

It probably doesn't matter here, but it's quite important elsewhere so it's a good habit.

Comment on lines +54 to +55
slices="$("./tacos-gha/"lib/tacos/slices \
.config/tacos-gha/drift.allowlist | jq -R | jq -sc)"
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit:

Fixed-width indents only, please. As soon as this is no longer a one-liner, I'd continuate each |.

Suggested change
slices="$("./tacos-gha/"lib/tacos/slices \
.config/tacos-gha/drift.allowlist | jq -R | jq -sc)"
slices="$(
"./tacos-gha/"lib/tacos/slices \
.config/tacos-gha/drift.allowlist |
jq -R |
jq -sc
)"

@@ -60,6 +60,10 @@ jobs:
- name: List Slices
id: list-slices
uses: ./tacos-gha/.github/actions/list-slices
with:
allowlist: >-
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
allowlist: >-
allowlist: |-


args = argv[1:]
# need to modify argv for fileinput to work
del argv[1:]

fs = FileSystem.from_git()
modified_paths = lines_to_paths(fileinput.input(encoding="utf-8"))
Copy link
Collaborator

Choose a reason for hiding this comment

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

fileinput is only useful where we want to not care whether the user is using stdin or positional arguments.
Since we can no longer use positional arguments for file inputs, fileinput is unecessary complextiy and this would be expressed more simply as:

Suggested change
modified_paths = lines_to_paths(fileinput.input(encoding="utf-8"))
from sys import stdin
...
modified_paths = lines_to_paths(stdin)

and then there's no need to modify argv, either.

lines.append(line)
except FileNotFoundError:
pass
for path in [OSPath(x) for x in configs] + [OSPath(DEFAULT_PATH)]:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Normally I'd expect a system to only use a default config file when nothing more specific has been specified by the user.

Comment on lines +58 to 66
from sys import argv

path_filter = PathFilter.from_config()
args = argv[1:]
# need to modify argv for fileinput to work
del argv[1:]

path_filter = PathFilter.from_config(args)

for line in fileinput.input(encoding="utf-8"):
Copy link
Collaborator

Choose a reason for hiding this comment

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

similarly

line = line.strip()
if line and not line.startswith("#"):
lines.append(line)
break
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is only making use of the first config file even if the user passed two? I would normally expect the system to concatenate the configs in this case.

If you treat a missing file as equal to an empty file I believe you get the same, correct behavior but with a bit fewer edge cases to consider.

"""Get a list of allowed globs from a file

Hash comments are removed and blank lines are ignored.
Inline comments are not allowed
An empty or missing file is treated as all allowed.
If both the provided and default files are missing, allow all.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
If both the provided and default files are missing, allow all.
If all configuration files are empty or missing, allow all.

@@ -61,6 +61,9 @@ jobs:
- name: List Slices
id: list-slices
uses: ./tacos-gha/.github/actions/list-slices
with:
allowlist: >-
.config/tacos-gha/apply.allowlist .config/tacos-gha/drift.allowlist
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
.config/tacos-gha/apply.allowlist .config/tacos-gha/drift.allowlist
.config/tacos-gha/apply.allowlist
.config/tacos-gha/drift.allowlist

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.

2 participants