diff --git a/.github/workflows/go-test.yml b/.github/workflows/go-test.yml index 5e10425..cff7839 100644 --- a/.github/workflows/go-test.yml +++ b/.github/workflows/go-test.yml @@ -1,40 +1,44 @@ name: Go Tests on: - push: - branches: [main] - pull_request: + push: + branches: [main] + pull_request: jobs: - test: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - - name: Set up Go - uses: actions/setup-go@v5 - with: - go-version: "stable" - - - name: Test - run: CGO_ENABLED=0 go test -count=1 -v ./... - - lint: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - - name: Set up Go - uses: actions/setup-go@v5 - with: - go-version: "stable" - - - name: golangci-lint - uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0 - with: - version: v2.1 - - - name: Check for unstaged changes - run: | - make gen - ./check_unstaged.sh + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: "stable" + + - name: Test + run: CGO_ENABLED=0 go test -count=1 -v ./... + + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: "stable" + + - name: Set up Bun + uses: oven-sh/setup-bun@v2 + + - name: Install Chat Dependencies + run: cd chat && bun install + + - name: run linters + run: make lint + + - name: Check for unstaged changes + run: | + make gen + ./check_unstaged.sh diff --git a/.github/workflows/pr-preview-release.yml b/.github/workflows/pr-preview-release.yml index 400b862..7a200b2 100644 --- a/.github/workflows/pr-preview-release.yml +++ b/.github/workflows/pr-preview-release.yml @@ -1,70 +1,69 @@ name: PR Preview Release on: - workflow_run: - workflows: ["PR Preview Build"] - types: - - completed + workflow_run: + workflows: ["PR Preview Build"] + types: + - completed permissions: - contents: write - pull-requests: write + contents: write + pull-requests: write jobs: - release: - name: Create Release - runs-on: ubuntu-latest - if: ${{ github.event.workflow_run.conclusion == 'success' }} + release: + name: Create Release + runs-on: ubuntu-latest + if: ${{ github.event.workflow_run.conclusion == 'success' }} - steps: - - name: Download PR number - uses: actions/download-artifact@v4 - with: - name: pr-number - github-token: ${{ secrets.GITHUB_TOKEN }} - run-id: ${{ github.event.workflow_run.id }} + steps: + - name: Download PR number + uses: actions/download-artifact@v4 + with: + name: pr-number + github-token: ${{ secrets.GITHUB_TOKEN }} + run-id: ${{ github.event.workflow_run.id }} - - name: Read PR number - id: pr - run: echo "number=$(cat number)" >> $GITHUB_OUTPUT + - name: Read PR number + id: pr + run: echo "number=$(cat number)" >> "${GITHUB_OUTPUT}" - - name: Download Build Artifacts - uses: actions/download-artifact@v4 - with: - name: agentapi-build-${{ steps.pr.outputs.number }} - path: ./out - github-token: ${{ secrets.GITHUB_TOKEN }} - run-id: ${{ github.event.workflow_run.id }} + - name: Download Build Artifacts + uses: actions/download-artifact@v4 + with: + name: agentapi-build-${{ steps.pr.outputs.number }} + path: ./out + github-token: ${{ secrets.GITHUB_TOKEN }} + run-id: ${{ github.event.workflow_run.id }} + - name: Create or Update PR Release + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + RELEASE_TAG: "agentapi_${{ steps.pr.outputs.number }}" + PR_NUMBER: ${{ steps.pr.outputs.number }} - - name: Create or Update PR Release - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - RELEASE_TAG: 'agentapi_${{ steps.pr.outputs.number }}' - PR_NUMBER: ${{ steps.pr.outputs.number }} + run: | + # Check if release exists + if gh release view "$RELEASE_TAG" --repo ${{ github.repository }} &>/dev/null; then + echo "Updating release $RELEASE_TAG" + gh release upload "$RELEASE_TAG" ./out/* --clobber --repo ${{ github.repository }} + else + echo "Creating release $RELEASE_TAG" + gh release create "$RELEASE_TAG" ./out/* \ + --title "$RELEASE_TAG" \ + --notes "Preview release for PR #${PR_NUMBER}" \ + --repo ${{ github.repository }} + fi - run: | - # Check if release exists - if gh release view "$RELEASE_TAG" --repo ${{ github.repository }} &>/dev/null; then - echo "Updating release $RELEASE_TAG" - gh release upload "$RELEASE_TAG" ./out/* --clobber --repo ${{ github.repository }} - else - echo "Creating release $RELEASE_TAG" - gh release create "$RELEASE_TAG" ./out/* \ - --title "$RELEASE_TAG" \ - --notes "Preview release for PR #${PR_NUMBER}" \ - --repo ${{ github.repository }} - fi - - - name: Comment on PR - uses: actions/github-script@v7 - with: - script: | - const prNumber = ${{ steps.pr.outputs.number }}; - const releaseTag = `agentapi_${prNumber}`; - github.rest.issues.createComment({ - issue_number: prNumber, - owner: context.repo.owner, - repo: context.repo.repo, - body: `✅ Preview binaries are ready!\n\nTo test with modules: \`\`\`agentapi: ${prNumber}\`\`\` or download from: ${repoUrl}/releases/tag/${releaseTag}` - }); \ No newline at end of file + - name: Comment on PR + uses: actions/github-script@v7 + with: + script: | + const prNumber = ${{ steps.pr.outputs.number }}; + const releaseTag = `agentapi_${prNumber}`; + github.rest.issues.createComment({ + issue_number: prNumber, + owner: context.repo.owner, + repo: context.repo.repo, + body: `✅ Preview binaries are ready!\n\nTo test with modules: \`\`\`agentapi: ${prNumber}\`\`\` or download from: ${repoUrl}/releases/tag/${releaseTag}` + }); diff --git a/Makefile b/Makefile index 97d78c2..800a38c 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,9 @@ CHAT_SOURCES = $(shell find chat \( -path chat/node_modules -o -path chat/out -o BINPATH ?= out/agentapi # This must be kept in sync with the magicBasePath in lib/httpapi/embed.go. BASE_PATH ?= /magic-base-path-placeholder +FIND_EXCLUSIONS= \ + -not \( \( -path '*/.git/*' -o -path './out/*' -o -path '*/node_modules/*' -o -path '*/.terraform/*' \) -prune \) +SHELL_SRC_FILES := $(shell find . $(FIND_EXCLUSIONS) -type f -name '*.sh') $(CHAT_SOURCES_STAMP): $(CHAT_SOURCES) @echo "Chat sources changed. Running build steps..." @@ -22,3 +25,24 @@ build: embed .PHONY: gen gen: go generate ./... + +lint: lint/shellcheck lint/go lint/ts lint/actions/actionlint +.PHONY: lint + +lint/go: + go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.5.0 run + go run github.com/coder/paralleltestctx/cmd/paralleltestctx@v0.0.1 ./... +.PHONY: lint/go + +lint/shellcheck: $(SHELL_SRC_FILES) + echo "--- shellcheck" + shellcheck --external-sources $(SHELL_SRC_FILES) +.PHONY: lint/shellcheck + +lint/ts: + cd ./chat && bun lint +.PHONY: lint/ts + +lint/actions/actionlint: + go run github.com/rhysd/actionlint/cmd/actionlint@v1.7.7 --config-file actionlint.yaml +.PHONY: lint/actions/actionlint diff --git a/actionlint.yaml b/actionlint.yaml new file mode 100644 index 0000000..22f02af --- /dev/null +++ b/actionlint.yaml @@ -0,0 +1,5 @@ +# Configuration related to self-hosted runner. +self-hosted-runner: + # Labels of self-hosted runner in array of strings. + labels: + - depot-ubuntu-22.04-4