-
Notifications
You must be signed in to change notification settings - Fork 0
Enforce immediate prior weekly provenance #37
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
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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,57 @@ | ||
| #!/usr/bin/env python3 | ||
| """Build the dedicated weekly artifact after the boundary guard.""" | ||
| from __future__ import annotations | ||
|
|
||
| import argparse | ||
| import json | ||
| import sys | ||
| from datetime import date, datetime | ||
| from pathlib import Path | ||
|
|
||
| sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src")) | ||
|
|
||
| from political_event_tracking_research.weekly_artifact import WeeklyArtifactError, build_weekly_artifact # noqa: E402 | ||
|
|
||
|
|
||
| def main() -> None: | ||
| parser = argparse.ArgumentParser() | ||
| parser.add_argument("--period-start", required=True) | ||
| parser.add_argument("--as-of", required=True) | ||
| parser.add_argument("--generated-at", required=True) | ||
| parser.add_argument("--workflow-ref", required=True) | ||
| parser.add_argument("--source-run-id", required=True) | ||
| parser.add_argument("--source-attempt", required=True, type=int) | ||
| parser.add_argument("--producer-ref", required=True) | ||
| parser.add_argument("--source-events", required=True, type=Path) | ||
| parser.add_argument("--watchlist", required=True, type=Path) | ||
| parser.add_argument("--feed-status", required=True, type=Path) | ||
| parser.add_argument("--output-dir", required=True, type=Path) | ||
| parser.add_argument("--run-mode", choices=("scheduled", "manual"), required=True) | ||
| args = parser.parse_args() | ||
| try: | ||
| files = build_weekly_artifact( | ||
| period_start=date.fromisoformat(args.period_start), | ||
| as_of=date.fromisoformat(args.as_of), | ||
| generated_at=datetime.fromisoformat(args.generated_at.replace("Z", "+00:00")), | ||
| workflow_ref=args.workflow_ref, | ||
| source_run_id=args.source_run_id, | ||
| source_attempt=args.source_attempt, | ||
| producer_ref=args.producer_ref, | ||
| source_events=args.source_events.read_bytes(), | ||
| watchlist=args.watchlist.read_bytes(), | ||
| feed_status=json.loads(args.feed_status.read_text(encoding="utf-8")), | ||
| run_mode=args.run_mode, | ||
| ) | ||
| args.output_dir.mkdir(parents=True, exist_ok=True) | ||
| if any(args.output_dir.iterdir()): | ||
| raise WeeklyArtifactError("artifact_output_not_empty") | ||
| for name, content in files.items(): | ||
| (args.output_dir / name).write_bytes(content) | ||
| except WeeklyArtifactError as error: | ||
| raise SystemExit(error.code) from None | ||
| except (OSError, UnicodeError, json.JSONDecodeError, TypeError, ValueError, OverflowError): | ||
| raise SystemExit("weekly_artifact_input_invalid") from None | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
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,48 @@ | ||
| #!/usr/bin/env python3 | ||
| """Validate trusted run identity and the only permitted weekly period.""" | ||
| from __future__ import annotations | ||
|
|
||
| import argparse | ||
| import json | ||
| import sys | ||
| from pathlib import Path | ||
|
|
||
| sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src")) | ||
|
|
||
| from political_event_tracking_research.workflow_boundary import ( # noqa: E402 | ||
| WorkflowBoundaryError, | ||
| validate_manual_period, | ||
| validate_manual_run, | ||
| validate_scheduled_run, | ||
| ) | ||
|
|
||
|
|
||
| def main() -> None: | ||
| parser = argparse.ArgumentParser() | ||
| parser.add_argument("--event", choices=("schedule", "workflow_dispatch"), required=True) | ||
| parser.add_argument("--run-id", required=True) | ||
| parser.add_argument("--run-attempt", required=True, type=int) | ||
| parser.add_argument("--workflow-ref", required=True) | ||
| parser.add_argument("--period-start", required=False) | ||
| parser.add_argument("--as-of", required=False) | ||
| parser.add_argument("--run-payload", required=True, type=Path) | ||
| parser.add_argument("--output", required=True, type=Path) | ||
| args = parser.parse_args() | ||
| try: | ||
| payload = json.loads(args.run_payload.read_text(encoding="utf-8")) | ||
| if args.event == "schedule": | ||
| evidence = validate_scheduled_run(payload, run_id=args.run_id, workflow_ref=args.workflow_ref, run_attempt=args.run_attempt) | ||
| start, end, as_of = evidence.period_start, evidence.period_end_exclusive, evidence.as_of | ||
| else: | ||
| evidence = validate_manual_run(payload, run_id=args.run_id, workflow_ref=args.workflow_ref, run_attempt=args.run_attempt) | ||
| start, as_of = validate_manual_period(args.period_start, args.as_of, run_created_at=evidence.created_at) | ||
| end = start.fromordinal(start.toordinal() + 7) | ||
| args.output.write_text(json.dumps({"period_start": start.isoformat(), "period_end_exclusive": end.isoformat(), "as_of": as_of.isoformat(), "producer_ref": evidence.producer_ref, "source_attempt": evidence.run_attempt}, sort_keys=True, separators=(",", ":")) + "\n", encoding="utf-8") | ||
| except WorkflowBoundaryError as error: | ||
| raise SystemExit(error.code) from None | ||
| except (OSError, UnicodeError, json.JSONDecodeError, TypeError, ValueError): | ||
| raise SystemExit("workflow_boundary_invalid") from None | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
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
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.
When
COMMIT_OUTPUTS=trueand generated files change, the later publish step runsgit commitfollowed by plaingit push; checking out the raw${{ github.sha }}leaves the job on a detached commit, andpersist-credentials: falseopts out of the checkout token that actions/checkout documents as enabling later authenticated git commands. Scheduled runs therefore fail instead of publishing live CSV updates whenever there is a change to commit.Useful? React with 👍 / 👎.