Skip to content
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

chore: Unify all SDKs to the inferable monorepo #1

Merged
merged 12 commits into from
Oct 25, 2024
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
189 changes: 189 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
name: Build and Test

on:
push:
branches:
- main
pull_request:
branches:
- main

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
check_changes:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: read
outputs:
sdk_node: ${{ steps.filter.outputs.sdk_node }}
sdk_dotnet: ${{ steps.filter.outputs.sdk_dotnet }}
sdk_go: ${{ steps.filter.outputs.sdk_go }}
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Filter changed files
uses: dorny/paths-filter@v2
id: filter
with:
filters: |
sdk_node:
- 'sdk-node/**'
sdk_dotnet:
- 'sdk-dotnet/**'
sdk_go:
- 'sdk-go/**'

build-node:
needs: check_changes
if: ${{ needs.check_changes.outputs.sdk_node == 'true' }}
runs-on: ubuntu-latest
permissions:
contents: read
defaults:
run:
working-directory: sdk-node
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 20
cache: "npm"
cache-dependency-path: sdk-node/package-lock.json
- name: Install dependencies
run: npm ci
- name: Build package
run: npm run build

test-node:
needs: [check_changes, build-node]
if: ${{ needs.check_changes.outputs.sdk_node == 'true' }}
runs-on: ubuntu-latest
permissions:
contents: read
strategy:
matrix:
# node-version: [18.x, 20.x, 21.x] There's a race condition with retry.test.ts
node-version: [20.x]
defaults:
run:
working-directory: sdk-node
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: "npm"
cache-dependency-path: sdk-node/package-lock.json
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm run test
env:
INFERABLE_API_ENDPOINT: "https://api.inferable.ai"
INFERABLE_CLUSTER_ID: ${{ secrets.INFERABLE_CLUSTER_ID }}
INFERABLE_MACHINE_SECRET: ${{ secrets.INFERABLE_MACHINE_SECRET }}
INFERABLE_CONSUME_SECRET: ${{ secrets.INFERABLE_CONSUME_SECRET }}

build-dotnet:
needs: check_changes
if: ${{ needs.check_changes.outputs.sdk_dotnet == 'true' }}
runs-on: windows-latest
permissions:
contents: read
defaults:
run:
working-directory: sdk-dotnet
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: "8.0.x"
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --configuration Release --no-restore

test-dotnet:
needs: [check_changes, build-dotnet]
if: ${{ needs.check_changes.outputs.sdk_dotnet == 'true' }}
runs-on: windows-latest
permissions:
contents: read
defaults:
run:
working-directory: sdk-dotnet
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: "8.0.x"
- name: Restore dependencies
run: dotnet restore
- name: Test
run: dotnet test --no-restore
env:
INFERABLE_API_ENDPOINT: "https://api.inferable.ai"
INFERABLE_CLUSTER_ID: ${{ secrets.INFERABLE_CLUSTER_ID }}
INFERABLE_MACHINE_SECRET: ${{ secrets.INFERABLE_MACHINE_SECRET }}
INFERABLE_CONSUME_SECRET: ${{ secrets.INFERABLE_CONSUME_SECRET }}

build-go:
needs: check_changes
if: ${{ needs.check_changes.outputs.sdk_go == 'true' }}
runs-on: ubuntu-latest
permissions:
contents: read
defaults:
run:
working-directory: sdk-go
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "1.22"
- name: Get dependencies
run: go mod download
- name: Build
run: go build -v ./...

test-go:
needs: [check_changes, build-go]
if: ${{ needs.check_changes.outputs.sdk_go == 'true' }}
runs-on: ubuntu-latest
permissions:
contents: read
defaults:
run:
working-directory: sdk-go
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "1.22"
- name: Get dependencies
run: go mod download
- name: Test
run: go test -v ./...
env:
INFERABLE_API_ENDPOINT: "https://api.inferable.ai"
INFERABLE_CLUSTER_ID: ${{ secrets.INFERABLE_CLUSTER_ID }}
INFERABLE_MACHINE_SECRET: ${{ secrets.INFERABLE_MACHINE_SECRET }}
INFERABLE_CONSUME_SECRET: ${{ secrets.INFERABLE_CONSUME_SECRET }}
153 changes: 143 additions & 10 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,167 @@ concurrency:
cancel-in-progress: true

jobs:
build-and-publish:
if: ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.head_branch == 'main' }}
check_changes:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: read
if: ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.head_branch == 'main' }}
outputs:
sdk_node: ${{ steps.filter.outputs.sdk_node }}
sdk_dotnet: ${{ steps.filter.outputs.sdk_dotnet }}
sdk_go: ${{ steps.filter.outputs.sdk_go }}
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Filter changed files
uses: dorny/paths-filter@v2
id: filter
with:
filters: |
sdk_node:
- 'sdk-node/**'
sdk_dotnet:
- 'sdk-dotnet/**'
sdk_go:
- 'sdk-go/**'

