-
Notifications
You must be signed in to change notification settings - Fork 1
feat(only-and-omit): pick or exclude actors #108
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f7a1866
feat(only-and-omit): pick or exclude actors
JuanGalilea f712fda
switch arg names and extend to other commands
JuanGalilea 0a53f31
error management so process.exit is not used in random places
JuanGalilea f9ab610
include actor selection logic in the reading of configuration
JuanGalilea File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,21 @@ | ||
| import type { ActorConfig } from './types.js'; | ||
|
|
||
| /** | ||
| * Restricts a set of actors to those selected via `--actors` and not excluded via `--ignore`. | ||
| * Both filters match on `actorFullName` (`owner/name`). `--actors` is applied first (empty means | ||
| * "all"), then `--ignore` removes from the result. A name that doesn't exist in the config throws — | ||
| * a malformed selection must never silently build/release/delete the wrong set. The caller is | ||
| * responsible for turning that into a non-zero exit. | ||
| */ | ||
| export function selectActors({ actors, ignore }: { actors: string[]; ignore: string[] }, actorConfigs: ActorConfig[]) { | ||
| const fullNames = actorConfigs.map((actor) => actor.actorFullName); | ||
| const missing = [...actors, ...ignore].filter((name) => !fullNames.includes(name)); | ||
| if (missing.length > 0) { | ||
| throw new Error(`The following actors from the filter config do not exist: ${missing.join(', ')}`); | ||
| } | ||
|
|
||
| const afterOnly = actors.length | ||
| ? actorConfigs.filter((actor) => actors.includes(actor.actorFullName)) | ||
| : actorConfigs; | ||
| return afterOnly.filter((actor) => !ignore.includes(actor.actorFullName)); | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,52 @@ | ||
| import { describe, expect, it } from 'vitest'; | ||
|
|
||
| import { selectActors } from '../../../bin/actor-filtering.js'; | ||
| import type { ActorConfig } from '../../../bin/types.js'; | ||
|
|
||
| const actor = (actorFullName: string): ActorConfig => ({ | ||
| actorFullName, | ||
| folder: actorFullName.split('/')[1], | ||
| tokenEnvVar: 'TOKEN', | ||
| dockerContextDir: '.', | ||
| contextPaths: [], | ||
| }); | ||
|
|
||
| const configs = [actor('owner/a'), actor('owner/b'), actor('owner/c')]; | ||
| const names = (result: ActorConfig[]) => result.map((c) => c.actorFullName); | ||
|
|
||
| describe('selectActors', () => { | ||
| it('returns all actors when neither filter is set', () => { | ||
| expect(names(selectActors({ actors: [], ignore: [] }, configs))).toStrictEqual([ | ||
| 'owner/a', | ||
| 'owner/b', | ||
| 'owner/c', | ||
| ]); | ||
| }); | ||
|
|
||
| it('keeps only the actors listed in --actors', () => { | ||
| expect(names(selectActors({ actors: ['owner/a', 'owner/c'], ignore: [] }, configs))).toStrictEqual([ | ||
| 'owner/a', | ||
| 'owner/c', | ||
| ]); | ||
| }); | ||
|
|
||
| it('drops the actors listed in --ignore', () => { | ||
| expect(names(selectActors({ actors: [], ignore: ['owner/b'] }, configs))).toStrictEqual(['owner/a', 'owner/c']); | ||
| }); | ||
|
|
||
| it('applies --actors first, then removes --ignore from that subset', () => { | ||
| expect(names(selectActors({ actors: ['owner/a', 'owner/b'], ignore: ['owner/b'] }, configs))).toStrictEqual([ | ||
| 'owner/a', | ||
| ]); | ||
| }); | ||
|
|
||
| it('can select down to nothing when --actors and --ignore overlap fully', () => { | ||
| expect(selectActors({ actors: ['owner/a'], ignore: ['owner/a'] }, configs)).toStrictEqual([]); | ||
| }); | ||
|
|
||
| it('throws listing every unknown name across both filters', () => { | ||
| expect(() => selectActors({ actors: ['owner/x'], ignore: ['owner/y'] }, configs)).toThrow( | ||
| 'The following actors from the filter config do not exist: owner/x, owner/y', | ||
| ); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
NIT: I'd rather call these
--include-actorsand--omit-actorsThere 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.
only went by these since local build already used
--actors.Can change it if needed tho, i don't really care either way