Skip to content

Commit

Permalink
broke through detect-changes issues
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch committed Sep 14, 2024
1 parent 4ec6610 commit 1df5cb9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
13 changes: 10 additions & 3 deletions docs/docs/contributing/development.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -547,14 +547,14 @@ act --list
To run a specific workflow:

```bash
act --job {workflow_name} --secret GITHUB_TOKEN=$GITHUB_TOKEN --event pull_request --container-architecture linux/amd64
act pull_request --job {workflow_name} --secret GITHUB_TOKEN=$GITHUB_TOKEN --container-architecture linux/amd64
```

In the example above, notice that:
- we target a specific workflow, using `--job`
- we pass a secret using `--secret`, as many jobs require read access (public) to the repo
- we simulate a `pull_request` event using `--event`, here we could simulate a
`push` event or something else
- we simulate a `pull_request` event by specifying it as the first arg,
similarly, we could simulate a `push` event or something else
- we specify `--container-architecture`, which tends to emulate GHA more reliably

:::note
Expand All @@ -563,6 +563,13 @@ events (pull_request, push, ...), semantics around passing secrets where require
more. For more information, refer to [act's documentation](https://nektosact.com/)
:::
:::note
Some jobs require secrets to interact with external systems and accounts that you may
not have in your possession. In those cases you may have to rely on remote CI or parameterize the
job further to target a different environment/sandbox or your own alongside the related
secrets.
:::
---
## Testing
Expand Down
14 changes: 10 additions & 4 deletions scripts/change_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,21 @@ def print_files(files: List[str]) -> None:
print("\n".join([f"- {s}" for s in files]))


def is_int(s: str) -> bool:
return bool(re.match(r"^-?\d+$", s))


def main(event_type: str, sha: str, repo: str) -> None:
"""Main function to check for file changes based on event context."""
print("SHA:", sha)
print("EVENT_TYPE", event_type)
files = None
if event_type == "pull_request":
pr_number = os.getenv("GITHUB_REF", "").split("/")[-2]
files = fetch_changed_files_pr(repo, pr_number)
print("PR files:")
print_files(files)
if is_int(pr_number):
files = fetch_changed_files_pr(repo, pr_number)
print("PR files:")
print_files(files)

elif event_type == "push":
files = fetch_changed_files_push(repo, sha)
Expand All @@ -119,7 +125,7 @@ def main(event_type: str, sha: str, repo: str) -> None:
changes_detected = {}
for group, regex_patterns in PATTERNS.items():
patterns_compiled = [re.compile(p) for p in regex_patterns]
changes_detected[group] = event_type == "workflow_dispatch" or detect_changes(
changes_detected[group] = files is None or detect_changes(
files, patterns_compiled
)

Expand Down

0 comments on commit 1df5cb9

Please sign in to comment.