Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 28 additions & 8 deletions .github/workflows/update-ca-bundle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,33 @@ jobs:
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- uses: knative/actions/setup-go@main
- name: Update CA bundle
run: go run ./hack/cmd/update-ca-bundle
- name: Run make generate
run: make generate/zz_filesystem_generated.go
- name: Check for changes
id: changes
run: |
if git diff --quiet; then
echo "changed=false" >> $GITHUB_OUTPUT
else
echo "changed=true" >> $GITHUB_OUTPUT
fi
- name: Create Pull Request
if: steps.changes.outputs.changed == 'true'
uses: peter-evans/create-pull-request@v7
with:
node-version: "20"
- name: Install NPM deps.
run: npm install octokit@3.2.1
- name: Create PR
env:
GITHUB_TOKEN: ${{ github.token }}
run: node ./hack/update-ca-bundle.js
token: ${{ github.token }}
commit-message: 'chore: update CA bundle'
title: 'chore: update CA bundle'
body: |
This PR updates the CA bundle in the embedded templates.

This PR was automatically generated by the [update-ca-bundle workflow](https://github.com/${{ github.repository }}/actions/workflows/update-ca-bundle.yaml).
branch: update-ca-bundle
delete-branch: true
committer: Knative Automation <automation@knative.team>
author: Knative Automation <automation@knative.team>
assignees: gauron99, matejvasek, lkingland
base: main
40 changes: 31 additions & 9 deletions .github/workflows/update-quarkus-platform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,39 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: knative/actions/setup-go@main
- uses: actions/setup-node@v4
with:
node-version: "20"
- uses: actions/setup-java@v4
with:
java-version: 21
distribution: 'temurin'
- name: Install NPM deps.
run: npm install xml2js@0.6.2 octokit@3.2.1
- name: Create PR
env:
GITHUB_TOKEN: ${{ github.token }}
run: node ./hack/update-quarkus-platform.js
- name: Update Quarkus platform version
run: go run ./hack/cmd/update-quarkus-platform
- name: Run make generate
run: make generate/zz_filesystem_generated.go
- name: Check for changes
id: changes
run: |
if git diff --quiet; then
echo "changed=false" >> $GITHUB_OUTPUT
else
echo "changed=true" >> $GITHUB_OUTPUT
fi
- name: Run smoke tests
if: steps.changes.outputs.changed == 'true'
run: make test-quarkus
- name: Create Pull Request
if: steps.changes.outputs.changed == 'true'
uses: peter-evans/create-pull-request@v7
with:
token: ${{ github.token }}
commit-message: 'chore: update Quarkus platform version'
title: 'chore: update Quarkus platform version'
body: |
This PR updates the Quarkus platform version in the Quarkus scaffolding templates to the latest version.

This PR was automatically generated by the [update-quarkus-platform workflow](https://github.com/${{ github.repository }}/actions/workflows/update-quarkus-platform.yaml).
branch: update-quarkus-platform
delete-branch: true
committer: Knative Automation <automation@knative.team>
author: Knative Automation <automation@knative.team>
assignees: gauron99, matejvasek, lkingland
base: main
38 changes: 31 additions & 7 deletions .github/workflows/update-springboot-platform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,41 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: knative/actions/setup-go@main
- uses: actions/setup-node@v4
with:
node-version: "20"
- uses: actions/setup-java@v4
with:
java-version: 21
distribution: 'temurin'
- name: Install NPM deps.
run: npm install xml2js@0.6.2 octokit@3.2.1 yaml@2.4.5 semver@7.6.3
- name: Create PR
- name: Update Spring Boot platform version
env:
GITHUB_TOKEN: ${{ github.token }}
run: node ./hack/update-springboot-platform.js
run: go run ./hack/cmd/update-springboot-platform
- name: Run make generate
run: make generate/zz_filesystem_generated.go
- name: Check for changes
id: changes
run: |
if git diff --quiet; then
echo "changed=false" >> $GITHUB_OUTPUT
else
echo "changed=true" >> $GITHUB_OUTPUT
fi
- name: Run smoke tests
if: steps.changes.outputs.changed == 'true'
run: make test-springboot
- name: Create Pull Request
if: steps.changes.outputs.changed == 'true'
uses: peter-evans/create-pull-request@v7
with:
token: ${{ github.token }}
commit-message: 'chore: update Spring Boot platform version'
title: 'chore: update Spring Boot platform version'
body: |
This PR updates the Spring Boot platform version in the Spring Boot scaffolding templates to the latest version.

This PR was automatically generated by the [update-springboot-platform workflow](https://github.com/${{ github.repository }}/actions/workflows/update-springboot-platform.yaml).
branch: update-springboot-platform
delete-branch: true
committer: Knative Automation <automation@knative.team>
author: Knative Automation <automation@knative.team>
assignees: gauron99, matejvasek, lkingland
base: main
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,18 @@ test-hack:
__update-builder: # Used in automation
cd hack && go run ./cmd/update-builder

.PHONY: update-quarkus-platform
update-quarkus-platform: ## Update Quarkus platform version in templates
go run ./hack/cmd/update-quarkus-platform

.PHONY: update-springboot-platform
update-springboot-platform: ## Update Spring Boot platform version in templates
go run ./hack/cmd/update-springboot-platform

.PHONY: update-ca-bundle
update-ca-bundle: ## Update CA bundle in templates
go run ./hack/cmd/update-ca-bundle

.PHONY: setup-githooks
setup-githooks:
git config --local core.hooksPath .githooks/
25 changes: 25 additions & 0 deletions hack/cmd/shared/shared.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package shared

import (
"context"
"fmt"
"net/http"
"os"
"os/exec"
"strings"
"time"
)

// HTTPClient is used for all outbound HTTP requests; has a 30-second timeout.
var HTTPClient = &http.Client{Timeout: 30 * time.Second}

Comment thread
Ankitsinghsisodya marked this conversation as resolved.
// RunCmd runs name with args, streaming stdout/stderr to the process output.
func RunCmd(ctx context.Context, name string, args ...string) error {
cmd := exec.CommandContext(ctx, name, args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
return fmt.Errorf("command %q failed: %w", name+" "+strings.Join(args, " "), err)
}
return nil
}
36 changes: 36 additions & 0 deletions hack/cmd/update-ca-bundle/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package main

import (
"context"
"fmt"
"os"
"os/signal"
"syscall"

"knative.dev/func/hack/cmd/shared"
)

const caBundleMakeTarget = "templates/certs/ca-certificates.crt"

func main() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
go func() {
<-sigs
cancel()
<-sigs
os.Exit(130)
}()

if err := run(ctx); err != nil {
fmt.Fprintf(os.Stderr, "ERROR: %v\n", err)
os.Exit(1)
}
}

func run(ctx context.Context) error {
return shared.RunCmd(ctx, "make", caBundleMakeTarget)
}
137 changes: 137 additions & 0 deletions hack/cmd/update-quarkus-platform/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
package main

import (
"context"
"encoding/json"
"fmt"
"net/http"
"os"
"os/signal"
"regexp"
"syscall"

"knative.dev/func/hack/cmd/shared"
)

const (
cePomPath = "templates/quarkus/cloudevents/pom.xml"
httpPomPath = "templates/quarkus/http/pom.xml"

quarkusPlatformAPI = "https://code.quarkus.io/api/platforms"

quarkusVersionTag = "quarkus.platform.version"
quarkusVersionExpr = `<quarkus\.platform\.version>([^<]+)</quarkus\.platform\.version>`
)

var quarkusVersionRe = regexp.MustCompile(quarkusVersionExpr)

type quarkusPlatformResponse struct {
Platforms []struct {
Streams []struct {
Releases []struct {
QuarkusCoreVersion string `json:"quarkusCoreVersion"`
} `json:"releases"`
} `json:"streams"`
} `json:"platforms"`
}

func main() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
go func() {
<-sigs
cancel()
<-sigs
os.Exit(130)
}()

if err := run(ctx); err != nil {
fmt.Fprintf(os.Stderr, "ERROR: %v\n", err)
os.Exit(1)
}
}

func run(ctx context.Context) error {
latestVersion, err := getLatestQuarkusVersion(ctx)
if err != nil {
return fmt.Errorf("cannot get latest Quarkus platform version: %w", err)
}
fmt.Printf("Latest Quarkus platform version: %s\n", latestVersion)

ceVersion, err := versionFromPOM(cePomPath)
if err != nil {
return fmt.Errorf("cannot read version from %s: %w", cePomPath, err)
}
httpVersion, err := versionFromPOM(httpPomPath)
if err != nil {
return fmt.Errorf("cannot read version from %s: %w", httpPomPath, err)
}

if ceVersion == latestVersion && httpVersion == latestVersion {
fmt.Println("Quarkus platform is up-to-date!")
return nil
}

for _, pomPath := range []string{cePomPath, httpPomPath} {
if err := updatePOM(pomPath, latestVersion); err != nil {
return fmt.Errorf("cannot update %s: %w", pomPath, err)
}
}
return nil
}

func getLatestQuarkusVersion(ctx context.Context) (string, error) {
req, err := http.NewRequestWithContext(ctx, http.MethodGet, quarkusPlatformAPI, nil)
if err != nil {
return "", err
}
resp, err := shared.HTTPClient.Do(req)
if err != nil {
return "", err
}
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
return "", fmt.Errorf("unexpected status %d from %s", resp.StatusCode, quarkusPlatformAPI)
}

var data quarkusPlatformResponse
if err := json.NewDecoder(resp.Body).Decode(&data); err != nil {
return "", err
}
if len(data.Platforms) == 0 ||
len(data.Platforms[0].Streams) == 0 ||
len(data.Platforms[0].Streams[0].Releases) == 0 {
return "", fmt.Errorf("unexpected response structure from Quarkus platform API")
}
v := data.Platforms[0].Streams[0].Releases[0].QuarkusCoreVersion
if v == "" {
return "", fmt.Errorf("quarkusCoreVersion is empty in API response")
}
return v, nil
}

func versionFromPOM(path string) (string, error) {
data, err := os.ReadFile(path)
if err != nil {
return "", err
}
m := quarkusVersionRe.FindSubmatch(data)
if len(m) < 2 {
return "", fmt.Errorf("cannot find <%s> in %s", quarkusVersionTag, path)
}
return string(m[1]), nil
}

func updatePOM(path, newVersion string) error {
data, err := os.ReadFile(path)
if err != nil {
return err
}
updated := quarkusVersionRe.ReplaceAll(data,
[]byte(fmt.Sprintf("<%s>%s</%s>", quarkusVersionTag, newVersion, quarkusVersionTag)))
return os.WriteFile(path, updated, 0644)
}
Loading
Loading