Skip to content
This repository was archived by the owner on Mar 26, 2025. It is now read-only.
Open
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: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ openapi.yaml
**/.env

.gitmodules
/hatchet

.idea

Expand Down
6 changes: 5 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
[submodule "hatchet"]
branch = main
path = hatchet
url = https://github.com/hatchet-dev/hatchet.git
branch = main
[submodule "hatchet-cloud"]
branch = feat/iac
path = hatchet-cloud
url = https://github.com/hatchet-dev/hatchet-cloud.git
63 changes: 57 additions & 6 deletions branch-sync.sh
Original file line number Diff line number Diff line change
@@ -1,28 +1,79 @@
#!/bin/bash

# Default values
mode="oss"
repo_url="https://github.com/hatchet-dev/hatchet.git"
submodule_name="hatchet"

# Parse command line options
while getopts ":n:" opt; do
case $opt in
n)
mode=$OPTARG
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done

# Set the repository URL and submodule name based on the mode
if [ "$mode" = "cloud" ]; then
repo_url="https://github.com/hatchet-dev/hatchet-cloud.git"
submodule_name="hatchet-cloud"
else
repo_url="https://github.com/hatchet-dev/hatchet.git"
submodule_name="hatchet"
fi

echo "Mode: $mode"
echo "Repository URL: $repo_url"
echo "Submodule name: $submodule_name"

# 1. Get the current branch name
current_branch=$(echo $GITHUB_HEAD_REF | sed 's/refs\/heads\///')

if [ -z "$current_branch" ]; then
current_branch=$(git rev-parse --abbrev-ref HEAD)
fi

# 2. Check a different repo and determine if a branch with the same name exists
git ls-remote --heads https://github.com/hatchet-dev/hatchet.git $current_branch | grep -q refs/heads/$current_branch
echo "Current branch: $current_branch"

# 2. Check the repo and determine if a branch with the same name exists
git ls-remote --heads $repo_url $current_branch | grep -q refs/heads/$current_branch
branch_exists=$?

# 3. If it does, update the .gitmodules to set `branch = {the branch name}`
if [ $branch_exists -eq 0 ]; then
git config -f .gitmodules submodule.hatchet.branch $current_branch
git config -f .gitmodules submodule.$submodule_name.branch $current_branch
git config -f .gitmodules submodule.$submodule_name.path $submodule_name
git config -f .gitmodules submodule.$submodule_name.url $repo_url
git add .gitmodules
echo "Updated .gitmodules with branch $current_branch"
else
echo "Branch $current_branch does not exist in the remote repository. Pulling main branch instead."
git config -f .gitmodules submodule.hatchet.branch main
echo "Branch $current_branch does not exist in the remote repository. Using main branch instead."
git config -f .gitmodules submodule.$submodule_name.branch main
git config -f .gitmodules submodule.$submodule_name.path $submodule_name
git config -f .gitmodules submodule.$submodule_name.url $repo_url
git add .gitmodules
echo "Updated .gitmodules with branch main"
fi

# 4. Initialize and update the submodule
# 4. Remove existing submodule if it exists
git submodule deinit -f -- $submodule_name
rm -rf .git/modules/$submodule_name
git rm -f $submodule_name

# 5. Re-add and initialize the submodule
git submodule add -b $(git config -f .gitmodules submodule.$submodule_name.branch) $repo_url $submodule_name
git submodule init

# 6. Update the submodule
git submodule update --remote --merge

