init
This commit is contained in:
parent
5ddf0baa2f
commit
f9876799f6
@ -3,121 +3,81 @@ kind: Task
|
|||||||
metadata:
|
metadata:
|
||||||
name: rust-nx-merge
|
name: rust-nx-merge
|
||||||
annotations:
|
annotations:
|
||||||
tekton.dev/pipelines.minVersion: "0.19.0"
|
tekton.dev/pipelines.minVersion: "0.30.0"
|
||||||
tekton.dev/categories: GitOps
|
tekton.dev/categories: GitOps
|
||||||
tekton.dev/tags: git, devops, nx, rust
|
tekton.dev/tags: git, nx, rust, monorepo
|
||||||
tekton.dev/displayName: "Merge Rust projects with nx import"
|
tekton.dev/displayName: "Merge Rust Projects into Nx Monorepo"
|
||||||
tekton.dev/platforms: "linux/amd64"
|
|
||||||
spec:
|
spec:
|
||||||
description: |
|
description: |
|
||||||
Clones a git repository, merges Rust projects using nx import,
|
Imports Rust projects into an Nx monorepo structure and synchronizes Cargo.toml versions.
|
||||||
updates target project versions to match source versions.
|
Accepts space-separated project pairs for bulk operations.
|
||||||
|
|
||||||
params:
|
params:
|
||||||
- name: context
|
- name: targetProjects
|
||||||
type: string
|
type: string
|
||||||
description: context directory
|
description: "Space-separated target project paths in monorepo (e.g., 'libs/auth libs/payment')"
|
||||||
default: ""
|
|
||||||
|
|
||||||
- name: repositoryUrl
|
- name: sourceProjects
|
||||||
type: string
|
type: string
|
||||||
description: Target repository URL
|
description: "Space-separated source project paths in workspace (e.g., 'generated/auth generated/payment')"
|
||||||
|
|
||||||
- name: branch
|
|
||||||
type: string
|
|
||||||
default: "main"
|
|
||||||
description: Git branch to operate on
|
|
||||||
|
|
||||||
- name: version
|
- name: version
|
||||||
description: Rust crate version
|
|
||||||
type: string
|
type: string
|
||||||
default: "0.0.0"
|
description: "Version to set in Cargo.toml files"
|
||||||
|
default: "0.1.0"
|
||||||
|
|
||||||
- name: workspaceName
|
- name: workspaceName
|
||||||
type: string
|
type: string
|
||||||
description: Nx workspace project name to lint and test
|
description: "Name of the monorepo workspace directory"
|
||||||
|
default: "unbox-x"
|
||||||
- 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:
|
workspaces:
|
||||||
- name: base
|
- name: source
|
||||||
- name: tmp
|
description: Workspace containing source projects
|
||||||
|
- name: repo
|
||||||
|
description: Git repository workspace
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: clone-repository
|
- name: import-projects
|
||||||
image: alpine/git:latest
|
image: node:18-alpine
|
||||||
workingDir: /workspace/tmp
|
workingDir: $(workspaces.repo.path)
|
||||||
env:
|
|
||||||
- name: HOME
|
|
||||||
value: /workspace/base/$(params.context)/home
|
|
||||||
script: |
|
script: |
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
set -e
|
set -ex
|
||||||
git clone -b $(params.branch) $(params.repositoryUrl) repo
|
|
||||||
cd repo
|
# Install Nx if missing
|
||||||
|
command -v nx >/dev/null || npm install -g nx@latest
|
||||||
- name: merge-projects
|
|
||||||
image: node:18
|
# Convert parameters to arrays
|
||||||
workingDir: /workspace/tmp
|
TARGETS=($(echo "$(params.targetProjects)" | tr ' ' '\n'))
|
||||||
script: |
|
SOURCES=($(echo "$(params.sourceProjects)" | tr ' ' '\n'))
|
||||||
#!/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
|
if [ ${#TARGETS[@]} -ne ${#SOURCES[@]} ]; then
|
||||||
echo "Error: targetProjects and sourceProjects length mismatch"
|
echo "Error: targetProjects and sourceProjects count mismatch"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Process each project pair
|
# Process each project pair
|
||||||
cd repo/$(params.workspaceName)
|
|
||||||
|
|
||||||
for i in $(seq 0 $((${#TARGETS[@]}-1))); do
|
for i in $(seq 0 $((${#TARGETS[@]}-1))); do
|
||||||
SOURCE_PATH="${SOURCES[$i]}"
|
SRC="$(workspaces.source.path)/${SOURCES[$i]}"
|
||||||
TARGET_PROJECT="${TARGETS[$i]}"
|
TARGET="${TARGETS[$i]}"
|
||||||
TARGET_PATH="repo/$(params.workspaceName)/${TARGET_PROJECT}"
|
|
||||||
|
echo "Importing: ${SRC} → ${TARGET}"
|
||||||
# Import project
|
nx import "${SRC}" --destination="${TARGET}" --importPath=$(basename "${TARGET}")
|
||||||
echo "Importing ${SOURCE_PATH} to ${TARGET_PROJECT}"
|
|
||||||
npx nx import "${SOURCE_PATH}" "${TARGET_PROJECT}"
|
echo "Updating version to $(params.version)"
|
||||||
|
sed -i.bak "s/^version = .*/version = \"$(params.version)\"/" "${TARGET}/Cargo.toml"
|
||||||
# Version sync
|
rm -f "${TARGET}/Cargo.toml.bak"
|
||||||
sed -i.bak "s/^version = .*/version = \"$(params.version)\"/" "${TARGET_PATH}/Cargo.toml"
|
|
||||||
rm -f "${TARGET_PATH}/Cargo.toml.bak"
|
|
||||||
done
|
done
|
||||||
|
|
||||||
- name: commit-and-push
|
- name: git-commit
|
||||||
image: alpine/git:latest
|
image: alpine/git:latest
|
||||||
workingDir: /workspace/tmp
|
workingDir: $(workspaces.repo.path)
|
||||||
env:
|
|
||||||
- name: HOME
|
|
||||||
value: /workspace/base/$(params.context)/home
|
|
||||||
script: |
|
script: |
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
set -e
|
set -e
|
||||||
cd repo"
|
git config --global user.name "tekton-bot"
|
||||||
|
git config --global user.email "tekton@example.com"
|
||||||
git add .
|
git add .
|
||||||
git commit -m "$(params.commitMessage)" || exit 0
|
git commit -m "chore: merge projects (version $(params.version))" || exit 0
|
||||||
git push origin HEAD:"$(params.branch)"
|
git push origin HEAD:main
|
||||||
|
|
||||||
volumes:
|
|
||||||
- name: tmp
|
|
||||||
emptyDir: {}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user