Skip to content
Merged
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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,4 @@ dist

# Vertesia
lib/
.npmrc
1 change: 1 addition & 0 deletions .npmrc.template
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@dglabs:registry=https://us-central1-npm.pkg.dev/dengenlabs/npm/
5 changes: 5 additions & 0 deletions apps/github-agent/.docker/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"credHelpers": {
"us-docker.pkg.dev": "vertesia"
}
}
7 changes: 7 additions & 0 deletions apps/github-agent/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.env
.DS_Store
.git
.gitignore
*.md
lib/
node_modules/
42 changes: 42 additions & 0 deletions apps/github-agent/.github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: release

on:
push:
tags:
- 'github-agent/*'

permissions:
id-token: write
contents: read

jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: pnpm/action-setup@v4
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 22
cache: pnpm
- name: Install dependencies
run: pnpm install
- name: Run build
run: pnpm -r build
- name: Authenticate with Google Cloud
uses: google-github-actions/auth@v2
with:
token_format: access_token
project_id: dengenlabs
service_account: gar-pusher@dengenlabs.iam.gserviceaccount.com
workload_identity_provider: projects/265888598630/locations/global/workloadIdentityPools/composable-cloud/providers/github
access_token_lifetime: 300s
create_credentials_file: true
- name: Authenticate to Google Artifact Registry
run: pnpm run registry-login --repo-config=.npmrc
- name: Publish Package
run: |
# We modified the .npmrc file to use GAR, which put the Git repository in dirty state.
# So we need to disable the Git checks.
pnpm publish packages/github-agent --no-git-checks
88 changes: 88 additions & 0 deletions apps/github-agent/.github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: actions

on: [push]

permissions:
id-token: write
contents: read

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: pnpm/action-setup@v4
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 22
cache: pnpm
- name: Authenticate with Google Cloud
uses: google-github-actions/auth@v2
with:
token_format: access_token
project_id: dengenlabs
service_account: gar-pusher@dengenlabs.iam.gserviceaccount.com
workload_identity_provider: projects/265888598630/locations/global/workloadIdentityPools/composable-cloud/providers/github
access_token_lifetime: 300s
create_credentials_file: true
- name: Authenticate to Google Artifact Registry
run: |
pnpm install --filter "@dglabs/demo-github-root"
pnpm run registry-login
- name: Install dependencies
run: pnpm install
- name: Run build
run: pnpm -r build
- name: Run tests
run: pnpm -r test

publish-github-agent:
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/docker')
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Authenticate with Google Cloud
uses: google-github-actions/auth@v2
id: gauth
with:
token_format: access_token
project_id: dengenlabs
service_account: gar-pusher@dengenlabs.iam.gserviceaccount.com
workload_identity_provider: projects/265888598630/locations/global/workloadIdentityPools/composable-cloud/providers/github
access_token_lifetime: 300s
create_credentials_file: true

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
# list of Docker images to use as base name for tags
images: |
us.gcr.io/dengenlabs/agents/vertesia/github-agent
tags: |
type=ref,event=branch
type=ref,event=pr
type=sha,format=long,prefix=

- name: Login to GAR
uses: docker/login-action@v3
with:
registry: us.gcr.io
username: oauth2accesstoken
password: ${{ steps.gauth.outputs.access_token }}

- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
file: ./apps/github-agent/Dockerfile
push: ${{ github.ref == 'refs/heads/main' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
secret-files: |
"gcp=${{ steps.gauth.outputs.credentials_file_path }}"
28 changes: 28 additions & 0 deletions apps/github-agent/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM node:23.5-slim AS base
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable
COPY . /app
WORKDIR /app

FROM base AS prod-deps
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --prod --frozen-lockfile

FROM base AS build
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
RUN pnpm run build

FROM base
RUN apt-get update -y && \
apt-get install -y openssl ca-certificates

COPY --from=prod-deps /app/node_modules /app/node_modules
COPY --from=build /app/lib /app/lib
COPY --from=build /app/bin /app/bin

COPY --from=datadog/serverless-init:1 /datadog-init /app/datadog-init

ENV SERVICE_NAME=vertesia_github-agent

ENTRYPOINT ["/app/datadog-init"]
CMD [ "pnpm", "start" ]
26 changes: 26 additions & 0 deletions apps/github-agent/bin/bundle-workflows.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env node

import { bundleWorkflowCode } from '@temporalio/worker';
import { writeFile } from 'node:fs/promises';
import path from 'node:path';

async function bundle(wsPath, bundlePath) {
const { code } = await bundleWorkflowCode({
workflowsPath: path.resolve(wsPath),
});
const codePath = path.resolve(bundlePath);
await writeFile(codePath, code);
console.log(`Bundle written to ${codePath}`);
}

const wsPath = process.argv[2];
const bundlePath = process.argv[3];
if (!wsPath || !bundlePath) {
console.error('Usage: build-workflows <workflows-path> <bundle-path>');
process.exit(1);
}

bundle(wsPath, bundlePath).catch((err) => {
console.error(err);
process.exit(1);
});
35 changes: 35 additions & 0 deletions apps/github-agent/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "@vertesia/github-agent",
"version": "1.10.0",
"description": "",
"type": "module",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"scripts": {
"clean": "rimraf ./lib tsconfig.tsbuildinfo",
"build": "${npm_package_vertesia_pm} run clean && tsc --build && node ./bin/bundle-workflows.mjs lib/workflows.js lib/workflows-bundle.js",
"start": "node lib/main.js",
"connect": "vertesia agent connect"
},
"vertesia": {
"pm": "pnpm",
"image": {
"repository": "us-docker.pkg.dev/dengenlabs/us.gcr.io",
"organization": "vertesia",
"name": "github-agent"
},
"profile": "staging-experiments"
},
"devDependencies": {
"@types/node": "^22.10.2",
"rimraf": "^6.0.1",
"typescript": "^5.7.2",
"vitest": "^2.1.8"
},
"dependencies": {
"@dglabs/agent-runner": "^0.9.2",
"@temporalio/activity": "^1.11.5",
"@temporalio/worker": "^1.11.5",
"@temporalio/workflow": "^1.11.5"
}
}
7 changes: 7 additions & 0 deletions apps/github-agent/src/activities.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { log } from "@temporalio/activity";

// Export your activity functions here

export async function helloActivity() {
log.info("Hello, World!");
}
9 changes: 9 additions & 0 deletions apps/github-agent/src/debug-replayer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { startDebugReplayer } from "@temporalio/worker";
import { resolveScriptFile } from "@dglabs/agent-runner";

resolveScriptFile("./workflows", import.meta.url).then((p: string) => {
console.log("Debugging using workflows path", p);
startDebugReplayer({
workflowsPath: p
})
});
37 changes: 37 additions & 0 deletions apps/github-agent/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* This is a generated file. Do not modify.
*/
import { resolveScriptFile, run } from "@dglabs/agent-runner";
import { readFileSync } from "fs";
import { fileURLToPath } from "url";
import { dirname, resolve } from 'path';

const pkg = readPackageJson();

let domain = `agents/${pkg.name}`;
if (pkg.vertesia?.image?.organization) {
if (pkg.vertesia.image.name) {
domain = `agents/${pkg.vertesia.image.organization}/${pkg.vertesia.image.name}`;
}
}

const workflowBundle = await resolveScriptFile("./workflows-bundle.js", import.meta.url);
const activities = await import("./activities.js");

await run({
workflowBundle,
activities,
domain
}).catch((err: any) => {
console.error(err);
}).finally(() => {
process.exit(0);
});


function readPackageJson() {
const scriptPath = fileURLToPath(import.meta.url);
const pkgFile = resolve(dirname(scriptPath), '../package.json')
const content = readFileSync(pkgFile, "utf8");
return JSON.parse(content);
}
22 changes: 22 additions & 0 deletions apps/github-agent/src/workflows.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { log, proxyActivities } from "@temporalio/workflow";
import * as activities from "./activities.js";

// Export your workflow functions here

const {
helloActivity,
} = proxyActivities<typeof activities>({
startToCloseTimeout: "5 minute",
retry: {
initialInterval: '5s',
backoffCoefficient: 2,
maximumAttempts: 5,
maximumInterval: 100 * 30 * 1000, //ms
nonRetryableErrorTypes: [],
},
});

export async function helloWorkflow() {
log.info("Entering Hello workflow");
await helloActivity();
}
39 changes: 39 additions & 0 deletions apps/github-agent/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"compilerOptions": {
"composite": true,
"rootDir": "./src",
"sourceMap": true,
"outDir": "./lib",
"forceConsistentCasingInFileNames": true,
"experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
"allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */
"target": "ES2022",
"useDefineForClassFields": true,
"lib": [
"ES2022",
"DOM"
],
"module": "NodeNext",
"moduleResolution": "NodeNext",
"declaration": true,
"declarationMap": true,
"skipLibCheck": true,
/* Bundler mode */
//"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
},
"exclude": [
"node_modules",
"**/*.test.ts",
"lib",
"test"
],
"references": []
}
Loading