Skip to content

Commit

Permalink
chore: add version update mechanism for ci dependencies
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Sagi-Kazar <[email protected]>
  • Loading branch information
sagikazarmark committed Aug 11, 2024
1 parent 7658cbf commit 35fcd7e
Show file tree
Hide file tree
Showing 8 changed files with 148 additions and 20 deletions.
100 changes: 100 additions & 0 deletions ci/dev.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package main

import (
"bytes"
"context"
"strings"

"github.com/dave/jennifer/jen"
"github.com/google/go-github/v63/github"

"github.com/openmeterio/openmeter/ci/internal/dagger"
)

func (m *Ci) Dev() *Dev {
return &Dev{
Source: m.Source,
}
}

type Dev struct {
Source *dagger.Directory
}

// Udate dependency versions used in CI.
func (m *Dev) UpdateVersions(
ctx context.Context,

// +optional
githubToken *dagger.Secret,
) (*dagger.File, error) {
githubClient := github.NewClient(nil)

if githubToken != nil {
token, err := githubToken.Plaintext(ctx)
if err != nil {
return nil, err
}

githubClient = githubClient.WithAuthToken(token)
}

versions := make(map[string]string)

// GolangCI Lint
{
release, _, err := githubClient.Repositories.GetLatestRelease(ctx, "golangci", "golangci-lint")
if err != nil {
return nil, err
}

versions["golangciLint"] = release.GetTagName()
}

// Helm
{
release, _, err := githubClient.Repositories.GetLatestRelease(ctx, "helm", "helm")
if err != nil {
return nil, err
}

versions["helm"] = strings.TrimPrefix(release.GetTagName(), "v")
}

// Helm docs
{
release, _, err := githubClient.Repositories.GetLatestRelease(ctx, "norwoodj", "helm-docs")
if err != nil {
return nil, err
}

versions["helmDocs"] = release.GetTagName()
}

// Spectral
{
release, _, err := githubClient.Repositories.GetLatestRelease(ctx, "stoplightio", "spectral")
if err != nil {
return nil, err
}

versions["spectral"] = strings.TrimPrefix(release.GetTagName(), "v")
}

f := jen.NewFile("main")

f.Const().DefsFunc(func(g *jen.Group) {
for tool, version := range versions {
g.Id(tool + "Version").Op("=").Lit(version)
}
})

var buf bytes.Buffer

err := f.Render(&buf)
if err != nil {
return nil, err
}

return dag.Directory().WithNewFile("versions.go", buf.String()).File("versions.go"), nil
}
3 changes: 3 additions & 0 deletions ci/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ go 1.22.5
require (
github.com/99designs/gqlgen v0.17.49
github.com/Khan/genqlient v0.7.0
github.com/dave/jennifer v1.7.0
github.com/google/go-github/v63 v63.0.0
github.com/sourcegraph/conc v0.3.0
github.com/vektah/gqlparser/v2 v2.5.16
go.opentelemetry.io/otel v1.28.0
Expand All @@ -27,6 +29,7 @@ require (
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
Expand Down
8 changes: 8 additions & 0 deletions ci/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 h1:bvNMNQO63//z+xNg
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8=
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/dave/jennifer v1.7.0 h1:uRbSBH9UTS64yXbh4FrMHfgfY762RD+C7bUPKODpSJE=
github.com/dave/jennifer v1.7.0/go.mod h1:nXbxhEmQfOZhWml3D1cDK5M1FLnMSozpbFN/m3RmGZc=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
Expand All @@ -15,8 +17,13 @@ github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-github/v63 v63.0.0 h1:13xwK/wk9alSokujB9lJkuzdmQuVn2QCPeck76wR3nE=
github.com/google/go-github/v63 v63.0.0/go.mod h1:IqbcrgUmIcEaioWrGYei/09o+ge5vhffGOcxrO0AfmA=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 h1:bkypFPDjIYGfCYD5mRBvpqxfYX1YCS1PXdKYWi8FsN0=
Expand Down Expand Up @@ -77,6 +84,7 @@ golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/genproto/googleapis/api v0.0.0-20240701130421-f6361c86f094 h1:0+ozOGcrp+Y8Aq8TLNN2Aliibms5LEzsq99ZZmAGYm0=
google.golang.org/genproto/googleapis/api v0.0.0-20240701130421-f6361c86f094/go.mod h1:fJ/e3If/Q67Mj99hin0hMhiNyCRmt6BQ2aWIJshUSJw=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094 h1:BwIjyKYGsK9dMCBOorzRri8MQwmi7mT9rGHsCEinZkA=
Expand Down
19 changes: 0 additions & 19 deletions ci/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,6 @@ import (
"github.com/openmeterio/openmeter/ci/internal/dagger"
)

const (
// Alpine is required for our current build (due to Kafka and CGO), but it doesn't seem to work well with golangci-lint
goVersion = "1.22.5"
goBuildVersion = goVersion + "-alpine3.19@sha256:0642d4f809abf039440540de1f0e83502401686e3946ed8e7398a1d94648aa6d"
xxBaseImage = "tonistiigi/xx:1.4.0@sha256:0cd3f05c72d6c9b038eb135f91376ee1169ef3a330d34e418e65e2a5c2e9c0d4"

golangciLintVersion = "v1.59.1"
spectralVersion = "6.11"
kafkaVersion = "3.6"
clickhouseVersion = "24.5.5.78"
redisVersion = "7.0.12"
postgresVersion = "14.9"

helmDocsVersion = "v1.14.2"
helmVersion = "3.15.2"

alpineBaseImage = "alpine:3.20.1@sha256:b89d9c93e9ed3597455c90a0b88a8bbb5cb7188438f70953fede212a0c4394e0"
)

type Ci struct {
// Project source directory
// This will become useful once pulling from remote becomes available
Expand Down
8 changes: 8 additions & 0 deletions ci/versions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package main

const (
golangciLintVersion = "v1.59.1"
helmVersion = "3.15.3"
helmDocsVersion = "v1.14.2"
spectralVersion = "6.11.1"
)
19 changes: 19 additions & 0 deletions ci/versions_pinned.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package main

const (
// Alpine is required for our current build (due to Kafka and CGO), but it doesn't seem to work well with golangci-lint
goVersion = "1.22.5"

kafkaVersion = "3.6"
clickhouseVersion = "24.5.5.78"
redisVersion = "7.0.12"
postgresVersion = "14.9"

// TODO: add update mechanism for versions below

// Alpine is required for our current build (due to Kafka and CGO), but it doesn't seem to work well with golangci-lint
goBuildVersion = goVersion + "-alpine3.19@sha256:0642d4f809abf039440540de1f0e83502401686e3946ed8e7398a1d94648aa6d"
xxBaseImage = "tonistiigi/xx:1.4.0@sha256:0cd3f05c72d6c9b038eb135f91376ee1169ef3a330d34e418e65e2a5c2e9c0d4"

alpineBaseImage = "alpine:3.20.1@sha256:b89d9c93e9ed3597455c90a0b88a8bbb5cb7188438f70953fede212a0c4394e0"
)
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ services:
# Credit
# docker compose --profile postgres up
postgres:
image: postgres:15.3
image: postgres:14.9
profiles:
- postgres
ports:
Expand Down
9 changes: 9 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
[private]
default:
@just --list

# tag and release a new version
release:
#!/usr/bin/env bash
set -euo pipefail
Expand All @@ -23,3 +28,7 @@ release:

git tag -m "Release ${version}" $version
git push origin $version

# update CI dependency versions
update-versions:
dagger call --source .:default dev update-versions export --path ci/versions.go

0 comments on commit 35fcd7e

Please sign in to comment.