-
Notifications
You must be signed in to change notification settings - Fork 440
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
internal: add workflow to check for outdated integrations #3008
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 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,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
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 | ||
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: "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
Oops, something went wrong.
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
Workflow depends on a GitHub actions pinned by tag (...read more)