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
19 changes: 19 additions & 0 deletions .github/workflows/bulk-import-git-repos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Bulk Import Git Repos workflow container image and manifest push

on:
workflow_dispatch:
push:
branches: [ "main" ]
paths:
- 'workflows/experimentals/bulk-import-git-repos/**'
- 'pipeline/**'
- 'scripts/**'
- .github/workflows/bulk-import-git-repos.yml
- .github/workflows/main.yml

jobs:
bulk-import-git-repos:
uses: ./.github/workflows/main.yml
with:
workflow_id: bulk-import-git-repos
secrets: inherit
14 changes: 10 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,17 @@ save-oci: build-image
# Description: Generates the k8s manifests for the WORKFLOW_ID workflow under the configured WORKDIR.
# Depends on: prepare-workdir target.
# Usage: make gen-manifests
# Optional: WORKFLOW_SUBDIR — when set, first arg is workflows/$(WORKFLOW_SUBDIR); when unset, workflows/$(WORKFLOW_ID)
# make WORKFLOW_ID=bulk-import-git-repos WORKFLOW_SUBDIR=bulk-import-git-repos/src/main/resources gen-manifests
GEN_MANIFESTS_WORKFLOW_FOLDER = workflows/$(if $(WORKFLOW_SUBDIR),$(WORKFLOW_SUBDIR),$(WORKFLOW_ID))
gen-manifests: prepare-workdir
cd $(WORKDIR)
$(CONTAINER_ENGINE) run --rm -v $(WORKDIR):/workdir:Z -w /workdir \
$(LINUX_IMAGE) /bin/bash -c "ENABLE_PERSISTENCE=$(ENABLE_PERSISTENCE) WORKFLOW_IMAGE_TAG=$(IMAGE_TAG) ${SCRIPTS_DIR}/gen_manifests.sh workflows/$(WORKFLOW_ID) $(WORKFLOW_ID)"
@echo "Manifests are available in workdir $(WORKDIR)/workflows/$(WORKFLOW_ID)/manifests"
@# Ensure WORKDIR exists and is accessible (important for macOS Podman)
@test -d $(WORKDIR) || mkdir -p $(WORKDIR)
@# Use absolute path for volume mount (required for Podman on macOS)
@# On macOS, use realpath or fallback to WORKDIR if realpath fails
@$(CONTAINER_ENGINE) run --rm -v "$(shell realpath $(WORKDIR) 2>/dev/null || echo $(WORKDIR)):/workdir:Z" -w /workdir \
$(LINUX_IMAGE) /bin/bash -c "ENABLE_PERSISTENCE=$(ENABLE_PERSISTENCE) WORKFLOW_IMAGE_TAG=$(IMAGE_TAG) ${SCRIPTS_DIR}/gen_manifests.sh $(GEN_MANIFESTS_WORKFLOW_FOLDER) $(WORKFLOW_ID)"
@echo "Manifests are available in workdir $(WORKDIR)/$(GEN_MANIFESTS_WORKFLOW_FOLDER)/manifests"
Comment on lines +171 to +177
Copy link
Collaborator

Choose a reason for hiding this comment

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

nice!


remove-trailing-whitespaces:
@echo "Removing all trailing whitespaces from application.properties files"
Expand Down
1 change: 0 additions & 1 deletion pipeline/workflow-builder.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ COPY --chown=1001 ${WF_RESOURCES} ./resources/
RUN ls -la ./resources

