-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: better CI handling, specially Buildkite
- Loading branch information
Showing
9 changed files
with
125 additions
and
65 deletions.
There are no files selected for viewing
This file contains 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,25 @@ | ||
import envCi from "env-ci"; | ||
import type { CiEnvironment, Context } from "./types"; | ||
|
||
export const getCiEnvironmentFromEnvCi = ( | ||
ctx: Context | ||
): CiEnvironment | null => { | ||
const ciContext = envCi(ctx); | ||
const name = ciContext.isCi | ||
? ciContext.name ?? null | ||
: ciContext.commit | ||
? "Git" | ||
: null; | ||
const commit = ciContext.commit ?? null; | ||
const branch = (ciContext.branch || ciContext.prBranch) ?? null; | ||
const slug = ciContext.slug ? ciContext.slug.split("/") : null; | ||
const owner = slug ? slug[0] : null; | ||
const repository = slug ? slug[1] : null; | ||
const jobId = ciContext.job ?? null; | ||
const runId = null; | ||
const prNumber = null; | ||
|
||
return commit | ||
? { name, commit, branch, owner, repository, jobId, runId, prNumber } | ||
: null; | ||
}; |
This file contains 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,16 @@ | ||
import { head, branch } from "./git"; | ||
|
||
describe("#head", () => { | ||
it("returns the current commit", () => { | ||
expect(head()).toMatch(/^[0-9a-f]{40}$/); | ||
}); | ||
}); | ||
|
||
/** | ||
* This test can be run locally, too hard to make it work on CI. | ||
*/ | ||
xdescribe("#branch", () => { | ||
it("returns the current branch", () => { | ||
expect(branch()).toBe("main"); | ||
}); | ||
}); |
This file contains 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,31 @@ | ||
import { execSync } from "node:child_process"; | ||
|
||
/** | ||
* Returns the head commit. | ||
*/ | ||
export const head = () => { | ||
try { | ||
return execSync("git rev-parse HEAD").toString().trim(); | ||
} catch { | ||
return null; | ||
} | ||
}; | ||
|
||
/** | ||
* Returns the current branch. | ||
*/ | ||
export const branch = () => { | ||
try { | ||
const headRef = execSync("git rev-parse --abbrev-ref HEAD") | ||
.toString() | ||
.trim(); | ||
|
||
if (headRef === "HEAD") { | ||
return null; | ||
} | ||
|
||
return headRef; | ||
} catch { | ||
return null; | ||
} | ||
}; |
This file contains 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 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 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 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 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 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