diff --git a/README.rst b/README.rst index 9790956..196ba58 100644 --- a/README.rst +++ b/README.rst @@ -231,7 +231,7 @@ A sample config file: repo: datalad/datalad vars: - path_prefix: '{year}//{month}//{day}/{ci}/{type}/{type_id}/{commit[:7]}' + path_prefix: '{year}//{month}//{day}/{ci}/{type}/{type_id}/{build_commit[:7]}' ci: github: path: '{path_prefix}/{wf_name}/{number}/logs/' @@ -295,8 +295,17 @@ Placeholder Definition is the name of the branch to which the push was made (or possibly the tag that was pushed, if using Appveyor); for ``release``, this is the name of the tag -``{commit}`` The hash of the commit the build ran against or that was - tagged for the release +``{build_commit}`` The hash of the commit the build ran against or that was + tagged for the release. Note that, for PR builds on + Travis and Appveyor, this is the hash of an autogenerated + merge commit. +``{commit}`` The hash of the original commit that triggered the build + or that was tagged for the release. For GitHub Actions + and all non-pull request builds, this is always the same + as ``{build_commit}``. For pull request builds on + Appveyor, this is the head of the PR branch. For pull + request builds on Travis, this is ``UNK``, as the API does + not expose the original commit. ``{number}`` The run number of the workflow run (GitHub) or the build number (Travis and Appveyor) [1]_ ``{status}`` The success status of the workflow run (GitHub) or job diff --git a/src/tinuous/__main__.py b/src/tinuous/__main__.py index 52f8a11..99be784 100644 --- a/src/tinuous/__main__.py +++ b/src/tinuous/__main__.py @@ -141,7 +141,8 @@ class Asset(ABC, BaseModel): created_at: datetime event_type: EventType event_id: str - commit: str + build_commit: str + commit: Optional[str] number: int status: str @@ -151,6 +152,7 @@ class Config: def path_fields(self) -> Dict[str, str]: utc_date = self.created_at.astimezone(timezone.utc) + commit = "UNK" if self.commit is None else self.commit return { "year": utc_date.strftime("%Y"), "month": utc_date.strftime("%m"), @@ -160,7 +162,8 @@ def path_fields(self) -> Dict[str, str]: "second": utc_date.strftime("%S"), "type": self.event_type.value, "type_id": self.event_id, - "commit": self.commit, + "build_commit": self.build_commit, + "commit": commit, "number": str(self.number), "status": self.status, "common_status": COMMON_STATUS_MAP[self.status], @@ -386,6 +389,7 @@ def from_workflow_run( created_at=ensure_aware(run.created_at), event_type=event_type, event_id=event_id, + build_commit=run.head_sha, commit=run.head_sha, workflow_name=workflow.name, workflow_file=workflow.path.split("/")[-1], @@ -451,6 +455,7 @@ def from_workflow_run( created_at=ensure_aware(run.created_at), event_type=event_type, event_id=event_id, + build_commit=run.head_sha, commit=run.head_sha, workflow_name=workflow.name, workflow_file=workflow.path.split("/")[-1], @@ -523,6 +528,7 @@ def path_fields(self) -> Dict[str, str]: "ci": "github", "type": "release", "type_id": self.tag_name, + "build_commit": self.commit, "commit": self.commit, } @@ -649,12 +655,16 @@ def from_job( if event is None: raise ValueError(f"Build has unknown event type {build['event_type']!r}") event_id: str + commit: Optional[str] if event is EventType.CRON: event_id = created_at.strftime("%Y%m%dT%H%M%S") + commit = build["commit"]["sha"] elif event is EventType.PUSH: event_id = build["branch"]["name"] + commit = build["commit"]["sha"] elif event is EventType.PULL_REQUEST: event_id = str(build["pull_request_number"]) + commit = None else: raise AssertionError(f"Unhandled EventType: {event!r}") return cls( @@ -662,7 +672,8 @@ def from_job( created_at=created_at, event_type=event, event_id=event_id, - commit=build["commit"]["sha"], + build_commit=build["commit"]["sha"], + commit=commit, number=int(build["number"]), job=removeprefix(job["number"], f"{build['number']}."), job_id=job["id"], @@ -783,15 +794,18 @@ def from_job( if build.get("pullRequestId"): event = EventType.PULL_REQUEST event_id = build["pullRequestId"] + commit = build["pullRequestHeadCommitId"] else: event = EventType.PUSH event_id = build["branch"] + commit = build["commitId"] return cls( client=client, created_at=created_at, event_type=event, event_id=event_id, - commit=build["commitId"], + build_commit=build["commitId"], + commit=commit, number=build["buildNumber"], job=job["jobId"], status=job["status"],