publish-node:
needs: check_changes
if: ${{ needs.check_changes.outputs.sdk_node == 'true' }}
runs-on: ubuntu-latest
permissions:
contents: write

packages: write
defaults:
run:
working-directory: sdk-node
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Install dependencies on root
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 20
cache: "npm"
cache-dependency-path: sdk-node/package-lock.json
- name: Install dependencies
run: npm ci

- name: Build packages
- name: Build package
run: npm run build

- name: Configure Git User
run: |
git config --global user.name "Inferable CI"
git config --global user.email "[email protected]"

- name: Release It
run: |
npm config set //registry.npmjs.org/:_authToken $NPM_TOKEN
npx release-it --npm.skipChecks
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

publish-dotnet:
needs: check_changes
if: ${{ needs.check_changes.outputs.sdk_dotnet == 'true' }}
runs-on: windows-latest
permissions:
contents: write
defaults:
run:
working-directory: sdk-dotnet
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: "8.0.x"
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --configuration Release --no-restore
- name: Test
run: dotnet test --no-restore
- name: Pack
run: dotnet pack --configuration Release --no-restore --output ./output
- name: Setup NuGet
uses: nuget/setup-nuget@v1
with:
nuget-api-key: ${{ secrets.NUGET_API_KEY }}
nuget-version: latest
- name: Publish
run: dotnet nuget push output\*.nupkg -s https://api.nuget.org/v3/index.json
- name: Extract version from NuGet package
id: extract_version
shell: pwsh
run: |
$nupkg = Get-ChildItem -Path ./output -Filter *.nupkg | Select-Object -First 1
if ($nupkg) {
$version = $nupkg.Name -replace '^[a-zA-Z0-9.-]+\.([0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+)?)\.nupkg$', '$1'
echo "version=$version" >> $GITHUB_OUTPUT
} else {
Write-Error "No .nupkg file found."
}
- name: Create release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.extract_version.outputs.version }}
release_name: ${{ steps.extract_version.outputs.version }}

publish-go:
needs: check_changes
if: ${{ needs.check_changes.outputs.sdk_go == 'true' }}
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
defaults:
run:
working-directory: sdk-go
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "1.22"
- name: Get current version
id: get_version
run: |
VERSION=$(grep -oP 'const Version = "\K[^"]+' inferable.go)
echo "current_version=$VERSION" >> $GITHUB_OUTPUT
- name: Increment patch version
id: increment_version
run: |
IFS='.' read -ra VERSION_PARTS <<< "${{ steps.get_version.outputs.current_version }}"
MAJOR=${VERSION_PARTS[0]}
MINOR=${VERSION_PARTS[1]}
PATCH=$((VERSION_PARTS[2] + 1))
NEW_VERSION="$MAJOR.$MINOR.$PATCH"
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
- name: Update version in code
run: |
sed -i 's/const Version = "[^"]*"/const Version = "${{ steps.increment_version.outputs.new_version }}"/' inferable.go
- name: Commit and push changes
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add inferable.go
git commit -m "Bump version to ${{ steps.increment_version.outputs.new_version }}"
git push
- name: Create Git tag
run: |
git tag v${{ steps.increment_version.outputs.new_version }}
git push origin v${{ steps.increment_version.outputs.new_version }}
29 changes: 29 additions & 0 deletions grand-unifier.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
rm -rf sdk-node
git clone [email protected]:inferablehq/inferable-node.git sdk-node
rm -rf sdk-node/.git
mkdir -p workflows/node
mv sdk-node/.github workflows/node/
rm -rf sdk-node/.editorconfig

rm -rf sdk-go
git clone [email protected]:inferablehq/inferable-go.git sdk-go
rm -rf sdk-go/.git
mkdir -p workflows/go
mv sdk-go/.github workflows/go/
mv sdk-go/.github workflows/
rm -rf sdk-go/.editorconfig

rm -rf sdk-bash
git clone [email protected]:inferablehq/inferable-bash.git sdk-bash
rm -rf sdk-bash/.git
mkdir -p workflows/bash
mv sdk-bash/.github workflows/bash/
mv sdk-bash/.github workflows/
rm -rf sdk-bash/.editorconfig

rm -rf sdk-dotnet
git clone [email protected]:inferablehq/inferable-dotnet.git sdk-dotnet
rm -rf sdk-dotnet/.git
mkdir -p workflows/dotnet
mv sdk-dotnet/.github workflows/dotnet/
rm -rf sdk-dotnet/.editorconfig
Loading
Loading