@vaharoni/devops 1.0.47 → 1.0.49

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -46,6 +46,6 @@ bun unlink
46
46
  To release:
47
47
  ```shell
48
48
  npm version patch
49
- git push --tags
49
+ git push --follow-tags
50
50
  gh release create vX.Y.Z
51
51
  ```
package/dist/cli/init.js CHANGED
@@ -55,12 +55,17 @@ To finish the setup:
55
55
  ],
56
56
 
57
57
  2. add the following to your .gitignore:
58
- .envrc
59
- **/.DS_Store
60
58
  **/.env*
61
59
  config/kubeconfig
62
60
  tmp/**
63
61
  !tmp/**/.gitkeep
64
62
  venv/
65
63
  **/__pycache__
64
+
65
+ 3. optionally create an .envrc file with the following content and run direnv allow:
66
+ if [ -f "$PWD/config/kubeconfig" ]; then
67
+ export KUBECONFIG="$PWD/config/kubeconfig"
68
+ else
69
+ export KUBECONFIG="$HOME/.kube/config"
70
+ fi
66
71
  `;
package/dist/devops.js CHANGED
File without changes
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vaharoni/devops",
3
3
  "type": "module",
4
- "version": "1.0.47",
4
+ "version": "1.0.49",
5
5
  "description": "Devops utility",
6
6
  "main": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
package/src/cli/init.ts CHANGED
@@ -64,12 +64,17 @@ To finish the setup:
64
64
  ],
65
65
 
66
66
  2. add the following to your .gitignore:
67
- .envrc
68
- **/.DS_Store
69
67
  **/.env*
70
68
  config/kubeconfig
71
69
  tmp/**
72
70
  !tmp/**/.gitkeep
73
71
  venv/
74
72
  **/__pycache__
73
+
74
+ 3. optionally create an .envrc file with the following content and run direnv allow:
75
+ if [ -f "$PWD/config/kubeconfig" ]; then
76
+ export KUBECONFIG="$PWD/config/kubeconfig"
77
+ else
78
+ export KUBECONFIG="$HOME/.kube/config"
79
+ fi
75
80
  `;
@@ -18,10 +18,7 @@ RUN npm install -g bun
18
18
  COPY . .
19
19
 
20
20
  # Install dependencies using bun
21
- # Mount the GH_PAT_TOKEN secret and use it during bun install
22
- RUN --mount=type=secret,id=GH_PAT_TOKEN \
23
- --mount=type=cache,target=/root/.bun/install/cache \
24
- GH_PAT_TOKEN=$(cat /run/secrets/GH_PAT_TOKEN) bun install
21
+ RUN --mount=type=cache,target=/root/.bun/install/cache bun install
25
22
 
26
23
  # For prisma client, if used
27
24
  RUN ./devops run-many generate
@@ -4,9 +4,6 @@ inputs:
4
4
  image_name:
5
5
  description: 'The image key in images.yaml'
6
6
  required: true
7
- gh_pat_token:
8
- description: "GitHub personal access token"
9
- required: true
10
7
  cache_path:
11
8
  description: "The path to cache inside the container"
12
9
  required: true
@@ -74,8 +71,6 @@ runs:
74
71
  tags: ${{ env.ECR_URL }}
75
72
  cache-from: type=gha
76
73
  cache-to: type=gha,mode=max
77
- secrets: |
78
- GH_PAT_TOKEN=${{ inputs.gh_pat_token }}
79
74
  build-args: |
80
75
  MONOREPO_ENV=${{ env.MONOREPO_ENV }}
81
76
 
@@ -1,9 +1,5 @@
1
1
  name: "Install prerequesites"
2
2
  description: "Sets up Node, Bun, and devops"
3
- inputs:
4
- gh_pat_token:
5
- description: "The GitHub Personal Access Token"
6
- required: true
7
3
  runs:
8
4
  using: "composite"
9
5
  steps:
