Skip to content

Use prettier for TypeScript files in .werft #8245

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitpod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,4 @@ vscode:
- timonwong.shellcheck
- vscjava.vscode-java-pack
- fwcd.kotlin
- esbenp.prettier-vscode
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,10 @@ repos:
- id: shellcheck
args: [-e, "SC1090,SC1091"]
exclude: .*/gradlew$

- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v2.5.1"
hooks:
- id: prettier
files: ".werft"
types_or: [ts]
5 changes: 5 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# We dont use it for YAML yet
*.yaml

# For now we only use it for .werft
components
100 changes: 50 additions & 50 deletions .werft/build.ts
Original file line number Diff line number Diff line change
@@ -1,60 +1,60 @@
import * as fs from 'fs';
import { SpanStatusCode } from '@opentelemetry/api';
import { Werft } from './util/werft';
import { reportBuildFailureInSlack } from './util/slack';
import * as Tracing from './observability/tracing'
import * as VM from './vm/vm'
import { buildAndPublish } from './jobs/build/build-and-publish';
import { validateChanges } from './jobs/build/validate-changes';
import { prepare } from './jobs/build/prepare';
import { coverage } from './jobs/build/coverage';
import { deployToPreviewEnvironment } from './jobs/build/deploy-to-preview-environment';
import { triggerIntegrationTests } from './jobs/build/trigger-integration-tests';
import { jobConfig } from './jobs/build/job-config';
import * as fs from "fs";
import { SpanStatusCode } from "@opentelemetry/api";
import { Werft } from "./util/werft";
import { reportBuildFailureInSlack } from "./util/slack";
import * as Tracing from "./observability/tracing";
import * as VM from "./vm/vm";
import { buildAndPublish } from "./jobs/build/build-and-publish";
import { validateChanges } from "./jobs/build/validate-changes";
import { prepare } from "./jobs/build/prepare";
import { coverage } from "./jobs/build/coverage";
import { deployToPreviewEnvironment } from "./jobs/build/deploy-to-preview-environment";
import { triggerIntegrationTests } from "./jobs/build/trigger-integration-tests";
import { jobConfig } from "./jobs/build/job-config";

// Will be set once tracing has been initialized
let werft: Werft
const context: any = JSON.parse(fs.readFileSync('context.json').toString());
let werft: Werft;
const context: any = JSON.parse(fs.readFileSync("context.json").toString());

Tracing.initialize()
.then(() => {
werft = new Werft("build")
})
.then(() => run(context))
.then(() => VM.stopKubectlPortForwards())
.then(() => werft.endAllSpans())
.catch((err) => {
werft.rootSpan.setStatus({
code: SpanStatusCode.ERROR,
message: err
})
werft.endAllSpans()

if (context.Repository.ref === "refs/heads/main") {
reportBuildFailureInSlack(context, err, () => process.exit(1));
} else {
console.log('Error', err)
// Explicitly not using process.exit as we need to flush tracing, see tracing.js
process.exitCode = 1
}

VM.stopKubectlPortForwards()
})
.then(() => {
werft = new Werft("build");
})
.then(() => run(context))
.then(() => VM.stopKubectlPortForwards())
.then(() => werft.endAllSpans())
.catch((err) => {
werft.rootSpan.setStatus({
code: SpanStatusCode.ERROR,
message: err,
});
werft.endAllSpans();

if (context.Repository.ref === "refs/heads/main") {
reportBuildFailureInSlack(context, err, () => process.exit(1));
} else {
console.log("Error", err);
// Explicitly not using process.exit as we need to flush tracing, see tracing.js
process.exitCode = 1;
}

VM.stopKubectlPortForwards();
});

