Skip to content

Commit

Permalink
Vaihda tuoreempi git-kirjasto
Browse files Browse the repository at this point in the history
  • Loading branch information
tomikat committed Jan 3, 2025
1 parent 2d6cbff commit 15a1a82
Show file tree
Hide file tree
Showing 3 changed files with 159 additions and 210 deletions.
96 changes: 55 additions & 41 deletions cdk/bin/cdk.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,63 @@
#!/usr/bin/env node
import { App } from 'aws-cdk-lib'
import { App } from "aws-cdk-lib";
import { HeratepalveluAMISStack } from "../lib/amis";
import { HeratepalveluTEPStack } from "../lib/tep";
import { HeratepalveluTPKStack } from "../lib/tpk";
import { HeratepalveluTEPRAHOITUSStack } from "../lib/teprah";
import { simpleGit, SimpleGitOptions } from "simple-git";

const checkGitStatus = async () => {
const options: Partial<SimpleGitOptions> = {
baseDir: process.cwd(),
binary: 'git',
maxConcurrentProcesses: 6,
trimmed: false,
};
const git = simpleGit(options);

const status = await git.status();
const gitLog = await git.log();
const upstreamBranch = await git.getRemotes();

if (upstreamBranch.length === 0) {
throw new Error("No upstream branch");
}

const git = require("git-utils");
const repo = git.open(".");

const status = repo.getStatus();
const aheadBehindCount = repo.getAheadBehindCount();
const upstreamBranch = repo.getUpstreamBranch();

if (!upstreamBranch) {
throw new Error("No upstream branch");
}

const canDeploy = (Object.entries(status).length === 0 && aheadBehindCount.ahead === 0 && aheadBehindCount.behind === 0);

const version = canDeploy ? repo.getReferenceTarget(repo.getHead()) : "uncommitted";

const app = new App();

new HeratepalveluAMISStack(app, "sieni-services-heratepalvelu", 'sieni', version);
const tepSieni = new HeratepalveluTEPStack(app, "sieni-services-heratepalvelu-tep", 'sieni', version);
new HeratepalveluTEPRAHOITUSStack(app, "sieni-services-heratepalvelu-teprah", 'sieni', version, tepSieni.jaksotunnusTable);
new HeratepalveluTPKStack(app, "sieni-services-heratepalvelu-tpk", 'sieni', version, tepSieni.jaksotunnusTable);

if (canDeploy) {
new HeratepalveluAMISStack(app, "pallero-services-heratepalvelu", 'pallero', version);
const tepPallero = new HeratepalveluTEPStack(app, "pallero-services-heratepalvelu-tep", 'pallero', version);
new HeratepalveluTEPRAHOITUSStack(app, "pallero-services-heratepalvelu-teprah", 'pallero', version, tepPallero.jaksotunnusTable);
new HeratepalveluTPKStack(app, "pallero-services-heratepalvelu-tpk", 'pallero', version, tepPallero.jaksotunnusTable);

if (upstreamBranch === "refs/remotes/origin/master") {
new HeratepalveluAMISStack(app, "sade-services-heratepalvelu", 'sade', version);
const tepSade = new HeratepalveluTEPStack(app, "sade-services-heratepalvelu-tep", 'sade', version);
new HeratepalveluTEPRAHOITUSStack(app, "sade-services-heratepalvelu-teprah", 'sade', version, tepSade.jaksotunnusTable);
new HeratepalveluTPKStack(app, "sade-services-heratepalvelu-tpk", 'sade', version, tepSade.jaksotunnusTable);
const version = status.isClean() ? gitLog.latest?.hash ?? "uncommitted" : "uncommitted";

const app = new App();

new HeratepalveluAMISStack(app, "sieni-services-heratepalvelu", 'sieni', version);
const tepSieni = new HeratepalveluTEPStack(app, "sieni-services-heratepalvelu-tep", 'sieni', version);
new HeratepalveluTEPRAHOITUSStack(app, "sieni-services-heratepalvelu-teprah", 'sieni', version, tepSieni.jaksotunnusTable);
new HeratepalveluTPKStack(app, "sieni-services-heratepalvelu-tpk", 'sieni', version, tepSieni.jaksotunnusTable);

if (status.isClean()) {
new HeratepalveluAMISStack(app, "pallero-services-heratepalvelu", 'pallero', version);
const tepPallero = new HeratepalveluTEPStack(app, "pallero-services-heratepalvelu-tep", 'pallero', version);
new HeratepalveluTEPRAHOITUSStack(app, "pallero-services-heratepalvelu-teprah", 'pallero', version, tepPallero.jaksotunnusTable);
new HeratepalveluTPKStack(app, "pallero-services-heratepalvelu-tpk", 'pallero', version, tepPallero.jaksotunnusTable);

if (status.tracking === "origin/master") {
new HeratepalveluAMISStack(app, "sade-services-heratepalvelu", 'sade', version);
const tepSade = new HeratepalveluTEPStack(app, "sade-services-heratepalvelu-tep", 'sade', version);
new HeratepalveluTEPRAHOITUSStack(app, "sade-services-heratepalvelu-teprah", 'sade', version, tepSade.jaksotunnusTable);
new HeratepalveluTPKStack(app, "sade-services-heratepalvelu-tpk", 'sade', version, tepSade.jaksotunnusTable);
} else {
console.log("\nNOT IN MASTER BRANCH!!!\n")
}
} else {
console.log("\nNOT IN MASTER BRANCH!!!\n")
console.log("\nUncommited changes or local is ahead/behind of remote, so not doing anything:\n");
console.log(status);
console.log("\n");
}
} else {
console.log("\nUncommited changes or local is ahead/behind of remote, so not doing anything:\n");
console.log(status);
console.log(aheadBehindCount);
console.log("\n");
}
};

checkGitStatus()
.then(() => {
console.log("Done checking git status.");
})
.catch((e) => {
console.log("Error in git status check:", e);
process.exit(1);
});
Loading

0 comments on commit 15a1a82

Please sign in to comment.