-
Notifications
You must be signed in to change notification settings - Fork 443
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
output supported versions #3058
Draft
quinna-h
wants to merge
5
commits into
main
Choose a base branch
from
quinna/add-supported-versions-workflow
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+368
−2
Draft
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,44 @@ | ||
name: Supported Versions | ||
on: | ||
workflow_run: | ||
workflows: ["Smoke Tests"] | ||
branches: [main] | ||
types: | ||
- completed | ||
|
||
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: | ||
on-smoke-tests-success: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
actions: read | ||
contents: write | ||
pull-requests: write | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
if: ${{ github.event.workflow_run.conclusion == 'success' }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
- run: echo 'Smoke Tests workflow passed' | ||
|
||
- run: go run parse_go_mod.go | ||
|
||
- run: git diff | ||
|
||
# note: This will only run when there *are* changes to integration versions | ||
- name: Create Pull Request | ||
id: pr | ||
uses: peter-evans/create-pull-request@v6 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
branch: "update-latest-supported-versions" | ||
commit-message: "Update supported versions" | ||
base: main | ||
title: "chore: update latest supported" | ||
labels: changelog/no-changelog | ||
body: "Test" |
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,163 @@ | ||
// 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 ( | ||
"bufio" | ||
"bytes" | ||
"context" | ||
"fmt" | ||
"os" | ||
"os/exec" | ||
"regexp" | ||
"strings" | ||
"sync" | ||
"time" | ||
) | ||
|
||
type ModuleVersion struct { | ||
Name string | ||
MinVersion string | ||
MaxVersion string | ||
} | ||
|
||
func parseGoMod(filePath string) ([]ModuleVersion, error) { | ||
// This parses the go.mod file and extracts modules with their minimum versions. | ||
var modules []ModuleVersion | ||
|
||
file, err := os.Open(filePath) | ||
if err != nil { | ||
return nil, fmt.Errorf("error: %s not found", filePath) | ||
} | ||
defer file.Close() | ||
|
||
regex := regexp.MustCompile(`^\s*([^\s]+)\s+v([0-9]+\.[0-9]+\.[0-9]+.*)`) | ||
|
||
scanner := bufio.NewScanner(file) | ||
inRequireBlock := false | ||
|
||
for scanner.Scan() { | ||
line := strings.TrimSpace(scanner.Text()) | ||
|
||
if strings.HasPrefix(line, "require (") { | ||
inRequireBlock = true | ||
continue | ||
} | ||
|
||
if inRequireBlock && line == ")" { | ||
inRequireBlock = false | ||
continue | ||
} | ||
|
||
if inRequireBlock || strings.HasPrefix(line, "require ") { | ||
match := regex.FindStringSubmatch(line) | ||
if match != nil { | ||
modules = append(modules, ModuleVersion{ | ||
Name: match[1], | ||
MinVersion: match[2], | ||
}) | ||
} | ||
} | ||
} | ||
|
||
if err := scanner.Err(); err != nil { | ||
return nil, fmt.Errorf("error reading file: %v", err) | ||
} | ||
|
||
return modules, nil | ||
} | ||
|
||
func fetchLatestVersion(module string) (string, error) { | ||
// Fetches latest version with `go list` | ||
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second) | ||
defer cancel() | ||
|
||
cmd := exec.CommandContext(ctx, "go", "list", "-m", "-versions", module) | ||
var stdout, stderr bytes.Buffer | ||
cmd.Stdout = &stdout | ||
cmd.Stderr = &stderr | ||
|
||
err := cmd.Run() | ||
if ctx.Err() == context.DeadlineExceeded { | ||
return "", fmt.Errorf("command timed out") | ||
} | ||
if err != nil { | ||
return "", fmt.Errorf("command error: %s", stderr.String()) | ||
} | ||
|
||
versions := strings.Fields(stdout.String()) | ||
if len(versions) < 1 { | ||
return "", fmt.Errorf("no versions found for module: %s", module) | ||
} | ||
|
||
return versions[len(versions)-1], nil | ||
} | ||
|
||
func fetchAllLatestVersions(modules []ModuleVersion) []ModuleVersion { | ||
// Concurrently fetches the latest version of each module. | ||
|
||
var wg sync.WaitGroup | ||
var mu sync.Mutex | ||
|
||
updatedModules := make([]ModuleVersion, 0, len(modules)) | ||
|
||
wg.Add(len(modules)) | ||
for _, mod := range modules { | ||
go func(mod ModuleVersion) { | ||
defer wg.Done() | ||
latestVersion, err := fetchLatestVersion(mod.Name) | ||
if err != nil { | ||
fmt.Printf("Error fetching latest version for %s: %v\n", mod.Name, err) | ||
mu.Lock() | ||
updatedModules = append(updatedModules, ModuleVersion{mod.Name, mod.MinVersion, "Error"}) | ||
mu.Unlock() | ||
return | ||
} | ||
mu.Lock() | ||
updatedModules = append(updatedModules, ModuleVersion{mod.Name, mod.MinVersion, latestVersion}) | ||
mu.Unlock() | ||
}(mod) | ||
} | ||
|
||
wg.Wait() | ||
return updatedModules | ||
} | ||
|
||
func outputVersionsAsMarkdown(modules []ModuleVersion, filePath string) error { | ||
file, err := os.Create(filePath) | ||
if err != nil { | ||
return fmt.Errorf("error creating file: %v", err) | ||
} | ||
defer file.Close() | ||
|
||
fmt.Fprintln(file, "| Dependency | Minimum Version | Maximum Version |") | ||
fmt.Fprintln(file, "|------------|-----------------|-----------------|") | ||
for _, mod := range modules { | ||
fmt.Fprintf(file, "| %s | v%s | %s |\n", mod.Name, mod.MinVersion, mod.MaxVersion) | ||
} | ||
return nil | ||
} | ||
|
||
func main() { | ||
goModPath := "integration_go.mod" // Modify path as needed | ||
outputPath := "minimum_versions.md" | ||
|
||
modules, err := parseGoMod(goModPath) | ||
if err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
|
||
modulesWithLatest := fetchAllLatestVersions(modules) | ||
|
||
err = outputVersionsAsMarkdown(modulesWithLatest, outputPath) | ||
if err != nil { | ||
fmt.Printf("Error writing output file: %v\n", err) | ||
return | ||
} | ||
|
||
fmt.Println("Version information written to", outputPath) | ||
} |
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,87 @@ | ||
| Dependency | Minimum Version | Maximum Version | | ||
|------------|-----------------|-----------------| | ||
| github.com/go-chi/chi/v5 | v5.0.10 | v5.2.0 | | ||
| github.com/tidwall/buntdb | v1.3.0 | v1.3.2 | | ||
| github.com/go-redis/redis/v7 | v7.4.1 | v7.4.1 | | ||
| github.com/99designs/gqlgen | v0.17.36 | v0.17.61 | | ||
| github.com/emicklei/go-restful | v2.16.0+incompatible | v2.16.0+incompatible | | ||
| github.com/IBM/sarama | v1.40.0 | v1.43.3 | | ||
| github.com/aws/aws-sdk-go | v1.44.327 | v1.55.5 | | ||
| github.com/globalsign/mgo | v0.0.0-20181015135952-eeefdecb41b8 | github.com/globalsign/mgo | | ||
| github.com/denisenkom/go-mssqldb | v0.11.0 | v0.12.3 | | ||
| github.com/gin-gonic/gin | v1.9.1 | v1.10.0 | | ||
| github.com/graphql-go/handler | v0.2.3 | v0.2.4 | | ||
| github.com/gocql/gocql | v1.6.0 | v1.7.0 | | ||
| github.com/Shopify/sarama | v1.38.1 | v1.43.3 | | ||
| github.com/google/pprof | v0.0.0-20230817174616-7a8ec2ada47b | github.com/google/pprof | | ||
| github.com/go-redis/redis/v8 | v8.11.5 | v8.11.5 | | ||
| github.com/jinzhu/gorm | v1.9.16 | v1.9.16 | | ||
| github.com/google/uuid | v1.5.0 | v1.6.0 | | ||
| github.com/syndtr/goleveldb | v1.0.1-0.20220721030215-126854af5e6d | v1.0.0 | | ||
| github.com/aws/aws-sdk-go-v2/service/dynamodb | v1.21.4 | v1.38.1 | | ||
| github.com/go-pg/pg/v10 | v10.11.1 | v10.14.0 | | ||
| github.com/hashicorp/vault/sdk | v0.9.2 | v0.14.0 | | ||
| github.com/lib/pq | v1.10.2 | v1.10.9 | | ||
| github.com/sirupsen/logrus | v1.9.3 | v1.9.3 | | ||
| github.com/hashicorp/vault/api | v1.9.2 | v1.15.0 | | ||
| github.com/go-sql-driver/mysql | v1.6.0 | v1.8.1 | | ||
| github.com/emicklei/go-restful/v3 | v3.11.0 | v3.12.1 | | ||
| github.com/aws/aws-sdk-go-v2/service/ec2 | v1.93.2 | v1.198.1 | | ||
| gorm.io/driver/postgres | v1.4.6 | v1.5.11 | | ||
| github.com/aws/aws-sdk-go-v2/config | v1.18.21 | v1.28.7 | | ||
| github.com/urfave/negroni | v1.0.0 | v1.0.0 | | ||
| google.golang.org/protobuf | v1.33.0 | v1.36.1 | | ||
| github.com/redis/go-redis/v9 | v9.7.0 | v9.7.0 | | ||
| github.com/elastic/go-elasticsearch/v8 | v8.15.0 | v8.17.0 | | ||
| github.com/garyburd/redigo | v1.6.4 | v1.6.4 | | ||
| github.com/gomodule/redigo | v1.8.9 | v1.9.2 | | ||
| go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp | v0.44.0 | v0.58.0 | | ||
| google.golang.org/api | v0.128.0 | v0.214.0 | | ||
| gopkg.in/jinzhu/gorm.v1 | v1.9.2 | v1.9.2 | | ||
| github.com/aws/aws-sdk-go-v2/service/eventbridge | v1.20.4 | v1.36.1 | | ||
| github.com/twitchtv/twirp | v8.1.3+incompatible | v8.1.3+incompatible | | ||
| github.com/aws/aws-sdk-go-v2/service/s3 | v1.32.0 | v1.71.1 | | ||
| github.com/mattn/go-sqlite3 | v1.14.18 | v1.14.24 | | ||
| k8s.io/client-go | v0.23.17 | v0.33.0-alpha.0 | | ||
| github.com/gofiber/fiber/v2 | v2.52.5 | v2.52.5 | | ||
| github.com/aws/aws-sdk-go-v2/service/kinesis | v1.18.4 | v1.32.8 | | ||
| gorm.io/driver/mysql | v1.0.1 | v1.5.7 | | ||
| github.com/aws/aws-sdk-go-v2 | v1.20.3 | v2.0.0-preview.4+incompatible | | ||
| gopkg.in/olivere/elastic.v5 | v5.0.84 | v5.0.86 | | ||
| gopkg.in/olivere/elastic.v3 | v3.0.75 | v3.0.75 | | ||
| github.com/confluentinc/confluent-kafka-go/v2 | v2.2.0 | v2.6.1 | | ||
| github.com/aws/aws-sdk-go-v2/service/sfn | v1.19.4 | v1.34.2 | | ||
| github.com/aws/aws-sdk-go-v2/service/sqs | v1.24.4 | v1.37.3 | | ||
| github.com/hashicorp/go-secure-stdlib/parseutil | v0.1.7 | v0.1.8 | | ||
| google.golang.org/grpc | v1.57.1 | v1.70.0-dev | | ||
| github.com/go-redis/redis | v6.15.9+incompatible | v6.15.9+incompatible | | ||
| gorm.io/driver/sqlserver | v1.4.2 | v1.5.4 | | ||
| cloud.google.com/go/pubsub | v1.33.0 | v1.45.3 | | ||
| github.com/uptrace/bun | v1.1.17 | v1.2.6 | | ||
| github.com/gorilla/mux | v1.8.0 | v1.8.1 | | ||
| github.com/go-chi/chi | v1.5.4 | v4.1.2+incompatible | | ||
| gorm.io/gorm | v1.25.3 | v1.25.12 | | ||
| github.com/elastic/go-elasticsearch/v6 | v6.8.5 | v6.8.10 | | ||
| github.com/go-redis/redis/v9 | v9.7.0 // renamed to redis/go-redis in v9 | v9.7.0 | | ||
| github.com/zenazn/goji | v1.0.1 | v1.0.1 | | ||
| github.com/miekg/dns | v1.1.55 | v1.1.62 | | ||
| github.com/vektah/gqlparser/v2 | v2.5.16 | v2.5.20 | | ||
| github.com/hashicorp/go-multierror | v1.1.1 | v1.1.1 | | ||
| github.com/confluentinc/confluent-kafka-go | v1.9.2 | v1.9.3-RC3 | | ||
| github.com/segmentio/kafka-go | v0.4.42 | v0.4.47 | | ||
| github.com/labstack/echo | v3.3.10+incompatible | v3.3.10+incompatible | | ||
| github.com/aws/aws-sdk-go-v2/service/sns | v1.21.4 | v1.33.8 | | ||
| github.com/graph-gophers/graphql-go | v1.5.0 | v1.5.0 | | ||
| github.com/jackc/pgx/v5 | v5.6.0 | v5.7.2 | | ||
| github.com/graphql-go/graphql | v0.8.1 | v0.8.1 | | ||
| github.com/uptrace/bun/dialect/sqlitedialect | v1.1.17 | v1.2.6 | | ||
| github.com/bradfitz/gomemcache | v0.0.0-20230611145640-acc696258285 | github.com/bradfitz/gomemcache | | ||
| github.com/labstack/echo/v4 | v4.11.1 | v4.13.3 | | ||
| github.com/elastic/go-elasticsearch/v7 | v7.17.10 | v7.17.10 | | ||
| github.com/julienschmidt/httprouter | v1.3.0 | v1.3.0 | | ||
| github.com/microsoft/go-mssqldb | v0.21.0 | v1.8.0 | | ||
| github.com/jmoiron/sqlx | v1.3.5 | v1.4.0 | | ||
| go.mongodb.org/mongo-driver | v1.12.1 | v1.17.1 | | ||
| github.com/hashicorp/consul/api | v1.24.0 | v1.31.0 | | ||
| github.com/dimfeld/httptreemux/v5 | v5.5.0 | v5.5.0 | | ||
| github.com/valyala/fasthttp | v1.51.0 | v1.58.0 | |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟠 Code Vulnerability
Dangerous GitHub actions trigger (...read more)