Skip to content

Commit

Permalink
cmd/konflux: add support for release branches
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Demeester <[email protected]>
  • Loading branch information
vdemeester committed Sep 18, 2024
1 parent b43763b commit 8e5ab6b
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 28 deletions.
69 changes: 46 additions & 23 deletions cmd/konflux/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ import (
var templateFS embed.FS

type Application struct {
Name string
Repository string
Upstream string
Branch string
Components []string
Name string
Repository string
Upstream string
Branch string
UpstreamBranch string
Components []string
}

type Component struct {
Expand All @@ -35,6 +36,12 @@ type Config struct {
Repository string
Upstream string
Components []string
Branches []Branch
}

type Branch struct {
Version string
Upstream string
}

func main() {
Expand All @@ -52,40 +59,59 @@ func main() {
}

app := Application{
Name: c.Repository,
Repository: path.Join("openshift-pipelines", c.Repository),
Upstream: c.Upstream,
Components: c.Components,
Branch: "main",
Name: c.Repository,
Repository: path.Join("openshift-pipelines", c.Repository),
Upstream: c.Upstream,
Components: c.Components,
Branch: "main",
UpstreamBranch: "main",
}

// FIXME: support release branches next for konflux
if err := generateKonflux(app, "main", filepath.Join(*target, ".konflux")); err != nil {
log.Println("Generate configurations for main branch")
if err := generateKonflux(app, filepath.Join(*target, ".konflux")); err != nil {
log.Fatalln(err)
}
if err := generateGitHub(app, filepath.Join(*target, ".github")); err != nil {
log.Fatalln(err)
}
for _, branch := range c.Branches {
log.Printf("Generate configurations for %s branch\n", branch.Version)

app := Application{
Name: c.Repository,
Repository: path.Join("openshift-pipelines", c.Repository),
Upstream: c.Upstream,
Components: c.Components,
Branch: fmt.Sprintf("release-v%s.x", branch.Version),
UpstreamBranch: branch.Upstream,
}
if err := generateKonflux(app, filepath.Join(*target, ".konflux")); err != nil {
log.Fatalln(err)
}
if err := generateGitHub(app, filepath.Join(*target, ".github")); err != nil {
log.Fatalln(err)
}
}
}

func generateKonflux(application Application, branch, target string) error {
func generateKonflux(application Application, target string) error {
log.Printf("Generate konflux manifest in %s\n", target)
if err := os.MkdirAll(filepath.Join(target, branch), 0o755); err != nil {
if err := os.MkdirAll(filepath.Join(target, application.Branch), 0o755); err != nil {
return err
}
if err := generateFileFromTemplate("application.yaml", application, filepath.Join(target, branch, "application.yaml")); err != nil {
if err := generateFileFromTemplate("application.yaml", application, filepath.Join(target, application.Branch, "application.yaml")); err != nil {
return err
}
if err := generateFileFromTemplate("tests.yaml", application, filepath.Join(target, branch, "tests.yaml")); err != nil {
if err := generateFileFromTemplate("tests.yaml", application, filepath.Join(target, application.Branch, "tests.yaml")); err != nil {
return err
}
for _, c := range application.Components {
if err := generateFileFromTemplate("component.yaml", Component{
Name: c,
Application: application.Name,
Repository: application.Repository,
Branch: "main",
}, filepath.Join(target, branch, fmt.Sprintf("component-%s.yaml", c))); err != nil {
Branch: application.Branch,
}, filepath.Join(target, application.Branch, fmt.Sprintf("component-%s.yaml", c))); err != nil {
return err
}
}
Expand All @@ -97,13 +123,10 @@ func generateGitHub(application Application, target string) error {
if err := os.MkdirAll(filepath.Join(target, "workflows"), 0o755); err != nil {
return err
}
if err := generateFileFromTemplate("update-sources.yaml", application, filepath.Join(target, "workflows", "update-sources.yaml")); err != nil {
filename := fmt.Sprintf("update-sources.%s.yaml", application.Branch)
if err := generateFileFromTemplate("update-sources.yaml", application, filepath.Join(target, "workflows", filename)); err != nil {
return err
}
// FIXME: figure out how to map release branch with upstream release branches
// if err := generateFileFromTemplate("update-sources-branches.yaml", application, filepath.Join(target, "workflows", "update-sources-branches.yaml")); err != nil {
// return err
// }
return nil
}

Expand Down
13 changes: 8 additions & 5 deletions cmd/konflux/templates/github/workflows/update-sources.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: update-sources
name: update-sources-{{.Branch}}

on:
workflow_dispatch: {}
Expand All @@ -21,12 +21,15 @@ jobs:
run: |
rm -fR upstream
git clone https://github.com/{{.Upstream}} upstream
pushd upstream
git checkout -b {{.UpstreamBranch}} origin/{{.UpstreamBranch}}
popd
- name: Commit new changes
run: |
git config user.name github-actions
git config user.email [email protected]
git checkout -b actions/update/sources-main
git checkout -b actions/update/sources-{{.Branch}}
pushd upstream
OLD_COMMIT=$(cat ../head)
NEW_COMMIT=$(git rev-parse HEAD)
Expand All @@ -49,13 +52,13 @@ jobs:
https://github.com/{{.Upstream}}/compare/${NEW_COMMIT}..${OLD_COMMIT}
EOF
git push -f origin actions/update/sources-main
git push -f origin actions/update/sources-{{.Branch}}
- name: Create pull request
run: |
if [ "$(gh pr list --base main --head actions/update/sources-main --json url --jq 'length')" = "0" ]; then
if [ "$(gh pr list --base {{.Branch}} --head actions/update/sources-{{.Branch}} --json url --jq 'length')" = "0" ]; then
echo "creating PR..."
gh pr create -B main -H actions/update/sources-main --fill
gh pr create -B {{.Branch}} -H actions/update/sources-{{.Branch}} --fill
else
echo "a PR already exists, skipping..."
fi
Expand Down
3 changes: 3 additions & 0 deletions config/konflux/tektoncd-pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ components:
- sidecarlogresults
- webhook
- workingdirinit
branches:
- version: 1.16
upstream: release-v0.62.x

0 comments on commit 8e5ab6b

Please sign in to comment.