@@ -20,7 +16,6 @@ runs:
20
16
  run: |
21
17
  BRANCH_NAME=${{ github.ref_name }}
22
18
  echo "MONOREPO_ENV=$BRANCH_NAME" >> $GITHUB_ENV
23
- echo "GH_PAT_TOKEN=${{ inputs.gh_pat_token }}" >> $GITHUB_ENV
24
19
 
25
20
  - name: Install the devops tool
26
21
  shell: bash
@@ -28,8 +28,6 @@ jobs:
28
28
 
29
29
  - name: Setup prerequesites
30
30
  uses: ./.github/actions/setup-prereq@v1
31
- with:
32
- gh_pat_token: ${{ secrets.GH_PAT_TOKEN }}
33
31
 
34
32
  - name: Connect to infrastructure
35
33
  uses: ./.github/actions/connect-to-infra@v1
@@ -44,7 +42,6 @@ jobs:
44
42
  uses: ./.github/actions/build-image@v1
45
43
  with:
46
44
  image_name: ${{ matrix.image_name }}
47
- gh_pat_token: ${{ secrets.GH_PAT_TOKEN }}
48
45
  cache_path: ${{ matrix.cache_path || '/root/.bun/install/cache' }}
49
46
 
50
47
  db_migrate_and_deploy:
@@ -59,8 +56,6 @@ jobs:
59
56
 
60
57
  - name: Setup prerequesites
61
58
  uses: ./.github/actions/setup-prereq@v1
62
- with:
63
- gh_pat_token: ${{ secrets.GH_PAT_TOKEN }}
64
59
 
65
60
  - name: Connect to infrastructure
66
61
  uses: ./.github/actions/connect-to-infra@v1
