Skip to content

Commit

Permalink
prevent git env from logging an error in the case of failure. just le…
Browse files Browse the repository at this point in the history
…t it fail.
  • Loading branch information
julianbenegas committed Oct 10, 2024
1 parent 8576782 commit 7777a02
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 27 deletions.
6 changes: 6 additions & 0 deletions packages/basehub/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# basehub

## 7.5.8

### Patch Changes

- prevent git env from logging an error in the case of failure. just let it fail.

## 7.5.7

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/basehub/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "basehub",
"description": "A very fast Headless CMS.",
"author": "JB <[email protected]>",
"version": "7.5.7",
"version": "7.5.8",
"license": "MIT",
"repository": "basehub-ai/basehub",
"bugs": "https://github.com/basehub-ai/basehub/issues",
Expand Down
55 changes: 30 additions & 25 deletions packages/basehub/src/bin/util/get-git-env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,37 @@
import { execSync } from "child_process";

export const getGitEnv = () => {
try {
const gitBranch =
process.env.VERCEL_GIT_COMMIT_REF ||
process.env.BRANCH ||
process.env.RENDER_GIT_BRANCH ||
process.env.GIT_BRANCH ||
process.env.CF_PAGES_BRANCH ||
execSync("git symbolic-ref --short HEAD").toString().trim();
const execSyncSafe = (command: string): string => {
try {
return execSync(command, { stdio: "pipe" }).toString().trim();
} catch (error) {
// If the command fails, return an empty string
return "";
}
};

const gitCommitSHA =
process.env.VERCEL_GIT_COMMIT_SHA ||
process.env.COMMIT_REF ||
process.env.RENDER_GIT_COMMIT ||
process.env.COMMIT_SHA ||
process.env.CF_PAGES_COMMIT_SHA ||
execSync("git rev-parse HEAD").toString().trim();
const gitBranch =
process.env.VERCEL_GIT_COMMIT_REF ||
process.env.BRANCH ||
process.env.RENDER_GIT_BRANCH ||
process.env.GIT_BRANCH ||
process.env.CF_PAGES_BRANCH ||
execSyncSafe("git symbolic-ref --short HEAD") ||
execSyncSafe("git rev-parse --abbrev-ref HEAD");

const gitBranchDeploymentURL =
process.env.VERCEL_BRANCH_URL ||
process.env.DEPLOY_PRIME_URL ||
process.env.CF_PAGES_URL ||
null;
const gitCommitSHA =
process.env.VERCEL_GIT_COMMIT_SHA ||
process.env.COMMIT_REF ||
process.env.RENDER_GIT_COMMIT ||
process.env.COMMIT_SHA ||
process.env.CF_PAGES_COMMIT_SHA ||
execSyncSafe("git rev-parse HEAD");

return { gitBranch, gitCommitSHA, gitBranchDeploymentURL };
} catch (error) {
// ignore error as this should not a blocker
return { gitBranch: "", gitCommitSHA: "", gitBranchDeploymentURL: "" };
}
const gitBranchDeploymentURL =
process.env.VERCEL_BRANCH_URL ||
process.env.DEPLOY_PRIME_URL ||
process.env.CF_PAGES_URL ||
null;

return { gitBranch, gitCommitSHA, gitBranchDeploymentURL };
};
7 changes: 7 additions & 0 deletions playground/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# playground

## 0.0.150

### Patch Changes

- Updated dependencies
- [email protected]

## 0.0.149

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion playground/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "playground",
"private": true,
"version": "0.0.149",
"version": "0.0.150",
"scripts": {
"dev": "basehub dev & next dev --port 3003",
"build": "basehub && next build",
Expand Down

0 comments on commit 7777a02

Please sign in to comment.