echo "Hatchet submodule ($mode mode) updated successfully"
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hatchet-dev/typescript-sdk",
"version": "0.15.0",
"version": "0.16.0-alpha.4",
"description": "Background task orchestration & visibility for developers",
"types": "dist/index.d.ts",
"files": [
Expand All @@ -23,6 +23,7 @@
"test:unit:watch": "jest --testMatch='**/*.test.ts' --watch",
"generate": "pnpm run '/generate-.*/'",
"generate-api": "npx --yes swagger-cli bundle ./hatchet/api-contracts/openapi/openapi.yaml --outfile openapi.yaml --type yaml && npx swagger-typescript-api -p openapi.yaml -o src/clients/rest/generated -n hatchet.ts --modular --axios",
"generate-cloud-api": "npx --yes swagger-cli bundle ./hatchet-cloud/api-contracts/openapi/openapi.yaml --outfile openapi.yaml --type yaml && npx swagger-typescript-api -p openapi.yaml -o src/clients/rest/generated/cloud -n hatchet.ts --modular --axios",
"generate-protoc": "./generate-protoc.sh",
"lint:check": "npm run eslint:check && npm run prettier:check",
"lint:fix": "npm run eslint:fix && npm run prettier:fix",
Expand All @@ -38,6 +39,7 @@
"example:rate": "npm run exec -- ./src/examples/rate-limit/events.ts",
"worker:fanout": "npm run exec -- ./src/examples/fanout-worker.ts",
"worker:simple": "npm run exec -- ./src/examples/simple-worker.ts",
"worker:managed": "npm run exec -- ./src/examples/managed-worker.ts",
"worker:affinity": "npm run exec -- ./src/examples/affinity-workers.ts",
"worker:sticky": "npm run exec -- ./src/examples/sticky-worker.ts",
"worker:on-failure": "npm run exec -- ./src/examples/on-failure.ts",
Expand Down
2 changes: 2 additions & 0 deletions src/clients/hatchet-client/client-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export const ClientConfigSchema = z.object({
log_level: z.enum(['OFF', 'DEBUG', 'INFO', 'WARN', 'ERROR']).optional(),
tenant_id: z.string(),
namespace: z.string().optional(),
runnable_actions: z.array(z.string()).optional(),
cloud_register_id: z.string().optional(),
});

export type ClientConfig = z.infer<typeof ClientConfigSchema> & {
Expand Down
5 changes: 4 additions & 1 deletion src/clients/hatchet-client/hatchet-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { AxiosRequestConfig } from 'axios';
import { ClientConfig, ClientConfigSchema } from './client-config';
import { ListenerClient } from '../listener/listener-client';
import { Api } from '../rest/generated/Api';
import api from '../rest';
import api, { CloudApi, cloudApi } from '../rest';

export interface HatchetClientOptions {
config_path?: string;
Expand Down Expand Up @@ -66,6 +66,7 @@ export class HatchetClient {
dispatcher: DispatcherClient;
admin: AdminClient;
api: Api;
cloudApi: CloudApi;
listener: ListenerClient;
tenantId: string;

Expand Down Expand Up @@ -100,6 +101,8 @@ export class HatchetClient {

this.tenantId = this.config.tenant_id;
this.api = api(this.config.api_url, this.config.token, axiosOpts);
this.cloudApi = cloudApi(this.config.api_url, this.config.token, axiosOpts);

this.event = new EventClient(
this.config,
channelFactory(this.config, this.credentials),
Expand Down
14 changes: 14 additions & 0 deletions src/clients/rest/api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import qs from 'qs';
import { AxiosRequestConfig } from 'axios';
import { Api } from './generated/Api';
import { Api as CloudApi } from './generated/cloud/Api';

const api = (serverUrl: string, token: string, axiosOpts?: AxiosRequestConfig) => {
return new Api({
Expand All @@ -13,4 +14,17 @@ const api = (serverUrl: string, token: string, axiosOpts?: AxiosRequestConfig) =
});
};

export const cloudApi = (serverUrl: string, token: string, axiosOpts?: AxiosRequestConfig) => {
return new CloudApi({
baseURL: serverUrl,
headers: {
Authorization: `Bearer ${token}`,
},
paramsSerializer: (params) => qs.stringify(params, { arrayFormat: 'repeat' }),
...axiosOpts,
});
};

export { api, CloudApi };

export default api;
Loading