ci: configure workflows to be package-by-package

Andrey Nering created

Copied generate script from `charmbracelet/x`.

Change summary

.github/workflows/ai.yml        | 56 +++++++++++++++++++++++++++
.github/workflows/anthropic.yml | 56 +++++++++++++++++++++++++++
.github/workflows/build.yml     | 11 -----
.github/workflows/examples.yml  | 56 +++++++++++++++++++++++++++
.github/workflows/lint.yml      | 11 -----
.github/workflows/openai.yml    | 56 +++++++++++++++++++++++++++
scripts/generate_ci             | 71 +++++++++++++++++++++++++++++++++++
7 files changed, 295 insertions(+), 22 deletions(-)

Detailed changes

.github/workflows/ai.yml 🔗

@@ -0,0 +1,56 @@
+# auto-generated by scripts/builds. DO NOT EDIT.
+name: ai
+
+on:
+  push:
+    branches:
+      - main
+  pull_request:
+    paths:
+      - ai/**
+      - .github/workflows/ai.yml
+
+jobs:
+  build:
+    strategy:
+      matrix:
+        os: [ubuntu-latest, macos-latest, windows-latest]
+    runs-on: ${{ matrix.os }}
+    defaults:
+      run:
+        working-directory: ./ai
+    steps:
+      - uses: actions/checkout@v4
+      - uses: actions/setup-go@v5
+        with:
+          go-version-file: ./ai/go.mod
+          cache: true
+          cache-dependency-path: ./ai/go.sum
+      - run: go build -v ./...
+      - run: go test -race -v ./...
+
+  dependabot:
+    needs: [build]
+    runs-on: ubuntu-latest
+    permissions:
+      pull-requests: write
+      contents: write
+    if: ${{ github.actor == 'dependabot[bot]' && github.event_name == 'pull_request'}}
+    steps:
+      - id: metadata
+        uses: dependabot/fetch-metadata@v2
+        with:
+          github-token: "${{ secrets.GITHUB_TOKEN }}"
+      - run: |
+          gh pr review --approve "$PR_URL"
+          gh pr merge --squash --auto "$PR_URL"
+        env:
+          PR_URL: ${{github.event.pull_request.html_url}}
+          GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
+
+  lint:
+    uses: charmbracelet/meta/.github/workflows/lint.yml@main
+    with:
+      directory: ./ai/...
+      golangci_path: .golangci.yml
+

.github/workflows/anthropic.yml 🔗

@@ -0,0 +1,56 @@
+# auto-generated by scripts/builds. DO NOT EDIT.
+name: anthropic
+
+on:
+  push:
+    branches:
+      - main
+  pull_request:
+    paths:
+      - providers/anthropic/**
+      - .github/workflows/anthropic.yml
+
+jobs:
+  build:
+    strategy:
+      matrix:
+        os: [ubuntu-latest, macos-latest, windows-latest]
+    runs-on: ${{ matrix.os }}
+    defaults:
+      run:
+        working-directory: ./providers/anthropic
+    steps:
+      - uses: actions/checkout@v4
+      - uses: actions/setup-go@v5
+        with:
+          go-version-file: ./providers/anthropic/go.mod
+          cache: true
+          cache-dependency-path: ./providers/anthropic/go.sum
+      - run: go build -v ./...
+      - run: go test -race -v ./...
+
+  dependabot:
+    needs: [build]
+    runs-on: ubuntu-latest
+    permissions:
+      pull-requests: write
+      contents: write
+    if: ${{ github.actor == 'dependabot[bot]' && github.event_name == 'pull_request'}}
+    steps:
+      - id: metadata
+        uses: dependabot/fetch-metadata@v2
+        with:
+          github-token: "${{ secrets.GITHUB_TOKEN }}"
+      - run: |
+          gh pr review --approve "$PR_URL"
+          gh pr merge --squash --auto "$PR_URL"
+        env:
+          PR_URL: ${{github.event.pull_request.html_url}}
+          GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
+
+  lint:
+    uses: charmbracelet/meta/.github/workflows/lint.yml@main
+    with:
+      directory: ./providers/anthropic/...
+      golangci_path: .golangci.yml
+

.github/workflows/build.yml 🔗

@@ -1,11 +0,0 @@
-name: build
-on: [push, pull_request]
-
-jobs:
-  build:
-    uses: charmbracelet/meta/.github/workflows/build.yml@main
-    with:
-      go-version: ""
-      go-version-file: ./go.mod
-    secrets:
-      gh_pat: "${{ secrets.PERSONAL_ACCESS_TOKEN }}"

.github/workflows/examples.yml 🔗

@@ -0,0 +1,56 @@
+# auto-generated by scripts/builds. DO NOT EDIT.
+name: examples
+
+on:
+  push:
+    branches:
+      - main
+  pull_request:
+    paths:
+      - examples/**
+      - .github/workflows/examples.yml
+
+jobs:
+  build:
+    strategy:
+      matrix:
+        os: [ubuntu-latest, macos-latest, windows-latest]
+    runs-on: ${{ matrix.os }}
+    defaults:
+      run:
+        working-directory: ./examples
+    steps:
+      - uses: actions/checkout@v4
+      - uses: actions/setup-go@v5
+        with:
+          go-version-file: ./examples/go.mod
+          cache: true
+          cache-dependency-path: ./examples/go.sum
+      - run: go build -v ./...
+      - run: go test -race -v ./...
+
+  dependabot:
+    needs: [build]
+    runs-on: ubuntu-latest
+    permissions:
+      pull-requests: write
+      contents: write
+    if: ${{ github.actor == 'dependabot[bot]' && github.event_name == 'pull_request'}}
+    steps:
+      - id: metadata
+        uses: dependabot/fetch-metadata@v2
+        with:
+          github-token: "${{ secrets.GITHUB_TOKEN }}"
+      - run: |
+          gh pr review --approve "$PR_URL"
+          gh pr merge --squash --auto "$PR_URL"
+        env:
+          PR_URL: ${{github.event.pull_request.html_url}}
+          GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
+
+  lint:
+    uses: charmbracelet/meta/.github/workflows/lint.yml@main
+    with:
+      directory: ./examples/...
+      golangci_path: .golangci.yml
+

.github/workflows/lint.yml 🔗

@@ -1,11 +0,0 @@
-name: lint
-on:
-  push:
-  pull_request:
-
-jobs:
-  lint:
-    uses: charmbracelet/meta/.github/workflows/lint.yml@main
-    with:
-      golangci_path: .golangci.yml
-      timeout: 10m

.github/workflows/openai.yml 🔗

@@ -0,0 +1,56 @@
+# auto-generated by scripts/builds. DO NOT EDIT.
+name: openai
+
+on:
+  push:
+    branches:
+      - main
+  pull_request:
+    paths:
+      - providers/openai/**
+      - .github/workflows/openai.yml
+
+jobs:
+  build:
+    strategy:
+      matrix:
+        os: [ubuntu-latest, macos-latest, windows-latest]
+    runs-on: ${{ matrix.os }}
+    defaults:
+      run:
+        working-directory: ./providers/openai
+    steps:
+      - uses: actions/checkout@v4
+      - uses: actions/setup-go@v5
+        with:
+          go-version-file: ./providers/openai/go.mod
+          cache: true
+          cache-dependency-path: ./providers/openai/go.sum
+      - run: go build -v ./...
+      - run: go test -race -v ./...
+
+  dependabot:
+    needs: [build]
+    runs-on: ubuntu-latest
+    permissions:
+      pull-requests: write
+      contents: write
+    if: ${{ github.actor == 'dependabot[bot]' && github.event_name == 'pull_request'}}
+    steps:
+      - id: metadata
+        uses: dependabot/fetch-metadata@v2
+        with:
+          github-token: "${{ secrets.GITHUB_TOKEN }}"
+      - run: |
+          gh pr review --approve "$PR_URL"
+          gh pr merge --squash --auto "$PR_URL"
+        env:
+          PR_URL: ${{github.event.pull_request.html_url}}
+          GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
+
+  lint:
+    uses: charmbracelet/meta/.github/workflows/lint.yml@main
+    with:
+      directory: ./providers/openai/...
+      golangci_path: .golangci.yml
+

scripts/generate_ci 🔗

@@ -0,0 +1,71 @@
+#!/usr/bin/env bash
+
+# shellcheck disable=SC2016
+find . -type f -name go.mod | sort | while read -r mod; do
+  dir="$(dirname "$mod")"
+  name="$(basename "$dir")"
+  # get the parent directory when the module is nested semver-style
+  if [[ "$name" =~ ^v[0-9]+.*$ ]]; then
+    ver="$(basename "$dir")"
+    dir="$(dirname "$dir")"
+    name="$(basename "$dir")-$ver"
+  fi
+
+  sum="$dir/go.sum"
+  echo "# auto-generated by scripts/builds. DO NOT EDIT.
+name: $name
+
+on:
+  push:
+    branches:
+      - main
+  pull_request:
+    paths:
+      - $(dirname "$mod" | cut -f2- -d/)/**
+      - .github/workflows/${name}.yml
+
+jobs:
+  build:
+    strategy:
+      matrix:
+        os: [ubuntu-latest, macos-latest, windows-latest]
+    runs-on: \${{ matrix.os }}
+    defaults:
+      run:
+        working-directory: $(dirname "$mod")
+    steps:
+      - uses: actions/checkout@v4
+      - uses: actions/setup-go@v5
+        with:
+          go-version-file: $mod
+          cache: true
+          cache-dependency-path: $sum
+      - run: go build -v ./...
+      - run: go test -race -v ./...
+
+  dependabot:
+    needs: [build]
+    runs-on: ubuntu-latest
+    permissions:
+      pull-requests: write
+      contents: write
+    if: \${{ github.actor == 'dependabot[bot]' && github.event_name == 'pull_request'}}
+    steps:
+      - id: metadata
+        uses: dependabot/fetch-metadata@v2
+        with:
+          github-token: \"\${{ secrets.GITHUB_TOKEN }}\"
+      - run: |
+          gh pr review --approve \"\$PR_URL\"
+          gh pr merge --squash --auto \"\$PR_URL\"
+        env:
+          PR_URL: \${{github.event.pull_request.html_url}}
+          GITHUB_TOKEN: \${{secrets.GITHUB_TOKEN}}
+
+  lint:
+    uses: charmbracelet/meta/.github/workflows/lint.yml@main
+    with:
+      directory: $(dirname "$mod")/...
+      golangci_path: .golangci.yml
+" >"./.github/workflows/${name}.yml"
+done