Skip to content

Commit 70b7593

Browse files
authored
fix: branch name based versions (#502)
1 parent ff5e1dd commit 70b7593

3 files changed

Lines changed: 23 additions & 1 deletion

File tree

packages/app/server/routes/publish.post.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,20 @@ export default eventHandler(async (event) => {
202202
});
203203
}
204204

205+
if (
206+
workflowData.headBranch &&
207+
workflowData.headBranch !== workflowData.ref
208+
) {
209+
const branchCursorKey = `${baseKey}:${workflowData.headBranch}`;
210+
const branchCursor = await cursorBucket.getItem(branchCursorKey);
211+
if (!branchCursor || branchCursor.timestamp < runId) {
212+
await cursorBucket.setItem(branchCursorKey, {
213+
sha: workflowData.sha,
214+
timestamp: runId,
215+
});
216+
}
217+
}
218+
205219
await workflowsBucket.removeItem(key);
206220

207221
const urls = packagesWithoutPrefix.map((packageName) =>

packages/app/server/routes/webhook.post.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,18 @@ export default eventHandler(async (event) => {
5555
const lookupKey = isNewPullRequest ? prKey : oldPrDataHash;
5656
const prNumber = await pullRequestNumbersBucket.getItem(lookupKey);
5757

58+
const headBranch = payload.workflow_run.head_branch;
59+
const isHeadOnUpstream =
60+
payload.workflow_run.head_repository?.full_name ===
61+
payload.repository.full_name;
62+
5863
const data: WorkflowData = {
5964
owner,
6065
repo,
6166
sha: payload.workflow_run.head_sha,
62-
ref: isPullRequest ? `${prNumber}` : payload.workflow_run.head_branch!, // it's a pull request workflow
67+
ref: isPullRequest ? `${prNumber}` : headBranch!,
68+
headBranch:
69+
isPullRequest && isHeadOnUpstream && headBranch ? headBranch : null,
6370
};
6471

6572
// Publishing is only available throughout the lifetime of a workflow_job

packages/app/server/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export interface WorkflowData {
33
repo: string;
44
sha: string;
55
ref: string;
6+
headBranch?: string | null;
67
}
78

89
export interface PullRequestData {

0 commit comments

Comments
 (0)