async function run(context: any) {
const config = jobConfig(werft, context)
const config = jobConfig(werft, context);

await validateChanges(werft)
await prepare(werft)
await buildAndPublish(werft, config)
await coverage(werft, config)
await validateChanges(werft);
await prepare(werft);
await buildAndPublish(werft, config);
await coverage(werft, config);

if (config.noPreview) {
werft.phase("deploy", "not deploying");
console.log("no-preview or publish-release is set");
return
}
if (config.noPreview) {
werft.phase("deploy", "not deploying");
console.log("no-preview or publish-release is set");
return;
}

await deployToPreviewEnvironment(werft, config)
await triggerIntegrationTests(werft, config, context.Owner)
await deployToPreviewEnvironment(werft, config);
await triggerIntegrationTests(werft, config, context.Owner);
}
129 changes: 74 additions & 55 deletions .werft/delete-preview-environments/delete-preview-environments-cron.ts
Original file line number Diff line number Diff line change
@@ -1,72 +1,91 @@
import { Werft } from '../util/werft';
import * as Tracing from '../observability/tracing';
import { SpanStatusCode } from '@opentelemetry/api';
import { wipePreviewEnvironmentAndNamespace, helmInstallName, listAllPreviewNamespaces } from '../util/kubectl';
import { exec } from '../util/shell';
import { Werft } from "../util/werft";
import * as Tracing from "../observability/tracing";
import { SpanStatusCode } from "@opentelemetry/api";
import {
wipePreviewEnvironmentAndNamespace,
helmInstallName,
listAllPreviewNamespaces,
} from "../util/kubectl";
import { exec } from "../util/shell";

// Will be set once tracing has been initialized
let werft: Werft
let werft: Werft;

Tracing.initialize()
.then(() => {
werft = new Werft("delete-preview-environment-cron")
})
.then(() => deletePreviewEnvironments())
.then(() => werft.endAllSpans())
.catch((err) => {
werft.rootSpan.setStatus({
code: SpanStatusCode.ERROR,
message: err
})
werft.endAllSpans()
})
.then(() => {
werft = new Werft("delete-preview-environment-cron");
})
.then(() => deletePreviewEnvironments())
.then(() => werft.endAllSpans())
.catch((err) => {
werft.rootSpan.setStatus({
code: SpanStatusCode.ERROR,
message: err,
});
werft.endAllSpans();
});

async function deletePreviewEnvironments() {
werft.phase("prep");
try {
const GCLOUD_SERVICE_ACCOUNT_PATH =
"/mnt/secrets/gcp-sa/service-account.json";
exec(
`gcloud auth activate-service-account --key-file "${GCLOUD_SERVICE_ACCOUNT_PATH}"`
);
exec(
"gcloud container clusters get-credentials core-dev --zone europe-west1-b --project gitpod-core-dev"
);
} catch (err) {
werft.fail("prep", err);
}
werft.done("prep");

werft.phase("prep");
try {
const GCLOUD_SERVICE_ACCOUNT_PATH = "/mnt/secrets/gcp-sa/service-account.json";
exec(`gcloud auth activate-service-account --key-file "${GCLOUD_SERVICE_ACCOUNT_PATH}"`);
exec('gcloud container clusters get-credentials core-dev --zone europe-west1-b --project gitpod-core-dev');
} catch (err) {
werft.fail("prep", err)
}
werft.done("prep")
werft.phase("Fetching branches");
const branches = getAllBranches();
const expectedPreviewEnvironmentNamespaces = new Set(
branches.map((branch) => parseBranch(branch))
);
werft.done("Fetching branches");

werft.phase("Fetching branches");
const branches = getAllBranches();
const expectedPreviewEnvironmentNamespaces = new Set(branches.map(branch => parseBranch(branch)));
werft.done("Fetching branches");
werft.phase("Fetching previews");
let previews;
try {
previews = listAllPreviewNamespaces({});
} catch (err) {
werft.fail("Fetching previews", err);
}
werft.done("Fetching previews");

werft.phase("Fetching previews");
let previews
try {
previews = listAllPreviewNamespaces({});
} catch (err) {
werft.fail("Fetching previews", err)
}
werft.done("Fetching previews");
werft.phase("Mapping previews => branches");
const previewsToDelete = previews.filter(
(ns) => !expectedPreviewEnvironmentNamespaces.has(ns)
);


werft.phase("Mapping previews => branches")
const previewsToDelete = previews.filter(ns => !expectedPreviewEnvironmentNamespaces.has(ns))

werft.phase("deleting previews")
try {
previewsToDelete.forEach(preview => wipePreviewEnvironmentAndNamespace(helmInstallName, preview, { slice: `Deleting preview ${preview}` }));
} catch (err) {
werft.fail("deleting previews", err)
}
werft.done("deleting previews")
werft.phase("deleting previews");
try {
previewsToDelete.forEach((preview) =>
wipePreviewEnvironmentAndNamespace(helmInstallName, preview, {
slice: `Deleting preview ${preview}`,
})
);
} catch (err) {
werft.fail("deleting previews", err);
}
werft.done("deleting previews");
}

