-
Notifications
You must be signed in to change notification settings - Fork 440
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into dario.castane/go-124-errors
- Loading branch information
Showing
66 changed files
with
2,028 additions
and
185 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,16 @@ | ||
module github.com/DataDog/dd-trace-go/.github/workflows/apps | ||
|
||
go 1.23.3 | ||
|
||
require ( | ||
github.com/Masterminds/semver/v3 v3.3.1 | ||
github.com/stretchr/testify v1.10.0 | ||
golang.org/x/mod v0.22.0 | ||
gopkg.in/DataDog/dd-trace-go.v1 v1.70.1 | ||
) | ||
|
||
require ( | ||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect | ||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
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,16 @@ | ||
github.com/Masterminds/semver/v3 v3.3.1 h1:QtNSWtVZ3nBfk8mAOu/B6v7FMJ+NHTIgUPi7rj+4nv4= | ||
github.com/Masterminds/semver/v3 v3.3.1/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM= | ||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= | ||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= | ||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= | ||
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= | ||
golang.org/x/mod v0.22.0 h1:D4nJWe9zXqHOmWqj4VMOJhvzj7bEZg4wEYa759z1pH4= | ||
golang.org/x/mod v0.22.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY= | ||
gopkg.in/DataDog/dd-trace-go.v1 v1.70.1 h1:ZIRxAKlr3xr6xbMUDs3IDa6xq+ISv9zxyjaDCfwDjMY= | ||
gopkg.in/DataDog/dd-trace-go.v1 v1.70.1/go.mod h1:PMOSkeY4VfXiuPvGodeNLCZCFYU2VfOvjVI6cX5bGrc= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= | ||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
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,153 @@ | ||
// Unless explicitly stated otherwise all files in this repository are licensed | ||
// under the Apache License Version 2.0. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
// Copyright 2024 Datadog, Inc. | ||
|
||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"sort" | ||
"github.com/Masterminds/semver/v3" | ||
"golang.org/x/mod/modfile" | ||
"net/http" | ||
"os" | ||
"regexp" | ||
"strings" | ||
) | ||
|
||
type Tag struct { | ||
Name string | ||
} | ||
|
||
func getLatestMajorVersion(repo string) (string, error) { | ||
// Get latest major version available for repo from github. | ||
const apiURL = "https://api.github.com/repos/%s/tags" | ||
url := fmt.Sprintf(apiURL, repo) | ||
|
||
resp, err := http.Get(url) | ||
if err != nil { | ||
return "", err | ||
} | ||
defer resp.Body.Close() | ||
|
||
if resp.StatusCode != http.StatusOK { | ||
return "", fmt.Errorf("failed to fetch tags: %s", resp.Status) | ||
} | ||
|
||
var tags []struct { | ||
Name string `json:"name"` | ||
} | ||
|
||
if err := json.NewDecoder(resp.Body).Decode(&tags); err != nil { | ||
return "", err | ||
} | ||
latestByMajor := make(map[int]*semver.Version) | ||
|
||
for _, tag := range tags { | ||
v, err := semver.NewVersion(tag.Name) | ||
if err != nil { | ||
continue // Skip invalid versions | ||
} | ||
|
||
if v.Prerelease() != "" { | ||
continue // Ignore pre-release versions | ||
} | ||
|
||
major := int(v.Major()) | ||
if current, exists := latestByMajor[major]; !exists || v.GreaterThan(current) { | ||
latestByMajor[major] = v | ||
} | ||
} | ||
|
||
var latestMajor *semver.Version | ||
for _, v := range latestByMajor { | ||
if latestMajor == nil || v.Major() > latestMajor.Major() { | ||
latestMajor = v | ||
} | ||
} | ||
|
||
if latestMajor != nil { | ||
return fmt.Sprintf("v%d", latestMajor.Major()), nil | ||
} | ||
|
||
return "", fmt.Errorf("no valid versions found") | ||
|
||
} | ||
|
||
func main() { | ||
|
||
data, err := os.ReadFile("integration_go.mod") | ||
if err != nil { | ||
fmt.Println("Error reading integration_go.mod:", err) | ||
return | ||
} | ||
|
||
modFile, err := modfile.Parse("integration_go.mod", data, nil) | ||
if err != nil { | ||
fmt.Println("Error parsing integration_go.mod:", err) | ||
return | ||
} | ||
|
||
latestMajor := make(map[string]*semver.Version) | ||
|
||
// Match on versions with /v{major} | ||
versionRegex := regexp.MustCompile(`^(?P<module>.+?)/v(\d+)$`) | ||
|
||
// Iterate over the required modules and update latest major version if necessary | ||
for _, req := range modFile.Require { | ||
module := req.Mod.Path | ||
|
||
if match := versionRegex.FindStringSubmatch(module); match != nil { | ||
url := match[1] // base module URL (e.g., github.com/foo) | ||
majorVersionStr := "v" + match[2] // Create semantic version string (e.g., "v2") | ||
|
||
moduleName := strings.TrimPrefix(strings.TrimSpace(url), "github.com/") | ||
|
||
// Parse the semantic version | ||
majorVersion, err := semver.NewVersion(majorVersionStr) | ||
if err != nil { | ||
fmt.Printf("Skip invalid version for module %s: %v\n", module, err) | ||
continue | ||
} | ||
|
||
if existing, ok := latestMajor[moduleName]; !ok || majorVersion.GreaterThan(existing) { | ||
latestMajor[moduleName] = majorVersion | ||
} | ||
} | ||
} | ||
|
||
// Output latest major version that we support. | ||
// Check if a new major version in Github is available that we don't support. | ||
// If so, output that a new latest is available. | ||
|
||
// Sort the output | ||
modules := make([]string, 0, len(latestMajor)) | ||
for module := range latestMajor { | ||
modules = append(modules, module) | ||
} | ||
sort.Strings(modules) | ||
|
||
for _, module := range modules { | ||
major := latestMajor[module] | ||
|
||
latestVersion, err := getLatestMajorVersion(module) // latest version available | ||
if err != nil { | ||
fmt.Printf("Error fetching latest version for module '%s': %v\n", module, err) | ||
continue | ||
} | ||
|
||
latestVersionParsed, err := semver.NewVersion(latestVersion) | ||
if err != nil { | ||
fmt.Printf("Error parsing latest version '%s' for module '%s': %v\n", latestVersion, module, err) | ||
continue | ||
} | ||
|
||
fmt.Printf("Latest DD major version of %s: %d\n", module, major.Major()) | ||
if major.LessThan(latestVersionParsed) { | ||
fmt.Printf("New latest major version of %s available: %d\n", module, latestVersionParsed.Major()) | ||
} | ||
|
||
} | ||
} |
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,41 @@ | ||
name: Outdated Integrations | ||
on: | ||
schedule: | ||
- cron: "0 0 * * 0" # Runs every Sunday at midnight UTC | ||
workflow_dispatch: | ||
|
||
concurrency: | ||
# Automatically cancel previous runs if a new one is triggered to conserve resources. | ||
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
test: | ||
name: Find new major versions for the contrib package dependencies | ||
runs-on: ubuntu-latest | ||
permissions: | ||
actions: read | ||
contents: write | ||
pull-requests: write | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- run: go get github.com/Masterminds/semver/v3 | ||
|
||
- run: go run .github/workflows/apps/latest_major_version.go > latests.txt | ||
|
||
- run: git diff | ||
|
||
- name: Create Pull Request | ||
id: pr | ||
uses: peter-evans/create-pull-request@v6 | ||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
branch: "upgrade-latest-major-version" | ||
commit-message: "Update latests file" | ||
base: main | ||
title: "chore: update latest majors" | ||
labels: changelog/no-changelog | ||
body: "Auto-generated PR from Outdated Integrations workflow to update latests major versions" |
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
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
Oops, something went wrong.