-
Notifications
You must be signed in to change notification settings - Fork 891
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:mongodb/mongo-go-driver into GODR…
- Loading branch information
Showing
36 changed files
with
1,779 additions
and
563 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
name: PR API Report | ||
on: | ||
pull_request_target: | ||
|
||
jobs: | ||
comment: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
pull-requests: write | ||
issues: write | ||
steps: | ||
- uses: actions/setup-go@v4 | ||
- name: Find Comment | ||
uses: peter-evans/find-comment@v2 | ||
id: fc | ||
with: | ||
issue-number: ${{ github.event.pull_request.number }} | ||
comment-author: 'github-actions[bot]' | ||
body-includes: "## API Change Report" | ||
|
||
- name: Create the comment body | ||
run: | | ||
set -eux | ||
git clone https://github.com/mongodb/mongo-go-driver | ||
cd mongo-go-driver | ||
git remote add source https://github.com/$GITHUB_ACTOR/mongo-go-driver | ||
git fetch origin $GITHUB_BASE_REF | ||
git fetch source $GITHUB_HEAD_REF | ||
git checkout $GITHUB_HEAD_REF | ||
make api-report | ||
cat api-report.md | ||
- name: Create or update comment | ||
uses: peter-evans/create-or-update-comment@v3 | ||
with: | ||
comment-id: ${{ steps.fc.outputs.comment-id }} | ||
issue-number: ${{ github.event.pull_request.number }} | ||
body-path: 'mongo-go-driver/api-report.md' | ||
edit-mode: replace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Copyright (C) MongoDB, Inc. 2023-present. | ||
// | ||
// 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 | ||
|
||
package main | ||
|
||
import ( | ||
"bufio" | ||
"fmt" | ||
"log" | ||
"os" | ||
"strings" | ||
) | ||
|
||
func main() { | ||
var line string | ||
var suppress bool | ||
var foundChange = false | ||
var foundSummary = false | ||
|
||
// open file to read | ||
fRead, err := os.Open("api-report.txt") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
// remember to close the file at the end of the program | ||
defer fRead.Close() | ||
|
||
// open file to write | ||
fWrite, err := os.Create("api-report.md") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
// remember to close the file at the end of the program | ||
defer fWrite.Close() | ||
|
||
fmt.Fprint(fWrite, "## API Change Report\n") | ||
|
||
// read the file line by line using scanner | ||
scanner := bufio.NewScanner(fRead) | ||
|
||
for scanner.Scan() { | ||
// do something with a line | ||
line = scanner.Text() | ||
if strings.Index(line, "## ") == 0 { | ||
line = "##" + line | ||
} | ||
|
||
if strings.Contains(line, "/mongo/integration/") { | ||
suppress = true | ||
} | ||
if strings.Index(line, "# summary") == 0 { | ||
suppress = true | ||
foundSummary = true | ||
} | ||
|
||
if strings.Contains(line, "go.mongodb.org/mongo-driver") { | ||
line = strings.Replace(line, "go.mongodb.org/mongo-driver", ".", -1) | ||
line = "##" + line | ||
} | ||
if !suppress { | ||
fmt.Fprintf(fWrite, "%s\n", line) | ||
foundChange = true | ||
} | ||
if len(line) == 0 { | ||
suppress = false | ||
} | ||
} | ||
|
||
if !foundChange { | ||
fmt.Fprint(fWrite, "No changes found!\n") | ||
} | ||
|
||
if !foundSummary { | ||
log.Fatal("Could not parse api summary") | ||
} | ||
|
||
if err := scanner.Err(); err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/usr/bin/env bash | ||
# api-report | ||
# Generates a report of Go Driver API changes for the current branch. | ||
set -eux | ||
|
||
cmd=$(command -v gorelease || true) | ||
|
||
if [ -z $cmd ]; then | ||
go install golang.org/x/exp/cmd/gorelease@latest | ||
fi | ||
|
||
branch=${GITHUB_BASE_REF:-master} | ||
sha=$(git merge-base $branch HEAD) | ||
|
||
gorelease -base=$sha > api-report.txt || true | ||
|
||
go run ./cmd/parse-api-report/main.go | ||
|
||
rm api-report.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
// Copied from https://cs.opensource.google/go/x/exp/+/24438e51023af3bfc1db8aed43c1342817e8cfcd:rand/arith128_test.go | ||
|
||
// Copyright 2017 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package rand | ||
|
||
import ( | ||
"math/big" | ||
"math/rand" | ||
"testing" | ||
) | ||
|
||
var bigMaxUint64 = big.NewInt(0).SetUint64(maxUint64) | ||
|
||
func bigInt(xHi, xLo uint64) *big.Int { | ||
b := big.NewInt(0).SetUint64(xHi) | ||
b.Lsh(b, 64) | ||
b.Or(b, big.NewInt(0).SetUint64(xLo)) | ||
return b | ||
} | ||
|
||
func splitBigInt(b *big.Int) (outHi, outLo uint64) { | ||
outHi = big.NewInt(0).Rsh(b, 64).Uint64() | ||
outLo = big.NewInt(0).And(b, bigMaxUint64).Uint64() | ||
return | ||
} | ||
|
||
func bigMulMod128bits(xHi, xLo, yHi, yLo uint64) (outHi, outLo uint64) { | ||
bigX := bigInt(xHi, xLo) | ||
bigY := bigInt(yHi, yLo) | ||
return splitBigInt(bigX.Mul(bigX, bigY)) | ||
} | ||
|
||
func bigAddMod128bits(xHi, xLo, yHi, yLo uint64) (outHi, outLo uint64) { | ||
bigX := bigInt(xHi, xLo) | ||
bigY := bigInt(yHi, yLo) | ||
return splitBigInt(bigX.Add(bigX, bigY)) | ||
} | ||
|
||
type arithTest struct { | ||
xHi, xLo uint64 | ||
} | ||
|
||
const ( | ||
iLo = increment & maxUint64 | ||
iHi = (increment >> 64) & maxUint64 | ||
) | ||
|
||
var arithTests = []arithTest{ | ||
{0, 0}, | ||
{0, 1}, | ||
{1, 0}, | ||
{0, maxUint64}, | ||
{maxUint64, 0}, | ||
{maxUint64, maxUint64}, | ||
// Randomly generated 64-bit integers. | ||
{3757956613005209672, 17983933746665545631}, | ||
{511324141977587414, 5626651684620191081}, | ||
{1534313104606153588, 2415006486399353367}, | ||
{6873586429837825902, 13854394671140464137}, | ||
{6617134480561088940, 18421520694158684312}, | ||
} | ||
|
||
func TestPCGAdd(t *testing.T) { | ||
for i, test := range arithTests { | ||
p := &PCGSource{ | ||
low: test.xLo, | ||
high: test.xHi, | ||
} | ||
p.add() | ||
expectHi, expectLo := bigAddMod128bits(test.xHi, test.xLo, iHi, iLo) | ||
if p.low != expectLo || p.high != expectHi { | ||
t.Errorf("%d: got hi=%d lo=%d; expect hi=%d lo=%d", i, p.high, p.low, expectHi, expectLo) | ||
} | ||
} | ||
} | ||
|
||
const ( | ||
mLo = multiplier & maxUint64 | ||
mHi = (multiplier >> 64) & maxUint64 | ||
) | ||
|
||
func TestPCGMultiply(t *testing.T) { | ||
for i, test := range arithTests { | ||
p := &PCGSource{ | ||
low: test.xLo, | ||
high: test.xHi, | ||
} | ||
p.multiply() | ||
expectHi, expectLo := bigMulMod128bits(test.xHi, test.xLo, mHi, mLo) | ||
if p.low != expectLo || p.high != expectHi { | ||
t.Errorf("%d: got hi=%d lo=%d; expect hi=%d lo=%d", i, p.high, p.low, expectHi, expectLo) | ||
} | ||
} | ||
} | ||
|
||
func TestPCGMultiplyLong(t *testing.T) { | ||
if testing.Short() { | ||
return | ||
} | ||
for i := 0; i < 1e6; i++ { | ||
low := rand.Uint64() | ||
high := rand.Uint64() | ||
p := &PCGSource{ | ||
low: low, | ||
high: high, | ||
} | ||
p.multiply() | ||
expectHi, expectLo := bigMulMod128bits(high, low, mHi, mLo) | ||
if p.low != expectLo || p.high != expectHi { | ||
t.Fatalf("%d: (%d,%d): got hi=%d lo=%d; expect hi=%d lo=%d", i, high, low, p.high, p.low, expectHi, expectLo) | ||
} | ||
} | ||
} | ||
|
||
func BenchmarkPCGMultiply(b *testing.B) { | ||
low := rand.Uint64() | ||
high := rand.Uint64() | ||
p := &PCGSource{ | ||
low: low, | ||
high: high, | ||
} | ||
for i := 0; i < b.N; i++ { | ||
p.multiply() | ||
} | ||
} |
Oops, something went wrong.