117 lines
3.5 KiB
YAML
117 lines
3.5 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: 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)/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)/source/$(params.workspaceName)
|
|
env:
|
|
- name: HOME
|
|
value: /workspace/base/$(params.context)/home
|
|
script: |
|
|
#!/bin/sh
|
|
set -ex
|
|
|
|
# Git 설치
|
|
apk add --no-cache git
|
|
# Git safe.directory 설정 (모든 경로 허용)
|
|
git config --global --add safe.directory '*'
|
|
git config --global init.defaultBranch main # master 대신 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-)
|
|
TARGET_PATH="/workspace/base/$(params.context)/source/$(params.workspaceName)/${TARGET}"
|
|
|
|
ls -al $SRC/src
|
|
|
|
cd "$SRC"
|
|
if [ ! -d .git ]; then
|
|
git init
|
|
git add .
|
|
git commit -m "init"
|
|
fi
|
|
cd -
|
|
|
|
echo "Importing: $SRC → $TARGET_PATH"
|
|
npx nx import --sourceDirectory="$SRC" --destinationDirectory="$TARGET_PATH" --interactive=false --ref=main
|
|
echo "Updating version to $(params.version)"
|
|
sed -i.bak "s/^version = .*/version = \"$(params.version)\"/" "$TARGET_PATH/Cargo.toml"
|
|
rm -f "$TARGET_PATH/Cargo.toml.bak"
|
|
|
|
# destination(monorepo) 변경사항 커밋 또는 리셋
|
|
git add .
|
|
git commit -m "auto-commit before nx import" || git reset --hard HEAD
|
|
|
|
done
|
|
|
|
- name: git-commit
|
|
image: alpine/git:latest
|
|
workingDir: /workspace/base/$(params.context)/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
|