From ed6dcb252f2aeafbe32006962157fba753b3b3b1 Mon Sep 17 00:00:00 2001 From: BAK BYEONG JUN Date: Sat, 12 Apr 2025 06:52:55 +0000 Subject: [PATCH] init --- .../task.yaml | 2 +- tasks/nodejs-nx-analysis/task.yaml | 71 +++++++++++++++++++ tasks/nodejs-nx-version/task.yaml | 54 ++++++++++++++ 3 files changed, 126 insertions(+), 1 deletion(-) rename tasks/{gitops-repository => git-gitops-sync}/task.yaml (99%) create mode 100644 tasks/nodejs-nx-analysis/task.yaml create mode 100644 tasks/nodejs-nx-version/task.yaml diff --git a/tasks/gitops-repository/task.yaml b/tasks/git-gitops-sync/task.yaml similarity index 99% rename from tasks/gitops-repository/task.yaml rename to tasks/git-gitops-sync/task.yaml index 76fd4a3..9d4fcfa 100644 --- a/tasks/gitops-repository/task.yaml +++ b/tasks/git-gitops-sync/task.yaml @@ -1,7 +1,7 @@ apiVersion: tekton.dev/v1beta1 kind: Task metadata: - name: gitops-repository + name: git-gitops-sync annotations: tekton.dev/pipelines.minVersion: "0.19.0" tekton.dev/categories: GitOps diff --git a/tasks/nodejs-nx-analysis/task.yaml b/tasks/nodejs-nx-analysis/task.yaml new file mode 100644 index 0000000..2082fe8 --- /dev/null +++ b/tasks/nodejs-nx-analysis/task.yaml @@ -0,0 +1,71 @@ +--- +apiVersion: tekton.dev/v1 +kind: Task +metadata: + name: nx-nodejs-analysis +spec: + params: + - name: subdirectory + type: string + description: Subdirectory within the repo where the source code is located + default: "" + + - name: targetProject + type: string + description: Nx workspace project name to lint and test + + - name: node-version + type: string + default: "18" + description: Node.js version (e.g., 18, 20) + + workspaces: + - name: source + description: Git-cloned source code with Nx monorepo + - name: npm-auth + optional: true + description: | + A workspace containing authentication credentials for a private npm repository. + Should include: + - username + - password + + results: + - name: coverage-dir + description: Path to generated coverage directory + - name: coverage-html + description: Path to generated HTML coverage report directory + + steps: + - name: lint-and-test + image: node:$(params.node-version) + workingDir: /workspace/source + script: | + #!/usr/bin/env bash + set -e + + if [ -n "$(params.subdirectory)" ]; then + cd "$(params.subdirectory)" + fi + + echo "๐Ÿ“ฆ Installing dependencies" + npm ci + + echo "๐Ÿ” Running ESLint for project: $(params.targetProject)" + npx nx lint $(params.targetProject) + + echo "๐Ÿงช Running Jest tests for project: $(params.targetProject) with coverage" + npx nx test $(params.targetProject) --code-coverage + + COVERAGE_DIR="coverage/$(params.targetProject)" + HTML_DIR="$COVERAGE_DIR/lcov-report" + + echo "๐Ÿ“ Saving coverage path: $COVERAGE_DIR" + echo -n "$COVERAGE_DIR" > /tekton/results/coverage-dir + echo -n "$HTML_DIR" > /tekton/results/coverage-html + + if [ -d "$HTML_DIR" ]; then + echo "๐Ÿ“„ HTML coverage report generated at $HTML_DIR" + else + echo "โš ๏ธ HTML coverage report not found" + fi diff --git a/tasks/nodejs-nx-version/task.yaml b/tasks/nodejs-nx-version/task.yaml new file mode 100644 index 0000000..f814c8f --- /dev/null +++ b/tasks/nodejs-nx-version/task.yaml @@ -0,0 +1,54 @@ +apiVersion: tekton.dev/v1beta1 +kind: Task +metadata: + name: nx-nodejs-version +spec: + params: + - name: subdirectory + type: string + description: Subdirectory within the repo where the source code is located + default: "" + - name: ref + type: string + description: Full Git ref string (e.g., refs/tags/v0.2.0) + - name: node-version + type: string + description: Node.js version to use + default: "18" + workspaces: + - name: source + description: Git-cloned source code + results: + - name: version + description: Extracted project version (e.g. 0.2.0) + steps: + - name: verify-tag-version + image: node:$(params.node-version) + workingDir: /workspace/source + script: | + #!/usr/bin/env bash + set -e + + if [ -n "$(params.subdirectory)" ]; then + cd $(params.subdirectory) + fi + + echo "๐Ÿ” Extracting tag from Git ref..." + FULL_REF="$(params.ref)" + TAG_FROM_REF=$(basename "$FULL_REF") # โ†’ v0.2.0 + + echo "๐Ÿ“„ Reading version from package.json..." + VERSION=$(node -p "require('./package.json').version") + TAG_FROM_PROJECT="v${VERSION}" + + echo "๐Ÿ” Comparing Git tag and project version:" + echo " - Git ref tag: $TAG_FROM_REF" + echo " - Project version: $TAG_FROM_PROJECT" + + if [ "$TAG_FROM_REF" != "$TAG_FROM_PROJECT" ]; then + echo "โŒ Mismatch! Git tag and project version are not the same." + exit 1 + fi + + echo "โœ… Tag and version match: $VERSION" + echo -n "$VERSION" > /tekton/results/version \ No newline at end of file