diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..b1ac79d --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,27 @@ +# Copyright 2021 Yahoo. +# +# 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. + +version: 2 +updates: +- package-ecosystem: "gomod" + directory: "/" + schedule: + interval: "daily" + open-pull-requests-limit: 10 + +- package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "daily" + open-pull-requests-limit: 10 diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml new file mode 100644 index 0000000..7193f4c --- /dev/null +++ b/.github/workflows/codeql-analysis.yml @@ -0,0 +1,65 @@ +# Copyright 2021 Yahoo. +# +# 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: "CodeQL" + +on: + push: + branches: [ main ] + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + language: [ 'go' ] + # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ] + # Learn more: + # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v1 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + # queries: ./path/to/local/query, your-org/your-repo/queries@main + + # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v1 + + # ℹī¸ Command-line programs to run using the OS shell. + # 📚 https://git.io/JvXDl + + # ✏ī¸ If the Autobuild fails above, remove it and uncomment the following three lines + # and modify them (or add more) to build your code if your project + # uses a compiled language + + #- run: | + # make bootstrap + # make release + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v1 diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml new file mode 100644 index 0000000..b92fc3d --- /dev/null +++ b/.github/workflows/golangci-lint.yml @@ -0,0 +1,29 @@ +# Copyright 2021 Yahoo. +# +# 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: golangci-lint +on: + push: + branches: + - main + pull_request: + +jobs: + golangci: + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: golangci-lint + uses: golangci/golangci-lint-action@v2 diff --git a/.github/workflows/license.yml b/.github/workflows/license.yml new file mode 100644 index 0000000..486cc8b --- /dev/null +++ b/.github/workflows/license.yml @@ -0,0 +1,39 @@ +# Copyright 2021 Yahoo. +# +# 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: license + +on: + push: + branches: + - main + pull_request: + +jobs: + license-check: + runs-on: ubuntu-latest + steps: + - name: Setup Go + uses: actions/setup-go@v2 + with: + go-version: 1.17.0 + - name: checkout + uses: actions/checkout@v2 + - name: Install addlicense + run: go install github.com/google/addlicense@latest + - name: Check license headers + run: | + set -e + addlicense -l apache -c 'Yahoo.' -v * + git diff --exit-code diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml new file mode 100644 index 0000000..54f9ef1 --- /dev/null +++ b/.github/workflows/linux.yml @@ -0,0 +1,67 @@ +# Copyright 2021 Yahoo. +# +# 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: Linux + +on: + push: + branches: + - main + pull_request: + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + go: [ '1.16.x', '1.17.0' ] + name: Go ${{ matrix.go }} build + steps: + - name: checkout + uses: actions/checkout@v2 + + # https://github.com/mvdan/github-actions-golang#how-do-i-set-up-caching-between-builds + - uses: actions/cache@v2 + with: + # In order: + # * Module download cache + # * Build cache (Linux) + path: | + ~/go/pkg/mod + ~/.cache/go-build + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Setup go + uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.go }} + + - name: go vet + run: go vet -v ./... + + - name: Basic build + run: go build ./... + + - name: Run tests on linux + run: go test ./... + + - name: Run tests with race detector + run: go test -v -race -coverprofile=coverage.txt -covermode=atomic ./... + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v2.1.0 + with: + file: ./coverage.txt diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..31a77b7 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,61 @@ +# Copyright 2021 Yahoo. +# +# 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: create release and upload binary + +on: + push: + tags: + - 'v[0-9]+.[0-9]+.[0-9]+' + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v2 + + - name: install go + uses: actions/setup-go@v2 + with: + go-version: 1.17.0 + + - name: get version + id: v + run: echo ::set-output name=tag::$( awk -F '/' '{print $NF}' <<< "${GITHUB_REF}" ) + + - name: package + run: | + tar -czvf grafeas-rds-${{ steps.v.outputs.tag }}-linux.tar.gz . + + - name: create release + id: create-release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ steps.v.outputs.tag }} + release_name: ${{ steps.v.outputs.tag }} + draft: false + prerelease: false + + - name: upload linux binary + uses: actions/upload-release-asset@v1.0.2 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create-release.outputs.upload_url }} + asset_path: grafeas-rds-${{ steps.v.outputs.tag }}-linux.tar.gz + asset_name: grafeas-rds-${{ steps.v.outputs.tag }}-linux.tar.gz + asset_content_type: application/gzip diff --git a/rds/connector_test.go b/rds/connector_test.go index 155a48b..e04c312 100644 --- a/rds/connector_test.go +++ b/rds/connector_test.go @@ -97,7 +97,10 @@ func TestConnectorConnect(t *testing.T) { driver: mockDriver, } mockDriver.EXPECT().Open(c.dsn).Times(1) - c.Connect(context.Background()) + _, err := c.Connect(context.Background()) + if err != nil { + t.Fatal(err) + } } func TestConnectorDriver(t *testing.T) {