2025-04-26 06:31:43 +00:00

125 lines
3.6 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: context
type: string
description: context directory
default: ""
- name: source
type: string
default: "source"
description: |
source directory (sub directory of context)
- 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"
- 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')"
workspaces:
- name: base
steps:
- name: install-deps
image: node:18-alpine
workingDir: /workspace/base/$(params.context)/$(params.source)/$(params.workspaceName)
env:
- name: HOME
value: /workspace/base/$(params.context)/home
script: |
# Install Nx if missing
command -v nx >/dev/null || npm install -g nx@latest
# Install pnpm if missing
command -v pnpm >/dev/null || npm install -g pnpm
pnpm install
- name: import-projects
image: node:18-alpine
workingDir: /workspace/base/$(params.context)/$(params.source)/$(params.workspaceName)
env:
- name: HOME
value: /workspace/base/$(params.context)/home
script: |
#!/bin/sh
set -ex
# 필수 패키지 설치 및 Git 설정
apk add --no-cache git
git config --global --add safe.directory '*'
git config --global init.defaultBranch main
TARGETS="$(params.targetProjects)"
SOURCES="$(params.sourceProjects)"
set -- $TARGETS
for TARGET in "$@"; do
SRC=$(echo "$SOURCES" | cut -d' ' -f1)
SOURCES=$(echo "$SOURCES" | cut -s -d' ' -f2-)
# 소스 디렉터리 Git 초기화
cd "$SRC"
if [ ! -d .git ]; then
git init -b main
git add .
git commit -m "init"
fi
cd -
# Nx 비대화형 임포트 실행 (옵션 수정)
echo "Importing: $SRC → $TARGET"
npx nx import "$SRC" "$TARGET" \
--interactive=false \ # ✅ 올바른 옵션
--ref=main \ # ✅ --branch → --ref
--sourceDirectory=.
# 버전 업데이트
sed -i.bak "s/^version = .*/version = \"$(params.version)\"/" "$TARGET/Cargo.toml"
rm -f "$TARGET/Cargo.toml.bak"
# 변경사항 커밋
git add .
git commit -m "chore: import $TARGET (v$(params.version))" || true
done
- name: git-commit
image: alpine/git:latest
workingDir: /workspace/base/$(params.context)/$(params.source)
env:
- name: HOME
value: /workspace/base/$(params.context)/home
script: |
#!/bin/sh
set -e
git add .
git commit -m "chore: merge projects (version $(params.version))" || exit 0
git push origin HEAD:main