function getAllBranches(): string[] {
return exec(`git branch -r | grep -v '\\->' | sed "s,\\x1B\\[[0-9;]*[a-zA-Z],,g" | while read remote; do echo "\${remote#origin/}"; done`).stdout.trim().split('\n');
return exec(
`git branch -r | grep -v '\\->' | sed "s,\\x1B\\[[0-9;]*[a-zA-Z],,g" | while read remote; do echo "\${remote#origin/}"; done`
)
.stdout.trim()
.split("\n");
}

function parseBranch(branch: string): string {
const prefix = 'staging-';
const parsedBranch = branch.normalize().split("/").join("-");
const prefix = "staging-";
const parsedBranch = branch.normalize().split("/").join("-");

return prefix + parsedBranch;
}
return prefix + parsedBranch;
}
85 changes: 46 additions & 39 deletions .werft/delete-preview-environments/delete-preview-environments.ts
Original file line number Diff line number Diff line change
@@ -1,50 +1,57 @@
import { Werft } from '../util/werft';
import * as fs from 'fs';
import * as Tracing from '../observability/tracing';
import { SpanStatusCode } from '@opentelemetry/api';
import { wipePreviewEnvironmentAndNamespace, helmInstallName } from '../util/kubectl';
import { Werft } from "../util/werft";
import * as fs from "fs";
import * as Tracing from "../observability/tracing";
import { SpanStatusCode } from "@opentelemetry/api";
import {
wipePreviewEnvironmentAndNamespace,
helmInstallName,
} from "../util/kubectl";

// Will be set once tracing has been initialized
let werft: Werft
let werft: Werft;

const context = JSON.parse(fs.readFileSync('context.json').toString());
const context = JSON.parse(fs.readFileSync("context.json").toString());

Tracing.initialize()
.then(() => {
werft = new Werft("delete-preview-environment")
})
.then(() => deletePreviewEnvironment())
.then(() => werft.endAllSpans())
.catch((err) => {
werft.rootSpan.setStatus({
code: SpanStatusCode.ERROR,
message: err
})
werft.endAllSpans()
})
.then(() => {
werft = new Werft("delete-preview-environment");
})
.then(() => deletePreviewEnvironment())
.then(() => werft.endAllSpans())
.catch((err) => {
werft.rootSpan.setStatus({
code: SpanStatusCode.ERROR,
message: err,
});
werft.endAllSpans();
});

async function deletePreviewEnvironment() {
werft.phase("preparing deletion")
const version = parseVersion();
const namespace = `staging-${version.split(".")[0]}`
werft.log("preparing deletion", `Proceeding to delete the ${namespace} namespace`)
werft.done("preparing deletion")
werft.phase("preparing deletion");
const version = parseVersion();
const namespace = `staging-${version.split(".")[0]}`;
werft.log(
"preparing deletion",
`Proceeding to delete the ${namespace} namespace`
);
werft.done("preparing deletion");

werft.phase("delete-preview")
try {
await wipePreviewEnvironmentAndNamespace(helmInstallName, namespace, { slice: 'delete-preview' })
} catch (err) {
werft.fail("delete-preview", err)
}
werft.done("delete-prewview")
werft.phase("delete-preview");
try {
await wipePreviewEnvironmentAndNamespace(helmInstallName, namespace, {
slice: "delete-preview",
});
} catch (err) {
werft.fail("delete-preview", err);
}
werft.done("delete-prewview");
}


export function parseVersion() {
let version = context.Name;
const PREFIX_TO_STRIP = "gitpod-delete-preview-environment-";
if (version.substr(0, PREFIX_TO_STRIP.length) === PREFIX_TO_STRIP) {
version = version.substr(PREFIX_TO_STRIP.length);
}
return version
}
let version = context.Name;
const PREFIX_TO_STRIP = "gitpod-delete-preview-environment-";
if (version.substr(0, PREFIX_TO_STRIP.length) === PREFIX_TO_STRIP) {
version = version.substr(PREFIX_TO_STRIP.length);
}
return version;
}
Loading