diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000000..e48f462c00 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1,6 @@ +# This file controls who is tagged for review for any given pull request. +# +# For syntax help see: +# https://help.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners#codeowners-syntax + +* @googleapis/senseai-eco diff --git a/.github/header-checker-lint.yaml b/.github/header-checker-lint.yaml new file mode 100644 index 0000000000..5e14571cce --- /dev/null +++ b/.github/header-checker-lint.yaml @@ -0,0 +1,22 @@ +# Copyright 2024 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +allowedCopyrightHolders: + - 'Google LLC' +allowedLicenses: + - 'Apache-2.0' +sourceFileExtensions: + - 'go' + - 'yaml' + - 'yml' diff --git a/.github/labels.yaml b/.github/labels.yaml new file mode 100644 index 0000000000..e26ccc3cbe --- /dev/null +++ b/.github/labels.yaml @@ -0,0 +1,70 @@ +# Copyright 2024 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +- name: duplicate + color: ededed + description: "" + +- name: 'type: bug' + color: db4437 + description: Error or flaw in code with unintended results or allowing sub-optimal + usage patterns. +- name: 'type: cleanup' + color: c5def5 + description: An internal cleanup or hygiene concern. +- name: 'type: docs' + color: 0000A0 + description: Improvement to the documentation for an API. +- name: 'type: feature request' + color: c5def5 + description: ‘Nice-to-have’ improvement, new feature or different behavior or design. +- name: 'type: process' + color: c5def5 + description: A process-related concern. May include testing, release, or the like. +- name: 'type: question' + color: c5def5 + description: Request for information or clarification. + +- name: 'priority: p0' + color: b60205 + description: Highest priority. Critical issue. P0 implies highest priority. +- name: 'priority: p1' + color: ffa03e + description: Important issue which blocks shipping the next release. Will be fixed + prior to next release. +- name: 'priority: p2' + color: fef2c0 + description: Moderately-important priority. Fix may not be included in next release. +- name: 'priority: p3' + color: ffffc7 + description: Desirable enhancement or fix. May not be included in next release. + +- name: do not merge + color: d93f0b + description: Indicates a pull request not ready for merge, due to either quality + or timing. + +- name: 'autorelease: pending' + color: ededed + description: Release please needs to do its work on this. +- name: 'autorelease: triggered' + color: ededed + description: Release please has triggered a release for this. +- name: 'autorelease: tagged' + color: ededed + description: Release please has completed a release for this. + +- name: 'tests: run' + color: 3DED97 + description: Label to trigger Github Action tests. diff --git a/.github/sync-repo-settings.yaml b/.github/sync-repo-settings.yaml new file mode 100644 index 0000000000..58170706da --- /dev/null +++ b/.github/sync-repo-settings.yaml @@ -0,0 +1,41 @@ +# Copyright 2024 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Synchronize repository settings from a centralized config +# https://github.com/googleapis/repo-automation-bots/tree/main/packages/sync-repo-settings +# Install: https://github.com/apps/sync-repo-settings + +# Disable merge commits +rebaseMergeAllowed: true +squashMergeAllowed: true +mergeCommitAllowed: false +# Enable branch protection +branchProtectionRules: + - pattern: main + isAdminEnforced: true + requiredStatusCheckContexts: + - "cla/google" + - "lint" + - "conventionalcommits.org" + - "header-check" + # - Add required status checks like presubmit tests + - "integration tests (ubuntu-latest)" + requiredApprovingReviewCount: 1 + requiresCodeOwnerReviews: true + requiresStrictStatusChecks: true + +# Set team access +permissionRules: + - team: senseai-eco + permission: admin diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml new file mode 100644 index 0000000000..6af4e889af --- /dev/null +++ b/.github/workflows/lint.yaml @@ -0,0 +1,73 @@ +# Copyright 2024 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +name: lint +on: + pull_request: + pull_request_target: + types: [labeled] + +# Declare default permissions as read only. +permissions: read-all + +jobs: + lint: + if: "${{ github.event.action != 'labeled' || github.event.label.name == 'tests: run' }}" + name: run lint + runs-on: ubuntu-latest + concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + permissions: + contents: 'read' + id-token: 'write' + issues: write + pull-requests: write + steps: + - name: Remove PR Label + if: "${{ github.event.action == 'labeled' && github.event.label.name == 'tests: run' }}" + uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + try { + await github.rest.issues.removeLabel({ + name: 'tests: run', + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.payload.pull_request.number + }); + } catch (e) { + console.log('Failed to remove label. Another job may have already removed it!'); + } + - name: Setup Go + uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1 + with: + go-version: "1.22" + - name: Checkout code + uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6 + with: + ref: ${{ github.event.pull_request.head.sha }} + repository: ${{ github.event.pull_request.head.repo.full_name }} + token: ${{ secrets.GITHUB_TOKEN }} + - name: > + Verify go mod tidy. If you're reading this and the check has + failed, run `goimports -w . && go mod tidy && golangci-lint run` + run: | + go mod tidy && git diff --exit-code + - name: golangci-lint + uses: golangci/golangci-lint-action@a4f60bb28d35aeee14e6880718e0c85ff1882e64 # v6.0.1 + with: + version: latest + args: --timeout 3m diff --git a/.github/workflows/sync-labels.yaml b/.github/workflows/sync-labels.yaml new file mode 100644 index 0000000000..b2b4d3b4ac --- /dev/null +++ b/.github/workflows/sync-labels.yaml @@ -0,0 +1,34 @@ +# Copyright 2024 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +name: Sync Labels +on: + push: + branches: + - main + +# Declare default permissions as read only. +permissions: read-all + +jobs: + build: + runs-on: ubuntu-latest + permissions: + issues: write + pull-requests: write + steps: + - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6 + - uses: micnncim/action-label-syncer@3abd5ab72fda571e69fffd97bd4e0033dd5f495c # v1.3.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml new file mode 100644 index 0000000000..749a455360 --- /dev/null +++ b/.github/workflows/tests.yaml @@ -0,0 +1,80 @@ +# Copyright 2024 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +name: tests +on: + push: + branches: + - 'main' + pull_request: + pull_request_target: + types: [labeled] + +# Declare default permissions as read only. +permissions: read-all + +jobs: + integration: + # run job on proper workflow event triggers (skip job for pull_request event from forks and only run pull_request_target for "tests: run" label) + if: "${{ (github.event.action != 'labeled' && github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name) || github.event.label.name == 'tests: run' }}" + name: integration tests + runs-on: ${{ matrix.os }} + strategy: + matrix: + # os: [macos-latest, windows-latest, ubuntu-latest] + os: [ubuntu-latest] + fail-fast: false + permissions: + contents: 'read' + id-token: 'write' + issues: write + pull-requests: write + steps: + - name: Remove PR label + if: "${{ github.event.action == 'labeled' && github.event.label.name == 'tests: run' }}" + uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + try { + await github.rest.issues.removeLabel({ + name: 'tests: run', + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.payload.pull_request.number + }); + } catch (e) { + console.log('Failed to remove label. Another job may have already removed it!'); + } + + - name: Setup Go + uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1 + with: + go-version: "1.22" + + - name: Checkout code + uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6 + with: + ref: ${{ github.event.pull_request.head.sha }} + repository: ${{ github.event.pull_request.head.repo.full_name }} + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Install dependencies + run: go get . + + - name: Build + run: go build -v ./... + + - name: Run tests + run: go test -race -v ./... diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000..5c2b98ff5a --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +# vscode +.vscode/ diff --git a/.golangci.yaml b/.golangci.yaml new file mode 100644 index 0000000000..b9fedead83 --- /dev/null +++ b/.golangci.yaml @@ -0,0 +1,32 @@ +# Copyright 2024 Google LLC. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +linters: + enable: + - errcheck + - goimports + - gosimple + - govet + - ineffassign + - staticcheck + - unused +linters-settings: + gofmt: + rewrite-rules: + - pattern: 'interface{}' + replacement: 'any' + - pattern: 'a[b:len(a)]' + replacement: 'a[b:]' +issues: + fix: true diff --git a/go.mod b/go.mod index 399fd86533..7cc7267b6a 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ -module toolbox +module github.com/googleapis/genai-toolbox go 1.22.2 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000000..e69de29bb2 diff --git a/main.go b/main.go index 5d434c735e..ed1b5c43d0 100644 --- a/main.go +++ b/main.go @@ -17,5 +17,5 @@ package main import "fmt" func main() { - fmt.Println("hello world") -} \ No newline at end of file + fmt.Println("hello world") +}