From 5337bf2f4b13ddd6956095c75c00456d15c13bf8 Mon Sep 17 00:00:00 2001 From: Andrey Nering Date: Tue, 2 Sep 2025 17:56:27 -0300 Subject: [PATCH] ci: configure workflows to be package-by-package Copied generate script from `charmbracelet/x`. --- .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(-) create mode 100644 .github/workflows/ai.yml create mode 100644 .github/workflows/anthropic.yml delete mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/lint.yml create mode 100644 .github/workflows/openai.yml create mode 100755 scripts/generate_ci diff --git a/.github/workflows/ai.yml b/.github/workflows/ai.yml new file mode 100644 index 0000000000000000000000000000000000000000..1455e8b69467a03fd1c17baeb18e28fb7eab6808 --- /dev/null +++ b/.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 + diff --git a/.github/workflows/anthropic.yml b/.github/workflows/anthropic.yml new file mode 100644 index 0000000000000000000000000000000000000000..7779163ce444fb0bd0909ce209047b96497fa90c --- /dev/null +++ b/.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 + diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index 3511f7fe0c4f487eb3fc9009795361ada8e2eff7..0000000000000000000000000000000000000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -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 }}" diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml new file mode 100644 index 0000000000000000000000000000000000000000..273aa481f0d0b27c0295ab8ad54334c6e43b54f3 --- /dev/null +++ b/.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 + diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml deleted file mode 100644 index 1ffad5f2f7da7042b6a2217043b48aefeb5a68ff..0000000000000000000000000000000000000000 --- a/.github/workflows/lint.yml +++ /dev/null @@ -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 diff --git a/.github/workflows/openai.yml b/.github/workflows/openai.yml new file mode 100644 index 0000000000000000000000000000000000000000..5aa12b2904173a45bb32b9b0840b123d5bffe2d7 --- /dev/null +++ b/.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 + diff --git a/scripts/generate_ci b/scripts/generate_ci new file mode 100755 index 0000000000000000000000000000000000000000..b74c6542acc21d19756a2e09951591958fb7b3c9 --- /dev/null +++ b/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