2025-04-25 20:16:39 +00:00

84 lines
2.7 KiB
YAML

apiVersion: tekton.dev/v1
kind: Task
metadata:
name: rust-nx-merge
annotations:
tekton.dev/pipelines.minVersion: "0.30.0"
tekton.dev/categories: GitOps
tekton.dev/tags: git, nx, rust, monorepo
tekton.dev/displayName: "Merge Rust Projects into Nx Monorepo"
spec:
description: |
Imports Rust projects into an Nx monorepo structure and synchronizes Cargo.toml versions.
Accepts space-separated project pairs for bulk operations.
params:
- name: targetProjects
type: string
description: "Space-separated target project paths in monorepo (e.g., 'libs/auth libs/payment')"
- name: sourceProjects
type: string
description: "Space-separated source project paths in workspace (e.g., 'generated/auth generated/payment')"
- name: version
type: string
description: "Version to set in Cargo.toml files"
default: "0.1.0"
- name: workspaceName
type: string
description: "Name of the monorepo workspace directory"
default: "unbox-x"
workspaces:
- name: source
description: Workspace containing source projects
- name: repo
description: Git repository workspace
steps:
- name: import-projects
image: node:18-alpine
workingDir: $(workspaces.repo.path)
script: |
#!/bin/sh
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 count mismatch"
exit 1
fi
# Process each project pair
for i in $(seq 0 $((${#TARGETS[@]}-1))); do
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: git-commit
image: alpine/git:latest
workingDir: $(workspaces.repo.path)
script: |
#!/bin/sh
set -e
git config --global user.name "tekton-bot"
git config --global user.email "tekton@example.com"
git add .
git commit -m "chore: merge projects (version $(params.version))" || exit 0
git push origin HEAD:main