@@ -1,19 +0,0 @@
1
- import type { ProjectData } from "../types";
2
- export declare class WorkspaceDependencies {
3
- getAllProjects: () => Record<string, ProjectData>;
4
- dependencies: Record<string, DependencyNode>;
5
- loaded: boolean;
6
- projects: Record<string, ProjectData>;
7
- constructor(getAllProjects: () => Record<string, ProjectData>);
8
- _getOrCreate(name: string): DependencyNode;
9
- _buildTree(): void;
10
- getDependents(workspaceName: string): string[];
11
- }
12
- declare class DependencyNode {
13
- name: string;
14
- dependsOn: Set<string>;
15
- constructor(name: string);
16
- flattenDependents(allDependencies: Record<string, DependencyNode>, visited?: Set<string>): string[];
17
- }
18
- export {};
19
- //# sourceMappingURL=dependencies.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dependencies.d.ts","sourceRoot":"","sources":["../../src/libs/dependencies.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAE5C,qBAAa,qBAAqB;IAKb,cAAc,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC;IAJpE,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAM;IAClD,MAAM,UAAS;IACf,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAM;gBAExB,cAAc,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC;IAEpE,YAAY,CAAC,IAAI,EAAE,MAAM;IASzB,UAAU;IAcV,aAAa,CAAC,aAAa,EAAE,MAAM;CAWpC;AAED,cAAM,cAAc;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;gBAEX,IAAI,EAAE,MAAM;IAKxB,iBAAiB,CACf,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,EAC/C,OAAO,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC;CAexB"}
@@ -1,62 +0,0 @@
1
- import chalk from "chalk";
2
- export class WorkspaceDependencies {
3
- getAllProjects;
4
- dependencies = {};
5
- loaded = false;
6
- projects = {};
7
- constructor(getAllProjects) {
8
- this.getAllProjects = getAllProjects;
9
- }
10
- _getOrCreate(name) {
11
- let node = this.dependencies[name];
12
- if (!node) {
13
- node = new DependencyNode(name);
14
- this.dependencies[name] = node;
15
- }
16
- return node;
17
- }
18
- _buildTree() {
19
- this.projects = this.getAllProjects();
20
- this.loaded = true;
21
- for (const workspace of Object.keys(this.projects)) {
22
- const node = this._getOrCreate(workspace);
23
- const { data } = this.projects[workspace];
24
- for (const dep of data.dependencyNames ?? []) {
25
- if (this.projects[dep]) {
26
- node.dependsOn.add(dep);
27
- }
28
- }
29
- }
30
- }
31
- getDependents(workspaceName) {
32
- if (!this.loaded) {
33
- this._buildTree();
34
- }
35
- const node = this.dependencies[workspaceName];
36
- if (!node) {
37
- console.error(chalk.red(`\nWorkspace ${workspaceName} not found\n`));
38
- process.exit(1);
39
- }
40
- return node.flattenDependents(this.dependencies);
41
- }
42
- }
43
- class DependencyNode {
44
- name;
45
- dependsOn;
46
- constructor(name) {
47
- this.name = name;
48
- this.dependsOn = new Set();
49
- }
50
- flattenDependents(allDependencies, visited) {
51
- visited ??= new Set();
52
- visited.add(this.name);
53
- const notVisitedDependents = [];
54
- for (const dep of this.dependsOn) {
55
- if (!visited.has(dep)) {
56
- const node = allDependencies[dep];
57
- notVisitedDependents.push(...node.flattenDependents(allDependencies, visited));
58
- }
59
- }
60
- return [this.name, ...notVisitedDependents];
61
- }
62
- }
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=dependencies.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dependencies.spec.d.ts","sourceRoot":"","sources":["../../src/libs/dependencies.spec.ts"],"names":[],"mappings":""}
@@ -1,21 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { WorkspaceDependencies } from './dependencies';
3
- describe('createDependencyResolver', () => {
4
- const projects = {
5
- '@local/a': { rootPath: 'applications/a', data: { name: '@local/a', dependencies: { '@local/b': 'workspace:*', '@local/d': 'workspace:*', external1: "^1.0.0" } } },
6
- '@local/b': { rootPath: 'applications/b', data: { name: '@local/b', dependencies: { '@local/c': 'workspace:*', external2: "^1.0.0" } } },
7
- '@local/c': { rootPath: 'applications/c', data: { name: '@local/c', dependencies: { external3: "^1.0.0" } } },
8
- '@local/d': { rootPath: 'applications/d', data: { name: '@local/d' } },
9
- '@local/e': { rootPath: 'applications/e', data: { name: '@local/e', dependencies: { '@local/f': 'workspace:*' } } },
10
- '@local/f': { rootPath: 'applications/f', data: { name: '@local/f', dependencies: { '@local/e': 'workspace:*' } } },
11
- };
12
- it('should return dependents of a given project', () => {
13
- const resolver = new WorkspaceDependencies(() => projects);
14
- expect(resolver.getDependents('@local/a')).toEqual(['@local/a', '@local/b', '@local/c', '@local/d']);
15
- expect(resolver.getDependents('@local/b')).toEqual(['@local/b', '@local/c']);
16
- expect(resolver.getDependents('@local/c')).toEqual(['@local/c']);
17
- expect(resolver.getDependents('@local/d')).toEqual(['@local/d']);
18
- expect(resolver.getDependents('@local/e')).toEqual(['@local/e', '@local/f']);
19
- expect(resolver.getDependents('@local/f')).toEqual(['@local/f', '@local/e']);
20
- });
21
- });
@@ -1,3 +0,0 @@
1
- import { type ProjectData } from "../../types";
2
- export declare function nodeWorkspaces(): Record<string, ProjectData>;
3
- //# sourceMappingURL=package-json-processor.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"package-json-processor.d.ts","sourceRoot":"","sources":["../../../src/libs/discovery/package-json-processor.ts"],"names":[],"mappings":"AAIA,OAAO,EAAqB,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAUlE,wBAAgB,cAAc,gCAgC7B"}
@@ -1,34 +0,0 @@
1
- import chalk from "chalk";
2
- import fs from "fs";
3
- import { globSync } from "glob";
4
- import path from "path";
5
- import { packageJsonSchema } from "../../types";
6
- const rootPkgJsonPath = path.join(process.cwd(), "package.json");
7
- const rootPkgJson = JSON.parse(fs.readFileSync(rootPkgJsonPath, "utf8"));
8
- const _workspaces = {};
9
- let _workspacesLoaded = false;
10
- export function nodeWorkspaces() {
11
- if (!_workspacesLoaded) {
12
- for (const workspaceGlob of (rootPkgJson.workspaces ?? [])) {
13
- globSync(path.join(workspaceGlob, "package.json")).forEach((packageJsonPath) => {
14
- // Skip packages under node_modules directories in case hoisting did not work
15
- if (packageJsonPath.includes("node_modules"))
16
- return;
17
- const unsafeData = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
18
- const parsedRes = packageJsonSchema.safeParse(unsafeData);
19
- if (parsedRes.error) {
20
- console.error(`Error parsing ${packageJsonPath}: ${parsedRes.error}`);
21
- process.exit(1);
22
- }
23
- const { dependencies, ...rest } = parsedRes.data;
24
- const dependencyNames = Object.keys(dependencies ?? []);
25
- const pkgName = rest.name;
26
- const rootPath = path.dirname(packageJsonPath);
27
- _workspaces[pkgName] = { data: { ...rest, dependencyNames }, rootPath };
28
- });
29
- }
30
- console.warn(chalk.yellow(`Node workspace discovery initialized. Workspaces found: ${Object.keys(_workspaces).join(", ")}`));
31
- _workspacesLoaded = true;
32
- }
33
- return _workspaces;
34
- }
@@ -1,3 +0,0 @@
1
- import { type ProjectData } from "../../types";
2
- export declare function pythonWorkspaces(): Record<string, ProjectData>;
3
- //# sourceMappingURL=pyproject-toml-processor.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"pyproject-toml-processor.d.ts","sourceRoot":"","sources":["../../../src/libs/discovery/pyproject-toml-processor.ts"],"names":[],"mappings":"AAIA,OAAO,EAAmB,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAMhE,wBAAgB,gBAAgB,gCAsC/B"}
@@ -1,39 +0,0 @@
1
- import chalk from "chalk";
2
- import fs from "fs";
3
- import { globSync } from "glob";
4
- import path from "path";
5
- import { pyProjectSchema } from "../../types";
6
- import TOML from '@iarna/toml';
7
- const _workspaces = {};
8
- let _workspacesLoaded = false;
9
- export function pythonWorkspaces() {
10
- if (!_workspacesLoaded) {
11
- globSync(path.join(process.cwd(), "**/*/pyproject.toml")).forEach((pyProjectPath) => {
12
- // Skip packages under venv just in case
13
- if (pyProjectPath.includes("venv"))
14
- return;
15
- const unsafeData = TOML.parse(fs.readFileSync(pyProjectPath, "utf8"));
16
- const parsedRes = pyProjectSchema.safeParse(unsafeData);
17
- if (parsedRes.error) {
18
- console.error(`Error parsing ${pyProjectPath}: ${parsedRes.error}`);
19
- process.exit(1);
20
- }
21
- const data = parsedRes.data;
22
- const pkgName = data.project.name;
23
- const deployment = data.tool?.devops?.deployment;
24
- const rootPath = path.dirname(pyProjectPath);
25
- _workspaces[pkgName] = {
26
- rootPath,
27
- data: {
28
- name: pkgName,
29
- scripts: data.tool?.poetry?.scripts,
30
- dependencyNames: Object.keys(data.tool?.poetry?.dependencies ?? []),
31
- deployment,
32
- }
33
- };
34
- });
35
- console.warn(chalk.yellow(`Python workspace discovery initialized. Workspaces found: ${Object.keys(_workspaces).join(", ")}`));
36
- _workspacesLoaded = true;
37
- }
38
- return _workspaces;
39
- }
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=workspace-discovery.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"workspace-discovery.d.ts","sourceRoot":"","sources":["../../src/libs/workspace-discovery.ts"],"names":[],"mappings":""}
@@ -1,75 +0,0 @@
1
- // import chalk from "chalk";
2
- // import fs from "fs";
3
- // import { globSync } from "glob";
4
- // import path from "path";
5
- // import type { PkgData, ProjectData } from "../types";
6
- // import { WorkspaceDependencies } from "./dependencies";
7
- // import { getImageData, getImageNames } from "./config";
8
- export {};
9
- // const _imageDescendents: Record<string, string[]> = {};
10
- // let _imageDescendentsLoaded = false;
11
- // function imageDescendents() {
12
- // if (!_imageDescendentsLoaded) {
13
- // for (const imageName of getImageNames()) {
14
- // const imageData = getImageData(imageName);
15
- // const descendents = new Set<string>();
16
- // imageData.applications.forEach((project) => {
17
- // descendents.add(project);
18
- // getDescendentNames(project).forEach((name) => descendents.add(name));
19
- // });
20
- // _imageDescendents[imageName] = Array.from(descendents);
21
- // }
22
- // _imageDescendentsLoaded = true;
23
- // }
24
- // return _imageDescendents;
25
- // }
26
- // const _workspaceImages: Record<string, string[]> = {};
27
- // let _workspaceImagesLoaded = false;
28
- // function workspaceImages() {
29
- // if (!_workspaceImagesLoaded) {
30
- // for (const [imageName, descendents] of Object.entries(imageDescendents())) {
31
- // for (const workspaceName of descendents) {
32
- // _workspaceImages[workspaceName] ??= [];
33
- // _workspaceImages[workspaceName].push(imageName);
34
- // }
35
- // }
36
- // _workspaceImagesLoaded = true;
37
- // }
38
- // return _workspaceImages;
39
- // }
40
- // export function workspaceNames() {
41
- // return Object.keys(workspaces());
42
- // }
43
- // export function getWorkspace(workspaceName: string) {
44
- // const workspace = workspaces()[workspaceName];
45
- // if (!workspace) {
46
- // console.error(chalk.red(`\nWorkspace ${workspaceName} not found\n`));
47
- // // The gha relies on the 13 exit code for "not found"
48
- // process.exit(13);
49
- // }
50
- // return workspace;
51
- // }
52
- // const dependencyResolve = new WorkspaceDependencies(workspaces);
53
- // /** Note: this includes the name of the provided workspace */
54
- // export function getDescendentNames(workspaceName: string) {
55
- // const _ensurePresence = getWorkspace(workspaceName);
56
- // return dependencyResolve.getDependents(workspaceName);
57
- // }
58
- // /** Note: this includes the provided workspace's data */
59
- // export function getDecendentData(workspaceName: string) {
60
- // return getDescendentNames(workspaceName).map((name) => getWorkspace(name));
61
- // }
62
- // /** The dependent workspaces are specified in config/images.yaml */
63
- // export function getImageDescendentNames(imageName: string) {
64
- // return imageDescendents()[imageName];
65
- // }
66
- // /** The dependent workspaces are specified in config/images.yaml */
67
- // export function getImageDescendentData(imageName: string) {
68
- // return (
69
- // getImageDescendentNames(imageName).map((name) => getWorkspace(name)) ?? []
70
- // );
71
- // }
72
- // export function getWorkspaceImages(workspaceName: string) {
73
- // const _verifyPresence = getWorkspace(workspaceName);
74
- // return workspaceImages()[workspaceName] ?? [];
75
- // }
@@ -1,5 +0,0 @@
1
- if [ -f "$PWD/config/kubeconfig" ]; then
2
- export KUBECONFIG="$PWD/config/kubeconfig"
3
- else
4
- export KUBECONFIG="${HOME}/.kube/config"
5
- fi