Skip to content
Merged
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
27 changes: 27 additions & 0 deletions .github/workflows/update-examples-cron.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Update Examples Cron

on:
schedule:
- cron: '0 0 * * *'
workflow_dispatch:

permissions:
contents: write
pull-requests: write

jobs:
update-examples-cron:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- run: |
make tools/update_examples
if ! git diff --exit-code;
then
make tools/update_examples_pr
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsure if this is the right token, this does something very similar:

GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }}

GITHUB_REPOSITORY: ${{ github.repository }}
16 changes: 15 additions & 1 deletion Makefile.examples
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
GITHUB_REPOSITORY ?= grafana/pyroscope

.PHONY: tools/update_examples
tools/update_examples:
go run tools/update_examples.go
docker build -t update_pyroscope_examples -f tools/update_examples.Dockerfile tools
docker run --rm -e GITHUB_TOKEN=$(GITHUB_TOKEN) -v$(shell pwd):/pyroscope -w /pyroscope update_pyroscope_examples bash -l -c "go run tools/update_examples.go"

.PHONY: tools/update_examples_pr
tools/update_examples_pr:
git config --local user.name 'Pyroscope Bot'
git config --local user.email 'dmitry+bot@pyroscope.io'
git checkout -b gh_bot_examples_update
git add .
git commit -m "chore(examples): update examples"
git push -f https://x-access-token:$(GITHUB_TOKEN)@github.com/$(GITHUB_REPOSITORY).git gh_bot_examples_update
gh pr create --head gh_bot_examples_update --title "chore(examples): update examples" --body "make tools/update_examples" --repo $(GITHUB_REPOSITORY) || \
gh pr edit gh_bot_examples_update --title "chore(examples): update examples" --body "make tools/update_examples" --repo $(GITHUB_REPOSITORY)


.PHONY: rideshare/docker/push
rideshare/docker/push: rideshare/docker/push-golang rideshare/docker/push-loadgen rideshare/docker/push-python rideshare/docker/push-ruby rideshare/docker/push-dotnet rideshare/docker/push-java rideshare/docker/push-rust
Expand Down
33 changes: 33 additions & 0 deletions tools/update_examples.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

ARG NODE_VERSION=node:18

FROM ${NODE_VERSION} AS node


FROM ubuntu:22.04

RUN apt-get update && apt-get -y install wget git build-essential libssl-dev libgmp-dev libyaml-dev zlib1g-dev curl \
gawk autoconf automake bison libffi-dev libgdbm-dev libsqlite3-dev libtool pkg-config sqlite3 libncurses5-dev \
libreadline-dev gnupg

ARG GO_VERSION=1.22.10
RUN wget https://go.dev/dl/go${GO_VERSION}.linux-amd64.tar.gz && \
tar -C /usr/local -xzf go${GO_VERSION}.linux-amd64.tar.gz
ENV PATH=$PATH:/usr/local/go/bin



ARG GH_VERSION=2.63.2
RUN wget https://github.com/cli/cli/releases/download/v${GH_VERSION}/gh_${GH_VERSION}_linux_amd64.deb && \
dpkg -i gh_${GH_VERSION}_linux_amd64.deb

COPY --from=node /usr/local/lib /usr/local/lib
COPY --from=node /usr/local/bin /usr/local/bin
COPY --from=node /opt /opt


ENV PATH=$PATH:/usr/local/bin

ARG RUBY_VERSION=3.2.2
RUN curl -sSL https://get.rvm.io | bash
RUN /bin/bash -l -c "rvm install ruby-${RUBY_VERSION} && rvm --default use ruby-${RUBY_VERSION}"
32 changes: 15 additions & 17 deletions tools/update_examples.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,15 @@ import (
"os"
"os/exec"
"path/filepath"
"regexp"
"slices"
"strconv"
"strings"

"github.com/grafana/regexp"
)

var ghToken string

