Skip to content

Commit 81ea45d

Browse files
committed
Change update schedule of repos
Use Default Action and Version when not provided
1 parent 710f3b9 commit 81ea45d

File tree

9 files changed

+100
-59
lines changed

9 files changed

+100
-59
lines changed

go.mod

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ go 1.21
55
toolchain go1.22.7
66

77
require (
8+
github.com/Masterminds/sprig/v3 v3.3.0
89
github.com/ghodss/yaml v1.0.0
910
github.com/openshift/ci-tools v0.0.0-20231129005518-2ec9d62902e9
1011
gopkg.in/yaml.v2 v2.4.0
@@ -19,7 +20,10 @@ require (
1920
cloud.google.com/go/storage v1.29.0 // indirect
2021
contrib.go.opencensus.io/exporter/ocagent v0.7.1-0.20200907061046-05415f1de66d // indirect
2122
contrib.go.opencensus.io/exporter/prometheus v0.4.0 // indirect
23+
dario.cat/mergo v1.0.1 // indirect
2224
github.com/GoogleCloudPlatform/testgrid v0.0.123 // indirect
25+
github.com/Masterminds/goutils v1.1.1 // indirect
26+
github.com/Masterminds/semver/v3 v3.3.0 // indirect
2327
github.com/andygrunwald/go-jira v1.14.0 // indirect
2428
github.com/aws/aws-sdk-go v1.44.116 // indirect
2529
github.com/beorn7/perks v1.0.1 // indirect
@@ -50,13 +54,13 @@ require (
5054
github.com/gomodule/redigo v1.8.5 // indirect
5155
github.com/google/btree v1.0.1 // indirect
5256
github.com/google/gnostic v0.6.9 // indirect
53-
github.com/google/go-cmp v0.5.9 // indirect
57+
github.com/google/go-cmp v0.6.0 // indirect
5458
github.com/google/go-containerregistry v0.15.2 // indirect
5559
github.com/google/go-querystring v1.1.0 // indirect
5660
github.com/google/gofuzz v1.2.1-0.20210504230335-f78f29fc09ea // indirect
5761
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 // indirect
5862
github.com/google/s2a-go v0.1.3 // indirect
59-
github.com/google/uuid v1.3.0 // indirect
63+
github.com/google/uuid v1.6.0 // indirect
6064
github.com/google/wire v0.4.0 // indirect
6165
github.com/googleapis/enterprise-certificate-proxy v0.2.3 // indirect
6266
github.com/googleapis/gax-go v2.0.2+incompatible // indirect
@@ -67,13 +71,16 @@ require (
6771
github.com/hashicorp/go-multierror v1.1.1 // indirect
6872
github.com/hashicorp/go-retryablehttp v0.7.2 // indirect
6973
github.com/hashicorp/golang-lru v0.5.4 // indirect
74+
github.com/huandu/xstrings v1.5.0 // indirect
7075
github.com/imdario/mergo v0.3.16 // indirect
7176
github.com/jmespath/go-jmespath v0.4.0 // indirect
7277
github.com/josharian/intern v1.0.0 // indirect
7378
github.com/json-iterator/go v1.1.12 // indirect
7479
github.com/mailru/easyjson v0.7.7 // indirect
7580
github.com/mattn/go-zglob v0.0.2 // indirect
7681
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
82+
github.com/mitchellh/copystructure v1.2.0 // indirect
83+
github.com/mitchellh/reflectwalk v1.0.2 // indirect
7784
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
7885
github.com/modern-go/reflect2 v1.0.2 // indirect
7986
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
@@ -86,9 +93,11 @@ require (
8693
github.com/prometheus/common v0.44.0 // indirect
8794
github.com/prometheus/procfs v0.10.1 // indirect
8895
github.com/prometheus/statsd_exporter v0.21.0 // indirect
96+
github.com/shopspring/decimal v1.4.0 // indirect
8997
github.com/shurcooL/githubv4 v0.0.0-20210725200734-83ba7b4c9228 // indirect
9098
github.com/shurcooL/graphql v0.0.0-20181231061246-d48a9a75455f // indirect
9199
github.com/sirupsen/logrus v1.9.2 // indirect
100+
github.com/spf13/cast v1.7.0 // indirect
92101
github.com/spf13/pflag v1.0.5 // indirect
93102
github.com/tektoncd/pipeline v0.48.0 // indirect
94103
github.com/trivago/tgo v1.0.7 // indirect
@@ -98,14 +107,14 @@ require (
98107
go.uber.org/zap v1.24.0 // indirect
99108
go4.org v0.0.0-20201209231011-d4a079459e60 // indirect
100109
gocloud.dev v0.19.0 // indirect
101-
golang.org/x/crypto v0.14.0 // indirect
110+
golang.org/x/crypto v0.26.0 // indirect
102111
golang.org/x/exp v0.0.0-20230307190834-24139beb5833 // indirect
103-
golang.org/x/net v0.17.0 // indirect
112+
golang.org/x/net v0.21.0 // indirect
104113
golang.org/x/oauth2 v0.8.0 // indirect
105-
golang.org/x/sync v0.5.0 // indirect
106-
golang.org/x/sys v0.13.0 // indirect
107-
golang.org/x/term v0.13.0 // indirect
108-
golang.org/x/text v0.13.0 // indirect
114+
golang.org/x/sync v0.8.0 // indirect
115+
golang.org/x/sys v0.23.0 // indirect
116+
golang.org/x/term v0.23.0 // indirect
117+
golang.org/x/text v0.17.0 // indirect
109118
golang.org/x/time v0.3.0 // indirect
110119
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
111120
gomodules.xyz/jsonpatch/v2 v2.3.0 // indirect

go.sum

Lines changed: 40 additions & 20 deletions
Large diffs are not rendered by default.

hack/release-manager.sh

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ ROOT="$(dirname "$SCRIPT_DIR")"
99
source $SCRIPT_DIR/common-functions.sh
1010

1111
# Default values
12-
ACTION="update-upstream-versions"
13-
VERSION="next"
14-
ENVIRONMENT="dev"
12+
DEFAULT_ACTION="update-upstream-versions"
13+
DEFAULT_VERSION="next"
14+
ACTION=""
15+
VERSION=""
1516

1617

1718
help() {
@@ -56,10 +57,6 @@ while [[ $# -gt 0 ]]; do
5657
VERSION="$2"
5758
shift 2
5859
;;
59-
--env|--environment | -e)
60-
ENVIRONMENT="$2"
61-
shift 2
62-
;;
6360
--help|-h)
6461
help
6562
;;
@@ -70,10 +67,14 @@ while [[ $# -gt 0 ]]; do
7067
esac
7168
done
7269

73-
# Validate required params
74-
if [[ -z "$ACTION" || -z "$VERSION" ]]; then
75-
echo "Missing required parameters!"
76-
help
70+
# Use Default Values for required params
71+
if [[ -z "$ACTION" ]]; then
72+
echo "Using default action $DEFAULT_ACTION!"
73+
ACTION=$DEFAULT_ACTION
74+
fi
75+
if [[ -z "$VERSION" ]]; then
76+
echo "Using default version $DEFAULT_VERSION!"
77+
VERSION=$DEFAULT_VERSION
7778
fi
7879

7980
# Call specific function based on ACTION

internal/konflux/git.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,17 @@ func cloneAndCheckout(ctx context.Context, repo Repository, targetDir string) (s
2424
}
2525
if exists {
2626
// Repository exists, fetch the latest changes
27-
if out, err := run(ctx, dir, "rm", "-rf", dir); err != nil {
28-
return dir, fmt.Errorf("failed to delete exisiting dir: %s, Error: %v, Output: %v", dir, err, out)
27+
if out, err := run(ctx, dir, "git", "fetch", "--all"); err != nil {
28+
return dir, fmt.Errorf("failed to fetch repository: %s, %s", err, out)
29+
}
30+
} else {
31+
// Repository does not exist, clone the repository
32+
if err := os.MkdirAll(dir, 0755); err != nil {
33+
return "", err
34+
}
35+
if out, err := run(ctx, dir, "git", "clone", repo.Url, "."); err != nil {
36+
return dir, fmt.Errorf("failed to clone repository: %s, %s", err, out)
2937
}
30-
}
31-
// Repository does not exist, clone the repository
32-
if err := os.MkdirAll(dir, 0755); err != nil {
33-
return "", err
34-
}
35-
if out, err := run(ctx, dir, "git", "clone", repo.Url, "."); err != nil {
36-
return dir, fmt.Errorf("failed to clone repository: %s, %s", err, out)
3738
}
3839

3940
if out, err := run(ctx, dir, "git", "reset", "--hard", "HEAD", "--"); err != nil {

internal/konflux/go-templates.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010
"regexp"
1111
"strings"
1212
"text/template"
13+
14+
"github.com/Masterminds/sprig/v3"
1315
)
1416

1517
//go:embed templates/*/*.yaml templates/*/*/*.yaml
@@ -43,6 +45,10 @@ func generateFileFromTemplate(templateFile string, data interface{}, filePath st
4345
"contains": strings.Contains,
4446
"eval": Eval,
4547
}
48+
// merge Sprig funcs into your map
49+
for k, v := range sprig.FuncMap() {
50+
funcMap[k] = v
51+
}
4652
tmpl, err := template.New(templateFile).Funcs(funcMap).ParseFS(templateFS, "templates/*/*.yaml", "templates/*/*/*.yaml")
4753
if err != nil {
4854
return err

internal/konflux/templates/github/workflows/update-sources.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
name: update-sources-{{.Name}}
2-
2+
{{- $minorVersion := "0" -}}
3+
{{- $versionParts := splitList "." .Application.Release.Version }}
4+
{{- if ge (len $versionParts) 2 }}
5+
{{- $minorVersion = index $versionParts 1 -}}
6+
{{- end }}
37
on:
48
workflow_dispatch: {}
59
schedule:
6-
- cron: "0 1 * * *" # At 1AM everyday
10+
- cron: "0 {{add (mod $minorVersion 23) 1}} * * *" # At {{add (mod $minorVersion 24) 1}}:00 everyday
711

812
jobs:
913

internal/konflux/templates/konflux/tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ spec:
1010
name: application
1111
params:
1212
- name: POLICY_CONFIGURATION
13-
value: {{- if not (contains .Name "index") }} tekton-ecosystem-tenant/tekton-ecosystem-tenant-containers {{- else}} tekton-ecosystem-tenant/tekton-ecosystem-tenant-indexes {{- end}}
13+
value: {{- if not (contains "index" .Name ) }} tekton-ecosystem-tenant/tekton-ecosystem-tenant-containers {{- else}} tekton-ecosystem-tenant/tekton-ecosystem-tenant-indexes {{- end}}
1414
- name: TIMEOUT
1515
value: "15m0s"
1616
- name: SINGLE_COMPONENT

internal/konflux/templates/tekton/component-pull-request.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ kind: PipelineRun
33
metadata:
44
annotations:
55
pipelinesascode.tekton.dev/cancel-in-progress: "true" # Cancel in-progress pipelines
6-
{{- if and (ne .Repository.Branch.Name "main") (contains .Name "index") }}
6+
{{- if and (ne .Repository.Branch.Name "main") (contains "index" .Name ) }}
77
pipelinesascode.tekton.dev/pipeline: "https://raw.githubusercontent.com/openshift-pipelines/operator/refs/heads/main/.tekton/fbc-build.yaml"
88
{{- else }}{{- if or (ne .Repository.Branch.Name "main") (ne .Repository.Name "tektoncd-operator") }}
99
pipelinesascode.tekton.dev/pipeline: "https://raw.githubusercontent.com/openshift-pipelines/operator/refs/heads/main/.tekton/docker-build-ta.yaml"
@@ -45,18 +45,18 @@ spec:
4545
- name: build-platforms
4646
value:
4747
- linux/x86_64
48-
{{- if eq .Name "bundle" }}
48+
{{- if eq "bundle" .Name }}
4949
- name: build-image-index
5050
value: false
5151
{{end }}
52-
{{- if not (contains .Name "index") }}
52+
{{- if not (contains "index" .Name) }}
5353
- name: prefetch-input
5454
value: |
5555
{{.PrefetchInput}}
5656
{{- end }}
5757
pipelineRef:
5858
name:
59-
{{- if not (contains .Name "index") }} docker-build-ta
59+
{{- if not (contains "index" .Name) }} docker-build-ta
6060
{{- else}} fbc-build {{- end }}
6161
taskRunTemplate:
6262
serviceAccountName: build-pipeline-{{basename .Repository.Name | hyphenize}}-{{hyphenize .Name}}-{{hyphenize .Version.Version}}

internal/konflux/templates/tekton/component-push.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ kind: PipelineRun
33
metadata:
44
annotations:
55
pipelinesascode.tekton.dev/cancel-in-progress: "true" # Cancel in-progress pipelines
6-
{{- if and (ne .Repository.Branch.Name "main") (contains .Name "index") }}
6+
{{- if and (ne .Repository.Branch.Name "main") (contains "index" .Name) }}
77
pipelinesascode.tekton.dev/pipeline: "https://raw.githubusercontent.com/openshift-pipelines/operator/refs/heads/main/.tekton/fbc-build.yaml"
88
{{- else }}{{- if or (ne .Repository.Branch.Name "main") (ne .Repository.Name "operator") }}
99
pipelinesascode.tekton.dev/pipeline: "https://raw.githubusercontent.com/openshift-pipelines/operator/refs/heads/main/.tekton/docker-build-ta.yaml"
@@ -43,20 +43,20 @@ spec:
4343
value:
4444
- "{{- .Version.Version}}"
4545
- "{{- .Application.Release.PatchVersion}}"
46-
{{- if contains (printf "%s-%s-%s" (basename .Repository.Name | hyphenize) (hyphenize .Version.Version) .Name) "bundle" }}
46+
{{- if contains "bundle" .Name }}
4747
- name: build-platforms
4848
value:
4949
- linux/x86_64
5050
- name: build-image-index
5151
value: false
5252
{{- end }}
53-
{{- if not (contains .Name "index") }}
53+
{{- if not (contains "index" .Name) }}
5454
- name: prefetch-input
5555
value: |
5656
{{.PrefetchInput}}
5757
{{- end }}
5858
pipelineRef:
59-
name: {{- if not (contains .Name "index") }} docker-build-ta {{- else}} fbc-build {{- end }}
59+
name: {{- if not (contains "index" .Name ) }} docker-build-ta {{- else}} fbc-build {{- end }}
6060
taskRunTemplate:
6161
serviceAccountName: build-pipeline-{{basename .Repository.Name | hyphenize}}-{{hyphenize .Name}}-{{hyphenize .Version.Version}}
6262
workspaces:

0 commit comments

Comments
 (0)