Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
This code is extracted from
cockroachdb/replicator@1f15b0d
with some minor API cleanups.
  • Loading branch information
bobvawter committed May 28, 2024
0 parents commit ad759f3
Show file tree
Hide file tree
Showing 19 changed files with 2,848 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .github/codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2023 The Cockroach Authors
#
# 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.
#
# SPDX-License-Identifier: Apache-2.0

github_checks:
annotations: true
ignore:
- '**/wire_gen.go' # Most error callbacks are unused.
- '**/*_string.go' # Strings are for debugging use only.
33 changes: 33 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright 2023 The Cockroach Authors
#
# 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.
#
# SPDX-License-Identifier: Apache-2.0

# Enable automatic version updates.
# https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
commit-message:
prefix: "actions"

- package-ecosystem: "gomod"
directory: "/"
schedule:
interval: "weekly"
commit-message:
prefix: "gomod"
49 changes: 49 additions & 0 deletions .github/workflows/go-codeql.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Copyright 2023 The Cockroach Authors
#
# 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.
#
# SPDX-License-Identifier: Apache-2.0

# Run GitHub CodeQL sanity-checks.
name: Golang CodeQL
permissions:
contents: read
security-events: write
on:
workflow_call:
workflow_dispatch:
jobs:
codeql:
name: CodeQL security scanning
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'

- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: go
queries: security-and-quality

- name: Autobuild
uses: github/codeql-action/autobuild@v3

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: "/language:go"
101 changes: 101 additions & 0 deletions .github/workflows/go-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# Copyright 2023 The Cockroach Authors
#
# 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.
#
# SPDX-License-Identifier: Apache-2.0

name: Golang Tests
permissions:
contents: read
packages: read
on:
workflow_call:
workflow_dispatch:
jobs:
# Static code-quality checks.
code-quality:
name: Code Quality
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'

- name: crlfmt returns no deltas
if: ${{ !cancelled() }}
run: |
DELTA=$(go run github.com/cockroachdb/crlfmt -ignore _gen.go .)
echo $DELTA
test -z "$DELTA"
- name: Copyright headers
if: ${{ !cancelled() }}
run: go run github.com/google/addlicense -c "The Cockroach Authors" -l apache -s -v -check -ignore '**/testdata/**/*.sql' .

- name: Lint
if: ${{ !cancelled() }}
run: go run golang.org/x/lint/golint -set_exit_status ./...

- name: Static checks
if: ${{ !cancelled() }}
run: go run honnef.co/go/tools/cmd/staticcheck -checks all ./...

- name: Go Vet
if: ${{ !cancelled() }}
run: go vet ./...

# Check that all dependencies have licenses and that those
# licenses are reasonably permissive. License files for modules
# reachable from the entry point will be bundled and are visible
# through the licenses subcommand.
- name: License Checks
if: ${{ !cancelled() }}
run: go run github.com/google/go-licenses check .

tests:
name: Go Tests
runs-on: ubuntu-latest
timeout-minutes: 10

env:
COVER_OUT: coverage.out
TEST_OUT: go-test.json
steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'

- name: Go Tests
run: >
go test
-count 1
-coverpkg=./internal/...
-covermode=atomic
-coverprofile=${{ env.COVER_OUT }}
-race
-tags target_all
-v
./...
- name: Upload coverage
uses: codecov/codecov-action@v4
continue-on-error: true # Sometimes CodeCov has a bad day.
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ${{ env.COVER_OUT }}
53 changes: 53 additions & 0 deletions .github/workflows/go.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Copyright 2023 The Cockroach Authors
#
# 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.
#
# SPDX-License-Identifier: Apache-2.0

# This is our top-level workflow that kicks off the various go- workflows.
name: Golang
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
on:
# Since we use the merge queue to push and there are no observable
# side-effects of running a test-only workflow, we don't respond to
# push events.
merge_group: # Enable merge queue
pull_request:
paths:
- 'go.mod'
- 'go.sum'
- '**/*.go'
- '.github/workflows/go*.yaml'
push:
branches: [ main ]
tags: [ 'v*.*.*' ]
jobs:
go-codeql:
uses: ./.github/workflows/go-codeql.yaml
permissions:
contents: read
security-events: write
secrets: inherit

go-tests:
uses: ./.github/workflows/go-tests.yaml
# We use the merge queue prior to pushing to a branch, so there's no
# reason to repeat tests that just ran.
if: ${{ github.event_name != 'push' }}
permissions:
contents: read
packages: read
statuses: write
secrets: inherit
27 changes: 27 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
cdc-sink
replicator

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

# CockroachDB data directory
cockroach-data/
goroutine_dump/
heap_profiler/

# Package working directory
upload/

go.work
Loading

0 comments on commit ad759f3

Please sign in to comment.