// this program requires gh cli, bundle, go to be installed
// todo run it by cron & create a PR if needed
// this program requires ruby, bundle, yarn, go to be installed
func main() {

getGHToken()
Expand All @@ -34,11 +32,11 @@ func main() {
}

func getGHToken() {
ghToken, _ = s.sh("gh auth token")
ghToken = os.Getenv("GITHUB_TOKEN")
}

func extractNodeJSVersion(tag Tag) *version {
re := regexp.MustCompile("(v)(\\d+).(\\d+).(\\d+)")
re := regexp.MustCompile(`(v)(\d+).(\d+).(\d+)`)
match := re.FindStringSubmatch(tag.Name)
if match != nil {
if match[1] == "v" {
Expand Down Expand Up @@ -73,19 +71,19 @@ func updateDotnet() {
last := tags[len(tags)-1]
fmt.Println(last)

reDockerGlibc := regexp.MustCompile("pyroscope/pyroscope-dotnet:\\d+\\.\\d+\\.\\d+-glibc")
reDockerGlibc := regexp.MustCompile(`pyroscope/pyroscope-dotnet:\d+\.\d+\.\d+-glibc`)
replDockerGlibc := fmt.Sprintf("pyroscope/pyroscope-dotnet:%s-glibc", last.version())
replaceInplace(reDockerGlibc, "examples/language-sdk-instrumentation/dotnet/fast-slow/Dockerfile", replDockerGlibc)
replaceInplace(reDockerGlibc, "examples/language-sdk-instrumentation/dotnet/rideshare/Dockerfile", replDockerGlibc)
replaceInplace(reDockerGlibc, "examples/language-sdk-instrumentation/dotnet/web-new/Dockerfile", replDockerGlibc)
replaceInplace(reDockerGlibc, "docs/sources/configure-client/language-sdks/dotnet.md", replDockerGlibc)

reDockerMusl := regexp.MustCompile("pyroscope/pyroscope-dotnet:\\d+\\.\\d+\\.\\d+-musl")
reDockerMusl := regexp.MustCompile(`pyroscope/pyroscope-dotnet:\d+\.\d+\.\d+-musl`)
replDockerMusl := fmt.Sprintf("pyroscope/pyroscope-dotnet:%s-musl", last.version())
replaceInplace(reDockerMusl, "examples/language-sdk-instrumentation/dotnet/fast-slow/musl.Dockerfile", replDockerMusl)
replaceInplace(reDockerMusl, "examples/language-sdk-instrumentation/dotnet/rideshare/musl.Dockerfile", replDockerMusl)

reUrl := regexp.MustCompile("https://github\\.com/grafana/pyroscope-dotnet/releases/download/v\\d+\\.\\d+\\.\\d+-pyroscope/pyroscope.\\d+\\.\\d+\\.\\d+-glibc-x86_64.tar.gz")
reUrl := regexp.MustCompile(`https://github\.com/grafana/pyroscope-dotnet/releases/download/v\d+\.\d+\.\d+-pyroscope/pyroscope.\d+\.\d+\.\d+-glibc-x86_64.tar.gz`)
replUrl := fmt.Sprintf("https://github.com/grafana/pyroscope-dotnet/releases/download/v%s-pyroscope/pyroscope.%s-glibc-x86_64.tar.gz", last.version(), last.version())
replaceInplace(reUrl, "docs/sources/configure-client/language-sdks/dotnet.md", replUrl)
}
Expand All @@ -95,7 +93,7 @@ func updatePython() {
last := tags[len(tags)-1]
fmt.Println(last)

re := regexp.MustCompile("pyroscope-io==\\d+\\.\\d+\\.\\d+")
re := regexp.MustCompile(`pyroscope-io==\d+\.\d+\.\d+`)
repl := fmt.Sprintf("pyroscope-io==%s", last.version())
replaceInplace(re, "examples/language-sdk-instrumentation/python/simple/requirements.txt", repl)
replaceInplace(re, "examples/language-sdk-instrumentation/python/rideshare/flask/Dockerfile", repl)
Expand All @@ -109,7 +107,7 @@ func updateRuby() {
last := tags[len(tags)-1]
fmt.Println(last)

re := regexp.MustCompile("gem ['\"]pyroscope['\"].*")
re := regexp.MustCompile(`gem ['"]pyroscope['"].*`)
repl := fmt.Sprintf("gem 'pyroscope', '= %s'", last.version())
replaceInplace(re, "examples/language-sdk-instrumentation/ruby/rideshare/Gemfile", repl)
replaceInplace(re, "examples/language-sdk-instrumentation/ruby/rideshare_rails/Gemfile", repl)
Expand All @@ -124,18 +122,18 @@ func updateJava() {
tags := getTagsV("grafana/pyroscope-java", extractGoVersion(""))
last := tags[len(tags)-1]
fmt.Println(last)
reJarURL := regexp.MustCompile("https://github\\.com/grafana/pyroscope-java/releases/download/(v\\d+\\.\\d+\\.\\d+)/pyroscope\\.jar")
reJarURL := regexp.MustCompile(`https://github\.com/grafana/pyroscope-java/releases/download/(v\d+\.\d+\.\d+)/pyroscope\.jar`)
lastJarURL := "https://github.com/grafana/pyroscope-java/releases/download/" + last.versionV() + "/pyroscope.jar"
replaceInplace(reJarURL, "examples/language-sdk-instrumentation/java/fib/Dockerfile", lastJarURL)
replaceInplace(reJarURL, "examples/language-sdk-instrumentation/java/simple/Dockerfile", lastJarURL)
replaceInplace(reJarURL, "examples/language-sdk-instrumentation/java/rideshare/Dockerfile", lastJarURL)

reGradelDep := regexp.MustCompile("implementation\\(\"io\\.pyroscope:agent:\\d+\\.\\d+\\.\\d+\"\\)")
reGradelDep := regexp.MustCompile(`implementation\("io\.pyroscope:agent:\d+\.\d+\.\d+"\)`)
lastGradleDep := fmt.Sprintf("implementation(\"io.pyroscope:agent:%s\")", last.version())
replaceInplace(reGradelDep, "examples/language-sdk-instrumentation/java/rideshare/build.gradle.kts", lastGradleDep)
replaceInplace(reGradelDep, "docs/sources/configure-client/language-sdks/java.md", lastGradleDep)

reMaven := regexp.MustCompile("<version>\\d+\\.\\d+\\.\\d+</version>")
reMaven := regexp.MustCompile(`<version>\d+\.\d+\.\d+</version>`)
replMaven := fmt.Sprintf("<version>%s</version>", last.version())
replaceInplace(reMaven, "docs/sources/configure-client/language-sdks/java.md", replMaven)

Expand Down Expand Up @@ -176,7 +174,7 @@ func updateGolang() {

func extractGoVersion(module string) func(tag Tag) *version {
return func(tag Tag) *version {
re := regexp.MustCompile("([^/]*)/?v(\\d+).(\\d+).(\\d+)")
re := regexp.MustCompile(`([^/]*)/?v(\d+).(\d+).(\d+)`)
match := re.FindStringSubmatch(tag.Name)
if match != nil {
//fmt.Println(len(match), match)
Expand All @@ -196,7 +194,7 @@ func extractGoVersion(module string) func(tag Tag) *version {

func extractRSVersion(module string) func(tag Tag) *version {
return func(tag Tag) *version {
re := regexp.MustCompile("(\\S+)-(\\d+).(\\d+).(\\d+)")
re := regexp.MustCompile(`(\S+)-(\d+).(\d+).(\d+)`)
match := re.FindStringSubmatch(tag.Name)
if match != nil {
//fmt.Println(len(match), match)
Expand All @@ -216,7 +214,7 @@ func extractRSVersion(module string) func(tag Tag) *version {

func extractDotnetVersion() func(tag Tag) *version {
return func(tag Tag) *version {
re := regexp.MustCompile("v(\\d+).(\\d+).(\\d+)-pyroscope")
re := regexp.MustCompile(`v(\d+).(\d+).(\d+)-pyroscope`)
match := re.FindStringSubmatch(tag.Name)
if match != nil {
fmt.Println(len(match), match)
Expand Down
Loading