ENV swf_home_dir=/home/kogito/serverless-workflow-project
RUN if [[ -d "./resources/src" ]]; then cp -r ./resources/src/* ./src/; fi

Comment on lines 43 to 44
Copy link
Collaborator

Choose a reason for hiding this comment

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

why was this line removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

RUN if [[ -d "./resources/src" ]]; then cp -r ./resources/src/* ./src/; fi

This command copies files from

/home/kogito/serverless-workflow-project/resources/src

to the

/home/kogito/serverless-workflow-project/src:

After that we have workflow file

/home/kogito/serverless-workflow-project/src/main/resources/create-pr-universal.sw.yaml  

inside container.
That's OK, but build-app.sh script also copies files...

Next Dockerfile command:

RUN /home/kogito/launch/build-app.sh ./resources

Fragment of this script:

... 
destination="${KOGITO_HOME}/serverless-workflow-project/src/main/resources/"
log_info "-> Destination folder is ${destination}"
cp -vR ${resources_path}/* ${destination}
...

And build image log for this command

INFO -> Destination folder is /home/kogito/serverless-workflow-project/src/main/resources/
'/home/kogito/serverless-workflow-project/resources/src/main/resources' -> '/home/kogito/serverless-workflow-project/src/main/resources/src/main/resources'
'/home/kogito/serverless-workflow-project/resources/src/main/resources/application.properties' -> '/home/kogito/serverless-workflow-project/src/main/resources/src/main/resources/application.properties'
'/home/kogito/serverless-workflow-project/resources/src/main/resources/create-pr-universal.sw.yaml' -> '/home/kogito/serverless-workflow-project/src/main/resources/src/main/resources/create-pr-universal.sw.yaml'

So build-app.sh provides duplicated workflow file. These workflows has a bit different path:

/home/kogito/serverless-workflow-project/src/main/resources/create-pr-universal.sw.yaml
/home/kogito/serverless-workflow-project/src/main/resources/src/main/resources/create-pr-universal.sw.yaml

Then build-app.sh makes maven build and fails with "Duplicated item found with id universal-pr":

Error:  Failed to execute goal com.redhat.quarkus.platform:quarkus-maven-plugin:3.15.4.redhat-00001:build (default) on project serverless-workflow-project: Failed to build quarkus application: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
Error: [ERROR] 	[error]: Build step org.kie.kogito.quarkus.common.deployment.KogitoAssetsProcessor#generateSources threw an exception: org.kie.kogito.codegen.process.ProcessCodegenException: Duplicated item found with id universal-pr. Please review the .sw files

Copy link
Collaborator

Choose a reason for hiding this comment

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

nice catch!

RUN /home/kogito/launch/build-app.sh ./resources

Expand Down
49 changes: 49 additions & 0 deletions workflows/bulk-import-git-repos/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Bulk Import Git Repos Workflow

This workflow creates pull requests (GitHub) or merge requests (GitLab) based on the `approvalTool` parameter.

## Overview

The workflow supports both GitHub and GitLab repositories and can create PRs/MRs with multiple files.

## Input Schema

The workflow expects the following input parameters:
- `approvalTool`: Either "GIT" for GitHub or "GITLAB" for GitLab
- `owner`: The owner/namespace of the repository
- `repo`: The repository name
- `baseBranch`: The base branch to create the PR/MR from
- `targetBranch`: The target branch name for the PR/MR

## Workflow Steps

1. **GetScafolderData**: Retrieves mock data with files to be added
2. **RouteToProvider**: Routes to either GitHub or GitLab workflow based on `approvalTool`
3. **GitHub Flow**: Creates branch, commits files, and creates a pull request
4. **GitLab Flow**: Searches for project, creates branch, commits files, and creates a merge request

## Output

- For GitHub: Returns PR URL in `PR_URL` output
- For GitLab: Returns MR URL in `MR_URL` output

# Development

Java artifacts build(prerequisites: pre-installed java and maven):

```
mvn clean install
```

Generate manifests, from the root of the repository:

```
make WORKFLOW_ID=bulk-import-git-repos WORKFLOW_SUBDIR=bulk-import-git-repos/src/main/resources gen-manifests
cp -rf /tmp/serverless-workflows/workflows/bulk-import-git-repos/src/main/resources/manifests ./workflows/bulk-import-git-repos
```

Build image:

```
make WORKFLOW_ID=bulk-import-git-repos build-image
```
2 changes: 2 additions & 0 deletions workflows/bulk-import-git-repos/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

kie.flyway.enabled=true
6 changes: 6 additions & 0 deletions workflows/bulk-import-git-repos/argfile.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FLOW_NAME=Universal PR
FLOW_SUMMARY=Create Universal Pull/Merge Request
FLOW_DESCRIPTION=This workflow creates a pull request (GitHub) or merge request (GitLab) based on approvalTool parameter.
# Base extensions (JARs included in image): persistence-jdbc, jdbc-postgresql, openapi-generator, oidc-client-filter, oidc, agroal
QUARKUS_EXTENSIONS=org.kie:kie-addons-quarkus-persistence-jdbc,io.quarkus:quarkus-jdbc-postgresql:3.15.4.redhat-00001,io.quarkiverse.openapi.generator:quarkus-openapi-generator:2.9.1-lts,io.quarkus:quarkus-oidc-client-filter,io.quarkus:quarkus-oidc,io.quarkus:quarkus-agroal:3.15.4.redhat-00001,org.kie:kie-addons-quarkus-monitoring-sonataflow,org.kie:kogito-addons-quarkus-jobs-knative-eventing
MAVEN_ARGS_APPEND=-DmaxYamlCodePoints=35000000 -Dkogito.persistence.type=jdbc -Dquarkus.datasource.db-kind=postgresql -Dkogito.persistence.proto.marshaller=false
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
apiVersion: v1
data:
application.properties: |
# This property is used to select the log level, which controls the amount
# of information logged on HTTP requests based on the severity of the events.
# Possible values: OFF, FATAL, ERROR, WARN, INFO, DEBUG, ALL.
# and see https://quarkus.io/guides/logging for documentation
quarkus.log.category."org.apache.http".level=DEBUG
quarkus.log.level=DEBUG

# Datasource
quarkus.datasource.db-kind=postgresql
quarkus.datasource.jdbc.url=jdbc:postgresql://postgres.showcase.svc.cluster.local:5432/sonata
quarkus.datasource.username=sonata
quarkus.datasource.password=sonata

# Persistence
kogito.persistence.type=jdbc
kogito.persistence.auto.ddl=false
kie.flyway.enabled=true

quarkus.oidc.enabled=false
quarkus.oidc.tenant-enabled=false
quarkus.kogito.devservices.enabled=false
quarkus.openapi-generator.github_yaml.auth.BearerToken.token-propagation=true
quarkus.openapi-generator.github_yaml.auth.BearerToken.header-name=X-Authorization-Github
# quarkus.rest-client.github_yaml.headers.Accept=application/vnd.github+json
# quarkus.openapi-generator.github_yaml.auth.BearerToken.header-name=X-Authorization-github
# quarkus.openapi-generator.github_yaml.auth.BearerToken.bearer-token=${ghToken}

# quarkus.openapi-generator.githubtwo_yaml.auth.BearerToken.token-propagation=true
# quarkus.openapi-generator.githubtwo_yaml.auth.BearerToken.header-name=X-Authorization-github-two

quarkus.openapi-generator.gitlab_yaml.auth.BearerToken.token-propagation=true
quarkus.openapi-generator.gitlab_yaml.auth.BearerToken.header-name=X-Authorization-gitlab

kie.flyway.enabled=true
kind: ConfigMap
metadata:
creationTimestamp: null
labels:
app: universal-pr
app.kubernetes.io/component: serverless-workflow
app.kubernetes.io/managed-by: sonataflow-operator
app.kubernetes.io/name: universal-pr
sonataflow.org/workflow-app: universal-pr
sonataflow.org/workflow-namespace: ""
name: universal-pr-props
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: v1
kind: Secret
metadata:
creationTimestamp: null
labels:
app: universal-pr
app.kubernetes.io/component: serverless-workflow
app.kubernetes.io/managed-by: sonataflow-operator
app.kubernetes.io/name: universal-pr
sonataflow.org/workflow-app: universal-pr
sonataflow.org/workflow-namespace: ""
name: universal-pr-secrets
stringData:
ghToken: ghp_ABC123
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
apiVersion: v1
data:
create-pr-universal-input-schema.json: |
{
"$id": "classpath:/schemas/create-pr-universal-input-schema.json",
"title": "Create Universal PR/MR Input Schema",
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"approvalTool": {
"title": "Approval Tool",
"description": "The Git provider to use: GIT for GitHub or GITLAB for GitLab",
"type": "string",
"enum": ["GIT", "GITLAB"]
},
"owner": {
"title": "Owner",
"description": "The owner/namespace of the repository",
"type": "string"
},
"repo": {
"title": "Repository",
"description": "The repository name",
"type": "string"
},
"baseBranch": {
"title": "Base Branch",
"description": "The base branch to create the PR/MR from",
"type": "string"
},
"targetBranch": {
"title": "Target Branch",
"description": "The target branch name for the PR/MR",
"type": "string"
}
},
"required": [
"approvalTool",
"owner",
"repo",
"baseBranch",
"targetBranch"
]
}
kind: ConfigMap
metadata:
creationTimestamp: null
name: 01-universal-pr-resources-schemas
Loading
Loading