From f9876799f6bbc86c02636a4eedad1aa99fbd90a8 Mon Sep 17 00:00:00 2001 From: BAK BYEONG JUN Date: Fri, 25 Apr 2025 20:16:39 +0000 Subject: [PATCH] init --- tasks/rust-nx-merge/task.yaml | 128 ++++++++++++---------------------- 1 file changed, 44 insertions(+), 84 deletions(-) diff --git a/tasks/rust-nx-merge/task.yaml b/tasks/rust-nx-merge/task.yaml index c6d0a3d..e6022ba 100644 --- a/tasks/rust-nx-merge/task.yaml +++ b/tasks/rust-nx-merge/task.yaml @@ -3,121 +3,81 @@ kind: Task metadata: name: rust-nx-merge annotations: - tekton.dev/pipelines.minVersion: "0.19.0" + tekton.dev/pipelines.minVersion: "0.30.0" tekton.dev/categories: GitOps - tekton.dev/tags: git, devops, nx, rust - tekton.dev/displayName: "Merge Rust projects with nx import" - tekton.dev/platforms: "linux/amd64" + tekton.dev/tags: git, nx, rust, monorepo + tekton.dev/displayName: "Merge Rust Projects into Nx Monorepo" spec: description: | - Clones a git repository, merges Rust projects using nx import, - updates target project versions to match source versions. + Imports Rust projects into an Nx monorepo structure and synchronizes Cargo.toml versions. + Accepts space-separated project pairs for bulk operations. params: - - name: context + - name: targetProjects type: string - description: context directory - default: "" + description: "Space-separated target project paths in monorepo (e.g., 'libs/auth libs/payment')" - - name: repositoryUrl + - name: sourceProjects type: string - description: Target repository URL - - - name: branch - type: string - default: "main" - description: Git branch to operate on + description: "Space-separated source project paths in workspace (e.g., 'generated/auth generated/payment')" - name: version - description: Rust crate version type: string - default: "0.0.0" + description: "Version to set in Cargo.toml files" + default: "0.1.0" - name: workspaceName type: string - description: Nx workspace project name to lint and test - - - name: targetProjects - type: array - description: List of target project paths in the repo (e.g., ["libs/project1"]) - - - name: sourceProjects - type: array - description: List of source project paths in workspace (e.g., ["generated/project1"]) - - - name: commitMessage - type: string - default: "chore: merge projects and sync versions" - description: Commit message + description: "Name of the monorepo workspace directory" + default: "unbox-x" workspaces: - - name: base - - name: tmp + - name: source + description: Workspace containing source projects + - name: repo + description: Git repository workspace steps: - - name: clone-repository - image: alpine/git:latest - workingDir: /workspace/tmp - env: - - name: HOME - value: /workspace/base/$(params.context)/home + - name: import-projects + image: node:18-alpine + workingDir: $(workspaces.repo.path) script: | #!/bin/sh - set -e - git clone -b $(params.branch) $(params.repositoryUrl) repo - cd repo - - - name: merge-projects - image: node:18 - workingDir: /workspace/tmp - script: | - #!/bin/sh - set -e - - # Install nx if not present - command -v nx >/dev/null || npm install -g nx - - # Get project pairs - TARGETS=($(params.targetProjects[*])) - SOURCES=($(params.sourceProjects[*])) + set -ex + + # Install Nx if missing + command -v nx >/dev/null || npm install -g nx@latest + + # Convert parameters to arrays + TARGETS=($(echo "$(params.targetProjects)" | tr ' ' '\n')) + SOURCES=($(echo "$(params.sourceProjects)" | tr ' ' '\n')) if [ ${#TARGETS[@]} -ne ${#SOURCES[@]} ]; then - echo "Error: targetProjects and sourceProjects length mismatch" + echo "Error: targetProjects and sourceProjects count mismatch" exit 1 fi # Process each project pair - cd repo/$(params.workspaceName) - for i in $(seq 0 $((${#TARGETS[@]}-1))); do - SOURCE_PATH="${SOURCES[$i]}" - TARGET_PROJECT="${TARGETS[$i]}" - TARGET_PATH="repo/$(params.workspaceName)/${TARGET_PROJECT}" - - # Import project - echo "Importing ${SOURCE_PATH} to ${TARGET_PROJECT}" - npx nx import "${SOURCE_PATH}" "${TARGET_PROJECT}" - - # Version sync - sed -i.bak "s/^version = .*/version = \"$(params.version)\"/" "${TARGET_PATH}/Cargo.toml" - rm -f "${TARGET_PATH}/Cargo.toml.bak" + SRC="$(workspaces.source.path)/${SOURCES[$i]}" + TARGET="${TARGETS[$i]}" + + echo "Importing: ${SRC} → ${TARGET}" + nx import "${SRC}" --destination="${TARGET}" --importPath=$(basename "${TARGET}") + + echo "Updating version to $(params.version)" + sed -i.bak "s/^version = .*/version = \"$(params.version)\"/" "${TARGET}/Cargo.toml" + rm -f "${TARGET}/Cargo.toml.bak" done - - name: commit-and-push + - name: git-commit image: alpine/git:latest - workingDir: /workspace/tmp - env: - - name: HOME - value: /workspace/base/$(params.context)/home + workingDir: $(workspaces.repo.path) script: | #!/bin/sh set -e - cd repo" - + git config --global user.name "tekton-bot" + git config --global user.email "tekton@example.com" git add . - git commit -m "$(params.commitMessage)" || exit 0 - git push origin HEAD:"$(params.branch)" - - volumes: - - name: tmp - emptyDir: {} + git commit -m "chore: merge projects (version $(params.version))" || exit 0 + git push origin HEAD:main