2025-04-25 19:22:03 +00:00

120 lines
3.2 KiB
YAML

apiVersion: tekton.dev/v1
kind: Task
metadata:
name: rust-nx-merge
annotations:
tekton.dev/pipelines.minVersion: "0.19.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"
spec:
description: |
Clones a git repository, merges Rust projects using nx import,
updates target project versions to match source versions.
params:
- name: context
type: string
description: context directory
default: ""
- name: repositoryUrl
type: string
description: Target repository URL
- name: branch
type: string
default: "main"
description: Git branch to operate on
- 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
workspaces:
- name: base
- name: tmp
steps:
- name: clone-repository
image: alpine/git:latest
workingDir: /workspace/tmp
env:
- name: HOME
value: /workspace/base/$(params.context)/home
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[*]))
if [ ${#TARGETS[@]} -ne ${#SOURCES[@]} ]; then
echo "Error: targetProjects and sourceProjects length 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
SRC_VERSION=$(grep '^version =' "${SOURCE_PATH}/Cargo.toml" | cut -d'"' -f2)
sed -i.bak "s/^version = .*/version = \"${SRC_VERSION}\"/" "${TARGET_PATH}/Cargo.toml"
rm -f "${TARGET_PATH}/Cargo.toml.bak"
done
- name: commit-and-push
image: alpine/git:latest
workingDir: /workspace/tmp
env:
- name: HOME
value: /workspace/base/$(params.context)/home
script: |
#!/bin/sh
set -e
cd repo"
git add .
git commit -m "$(params.commitMessage)" || exit 0
git push origin HEAD:"$(params.branch)"
volumes:
- name: tmp
emptyDir: {}