Skip to content

Commit

Permalink
feat: ✨ add deploy.ts for source maps
Browse files Browse the repository at this point in the history
  • Loading branch information
peelar committed Oct 9, 2023
1 parent fbd1948 commit efc0c19
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 2 deletions.
5 changes: 4 additions & 1 deletion apps/taxes/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ PORT=
VERCEL_URL=
REST_APL_ENDPOINT=
REST_APL_TOKEN=
ALLOWED_DOMAIN
ALLOWED_DOMAIN=
GITHUB_SHA=
VERCEL=
VERCEL_GIT_COMMIT_SHA=

# Local development variables. When developped locally with Saleor inside docker, these can be set to:

Check warning on line 16 in apps/taxes/.env.example

View workflow job for this annotation

GitHub Actions / spellcheck

Unknown word (developped)
# APP_IFRAME_BASE_URL = http://localhost:3000, so Dashboard on host can access iframe
Expand Down
1 change: 1 addition & 0 deletions apps/taxes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
},
"dependencies": {
"@hookform/resolvers": "^3.3.1",
"@next/env": "^13.5.4",
"@saleor/app-sdk": "0.43.1",
"@saleor/apps-shared": "workspace:*",
"@saleor/apps-ui": "workspace:*",
Expand Down
16 changes: 16 additions & 0 deletions apps/taxes/src/deploy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { default as envUtils } from "@next/env";
import { execSync } from "child_process";

envUtils.loadEnvConfig(".");

async function setReleaseTag() {
// Must use dynamic import for env variables to load properly
const { getReleaseTag } = await import("./release-utils");
const release = getReleaseTag();

console.log("Using release tag:", release);

execSync(`SENTRY_RELEASE='${release}' pnpm run build`, { stdio: "inherit" });
}

setReleaseTag();
32 changes: 32 additions & 0 deletions apps/taxes/src/release-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { execSync } from "child_process";
import packageJson from "../../../package.json";

const getCommitHash = () => {
if (process.env.VERCEL) {
return process.env.VERCEL_GIT_COMMIT_SHA;
}
if (process.env.GITHUB_SHA) {
return process.env.GITHUB_SHA;
}
try {
const result = execSync("git rev-parse HEAD");

return result.toString().trim();
} catch (e) {
console.warn("Cannot fetch commit hash", e);
return null;
}
};

export const getReleaseTag = () => {
const version = packageJson.version;

if (
process.env.NODE_ENV === "production" &&
process.env.NEXT_PUBLIC_SENTRY_ENVIRONMENT === "production"
) {
return version;
}

return `${version}-${getCommitHash() ?? "<unknown_commit_hash>"}`;
};
6 changes: 5 additions & 1 deletion apps/taxes/turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
"APP_API_BASE_URL",
"APP_DEBUG",
"APP_IFRAME_BASE_URL",
"GITHUB_SHA",
"NEXT_PUBLIC_SENTRY_DSN",
"NEXT_PUBLIC_SENTRY_ENVIRONMENT",
"NEXT_PUBLIC_SENTRY_REPORT_LEVEL",
"NODE_ENV",
"PORT",
Expand All @@ -21,7 +23,9 @@
"SENTRY_ENVIRONMENT",
"SENTRY_ORG",
"SENTRY_PROJECT",
"VERCEL_URL"
"VERCEL_GIT_COMMIT_SHA",
"VERCEL_URL",
"VERCEL"
]
}
}
Expand Down
7 changes: 7 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit efc0c19

Please sign in to comment.