diff --git a/.tekton/ec-policy.yaml b/.tekton/ec-policy.yaml new file mode 100644 index 0000000..a1dbc8c --- /dev/null +++ b/.tekton/ec-policy.yaml @@ -0,0 +1,21 @@ +--- +apiVersion: appstudio.redhat.com/v1alpha1 +kind: EnterpriseContractPolicy +metadata: + name: migration-planner-ui-policy +spec: + description: Custom Enterprise Contract policy for migration-planner-ui + publicKey: k8s://openshift-pipelines/public-key + sources: + - name: Release Policies + policy: + - github.com/enterprise-contract/ec-policies//policy/lib + - github.com/enterprise-contract/ec-policies//policy/release + data: + - github.com/enterprise-contract/ec-policies//data + configuration: + exclude: + # Exclude the update-version inline task from trusted task check + # This task updates package.json with version information before build + # and is necessary for proper versioning in Konflux builds + - trusted_task.trusted:update-version-task diff --git a/.tekton/migration-planner-ui-branch-push.yaml b/.tekton/migration-planner-ui-branch-push.yaml deleted file mode 100644 index 1bc555c..0000000 --- a/.tekton/migration-planner-ui-branch-push.yaml +++ /dev/null @@ -1,635 +0,0 @@ -apiVersion: tekton.dev/v1 -kind: PipelineRun -metadata: - annotations: - build.appstudio.openshift.io/repo: https://github.com/kubev2v/migration-planner-ui-app?rev={{revision}} - build.appstudio.redhat.com/commit_sha: '{{revision}}' - build.appstudio.redhat.com/target_branch: '{{target_branch}}' - pipelinesascode.tekton.dev/cancel-in-progress: "false" - pipelinesascode.tekton.dev/max-keep-runs: "3" - pipelinesascode.tekton.dev/on-cel-expression: event == "push" && target_branch == "release_0.1.4-1" - creationTimestamp: - labels: - appstudio.openshift.io/application: assisted-migration - appstudio.openshift.io/component: migration-planner-ui - pipelines.appstudio.openshift.io/type: build - name: migration-planner-ui-on-branch-push - namespace: assisted-migration-tenant -spec: - params: - - name: git-url - value: '{{source_url}}' - - name: revision - value: '{{revision}}' - - name: output-image - value: quay.io/redhat-user-workloads/assisted-migration-tenant/migration-planner-ui:{{revision}} - - name: dockerfile - value: build-tools/Dockerfile - - name: path-context - value: . - - name: build-args - value: - - MIGRATION_PLANNER_UI_GIT_COMMIT={{revision}} - - MIGRATION_PLANNER_UI_VERSION={{revision}} - pipelineSpec: - description: | - This pipeline is ideal for building container images from a Containerfile while reducing network traffic. - - _Uses `buildah` to create a container image. It also optionally creates a source image and runs some build-time tests. EC will flag a violation for [`trusted_task.trusted`](https://conforma.dev/docs/policy/packages/release_trusted_task.html#trusted_task__trusted) if any tasks are added to the pipeline. - This pipeline is pushed as a Tekton bundle to [quay.io](https://quay.io/repository/konflux-ci/tekton-catalog/pipeline-docker-build?tab=tags)_ - finally: - - name: show-sbom - params: - - name: IMAGE_URL - value: $(tasks.build-image-index.results.IMAGE_URL) - taskRef: - params: - - name: name - value: show-sbom - - name: bundle - value: quay.io/konflux-ci/tekton-catalog/task-show-sbom:0.1@sha256:beb0616db051952b4b861dd8c3e00fa1c0eccbd926feddf71194d3bb3ace9ce7 - - name: kind - value: task - resolver: bundles - - name: show-summary - params: - - name: pipelinerun-name - value: $(context.pipelineRun.name) - - name: git-url - value: $(tasks.clone-repository.results.url)?rev=$(tasks.clone-repository.results.commit) - - name: image-url - value: $(params.output-image) - - name: build-task-status - value: $(tasks.build-image-index.status) - taskRef: - params: - - name: name - value: summary - - name: bundle - value: quay.io/konflux-ci/tekton-catalog/task-summary:0.2@sha256:3f6e8513cbd70f0416eb6c6f2766973a754778526125ff33d8e3633def917091 - - name: kind - value: task - resolver: bundles - workspaces: - - name: workspace - workspace: workspace - params: - - description: Source Repository URL - name: git-url - type: string - - default: "" - description: Revision of the Source Repository - name: revision - type: string - - description: Fully Qualified Output Image - name: output-image - type: string - - default: . - description: Path to the source code of an application's component from where to build image. - name: path-context - type: string - - default: Dockerfile - description: Path to the Dockerfile inside the context specified by parameter path-context - name: dockerfile - type: string - - default: "false" - description: Force rebuild image - name: rebuild - type: string - - default: "false" - description: Skip checks against built image - name: skip-checks - type: string - - default: "false" - description: Execute the build with network isolation - name: hermetic - type: string - - default: "" - description: Build dependencies to be prefetched by Cachi2 - name: prefetch-input - type: string - - default: "" - description: Image tag expiration time, time values could be something like 1h, 2d, 3w for hours, days, and weeks, respectively. - name: image-expires-after - type: string - - default: "false" - description: Build a source image. - name: build-source-image - type: string - - default: "false" - description: Add built image into an OCI image index - name: build-image-index - type: string - - default: [] - description: Array of --build-arg values ("arg=value" strings) for buildah - name: build-args - type: array - - default: "" - description: Path to a file with build arguments for buildah, see https://www.mankier.com/1/buildah-build#--build-arg-file - name: build-args-file - type: string - - default: "false" - description: Whether to enable privileged mode, should be used only with remote VMs - name: privileged-nested - type: string - - name: buildah-format - default: docker - type: string - description: The format for the resulting image's mediaType. Valid values are oci or docker. - results: - - description: "" - name: IMAGE_URL - value: $(tasks.build-image-index.results.IMAGE_URL) - - description: "" - name: IMAGE_DIGEST - value: $(tasks.build-image-index.results.IMAGE_DIGEST) - - description: "" - name: CHAINS-GIT_URL - value: $(tasks.clone-repository.results.url) - - description: "" - name: CHAINS-GIT_COMMIT - value: $(tasks.clone-repository.results.commit) - tasks: - - name: init - params: - - name: image-url - value: $(params.output-image) - - name: rebuild - value: $(params.rebuild) - - name: skip-checks - value: $(params.skip-checks) - taskRef: - params: - - name: name - value: init - - name: bundle - value: quay.io/konflux-ci/tekton-catalog/task-init:0.2@sha256:bbf313b09740fb39b3343bc69ee94b2a2c21d16a9304f9b7c111c305558fc346 - - name: kind - value: task - resolver: bundles - - name: clone-repository - params: - - name: url - value: $(params.git-url) - - name: revision - value: $(params.revision) - runAfter: - - init - taskRef: - params: - - name: name - value: git-clone - - name: bundle - value: quay.io/konflux-ci/tekton-catalog/task-git-clone:0.1@sha256:90d2d42d17e6276ef45505cbb5a78598e5f5186257d0ee2260b3d4835f1c2d6b - - name: kind - value: task - resolver: bundles - when: - - input: $(tasks.init.results.build) - operator: in - values: - - "true" - workspaces: - - name: output - workspace: workspace - - name: basic-auth - workspace: git-auth - - name: prefetch-dependencies - params: - - name: input - value: $(params.prefetch-input) - runAfter: - - clone-repository - taskRef: - params: - - name: name - value: prefetch-dependencies - - name: bundle - value: quay.io/konflux-ci/tekton-catalog/task-prefetch-dependencies:0.2@sha256:846a3b883ee729c45a6714ab3a3688f6044a4d352655546d057e43e34b10149e - - name: kind - value: task - resolver: bundles - workspaces: - - name: source - workspace: workspace - - name: git-basic-auth - workspace: git-auth - - name: netrc - workspace: netrc - - name: build-container - params: - - name: IMAGE - value: $(params.output-image) - - name: DOCKERFILE - value: $(params.dockerfile) - - name: CONTEXT - value: $(params.path-context) - - name: HERMETIC - value: $(params.hermetic) - - name: PREFETCH_INPUT - value: $(params.prefetch-input) - - name: IMAGE_EXPIRES_AFTER - value: $(params.image-expires-after) - - name: COMMIT_SHA - value: $(tasks.clone-repository.results.commit) - - name: BUILD_ARGS - value: - - $(params.build-args[*]) - - name: BUILD_ARGS_FILE - value: $(params.build-args-file) - - name: PRIVILEGED_NESTED - value: $(params.privileged-nested) - - name: BUILDAH_FORMAT - value: $(params.buildah-format) - runAfter: - - prefetch-dependencies - taskRef: - params: - - name: name - value: buildah - - name: bundle - value: quay.io/konflux-ci/tekton-catalog/task-buildah:0.6@sha256:e8648dff9859d89a0dbaedd120eec2e07afbffc850e706d16d0ac479a905efa0 - - name: kind - value: task - resolver: bundles - when: - - input: $(tasks.init.results.build) - operator: in - values: - - "true" - workspaces: - - name: source - workspace: workspace - - name: build-image-index - params: - - name: IMAGE - value: $(params.output-image) - - name: COMMIT_SHA - value: $(tasks.clone-repository.results.commit) - - name: IMAGE_EXPIRES_AFTER - value: $(params.image-expires-after) - - name: ALWAYS_BUILD_INDEX - value: $(params.build-image-index) - - name: IMAGES - value: - - $(tasks.build-container.results.IMAGE_URL)@$(tasks.build-container.results.IMAGE_DIGEST) - - name: BUILDAH_FORMAT - value: $(params.buildah-format) - runAfter: - - build-container - taskRef: - params: - - name: name - value: build-image-index - - name: bundle - value: quay.io/konflux-ci/tekton-catalog/task-build-image-index:0.1@sha256:d94cad7f41be61074dd21c7dff26dab9217c3435a16f62813c1cb8382dd9aae6 - - name: kind - value: task - resolver: bundles - when: - - input: $(tasks.init.results.build) - operator: in - values: - - "true" - - name: build-source-image - params: - - name: BINARY_IMAGE - value: $(tasks.build-image-index.results.IMAGE_URL) - - name: BINARY_IMAGE_DIGEST - value: $(tasks.build-image-index.results.IMAGE_DIGEST) - runAfter: - - build-image-index - taskRef: - params: - - name: name - value: source-build - - name: bundle - value: quay.io/konflux-ci/tekton-catalog/task-source-build:0.3@sha256:268bf4dba7455ef3871d84bc26de1800b8221a0d1809c9f5101616bccfa84d33 - - name: kind - value: task - resolver: bundles - when: - - input: $(tasks.init.results.build) - operator: in - values: - - "true" - - input: $(params.build-source-image) - operator: in - values: - - "true" - workspaces: - - name: workspace - workspace: workspace - - name: deprecated-base-image-check - params: - - name: IMAGE_URL - value: $(tasks.build-image-index.results.IMAGE_URL) - - name: IMAGE_DIGEST - value: $(tasks.build-image-index.results.IMAGE_DIGEST) - runAfter: - - build-image-index - taskRef: - params: - - name: name - value: deprecated-image-check - - name: bundle - value: quay.io/konflux-ci/tekton-catalog/task-deprecated-image-check:0.5@sha256:f59175d9a0a60411738228dfe568af4684af4aa5e7e05c832927cb917801d489 - - name: kind - value: task - resolver: bundles - when: - - input: $(params.skip-checks) - operator: in - values: - - "false" - - name: clair-scan - params: - - name: image-digest - value: $(tasks.build-image-index.results.IMAGE_DIGEST) - - name: image-url - value: $(tasks.build-image-index.results.IMAGE_URL) - runAfter: - - build-image-index - taskRef: - params: - - name: name - value: clair-scan - - name: bundle - value: quay.io/konflux-ci/tekton-catalog/task-clair-scan:0.3@sha256:a7cc183967f89c4ac100d04ab8f81e54733beee60a0528208107c9a22d3c43af - - name: kind - value: task - resolver: bundles - when: - - input: $(params.skip-checks) - operator: in - values: - - "false" - - name: ecosystem-cert-preflight-checks - params: - - name: image-url - value: $(tasks.build-image-index.results.IMAGE_URL) - runAfter: - - build-image-index - taskRef: - params: - - name: name - value: ecosystem-cert-preflight-checks - - name: bundle - value: quay.io/konflux-ci/tekton-catalog/task-ecosystem-cert-preflight-checks:0.2@sha256:9568c51a5158d534248908b9b561cf67d2826ed4ea164ffd95628bb42380e6ec - - name: kind - value: task - resolver: bundles - when: - - input: $(params.skip-checks) - operator: in - values: - - "false" - - name: sast-snyk-check - params: - - name: image-digest - value: $(tasks.build-image-index.results.IMAGE_DIGEST) - - name: image-url - value: $(tasks.build-image-index.results.IMAGE_URL) - runAfter: - - build-image-index - taskRef: - params: - - name: name - value: sast-snyk-check - - name: bundle - value: quay.io/konflux-ci/tekton-catalog/task-sast-snyk-check:0.4@sha256:b487b08bd617d28adb47ee7c217b148b26b22bf906775b9f0ae7055acd042416 - - name: kind - value: task - resolver: bundles - when: - - input: $(params.skip-checks) - operator: in - values: - - "false" - workspaces: - - name: workspace - workspace: workspace - - name: clamav-scan - params: - - name: image-digest - value: $(tasks.build-image-index.results.IMAGE_DIGEST) - - name: image-url - value: $(tasks.build-image-index.results.IMAGE_URL) - runAfter: - - build-image-index - taskRef: - params: - - name: name - value: clamav-scan - - name: bundle - value: quay.io/konflux-ci/tekton-catalog/task-clamav-scan:0.3@sha256:b0bd59748cda4a7abf311e4f448e6c1d00c6b6d8c0ecc1c2eb33e08dc0e0b802 - - name: kind - value: task - resolver: bundles - when: - - input: $(params.skip-checks) - operator: in - values: - - "false" - - name: sast-coverity-check - params: - - name: image-digest - value: $(tasks.build-image-index.results.IMAGE_DIGEST) - - name: image-url - value: $(tasks.build-image-index.results.IMAGE_URL) - - name: IMAGE - value: $(params.output-image) - - name: DOCKERFILE - value: $(params.dockerfile) - - name: CONTEXT - value: $(params.path-context) - - name: HERMETIC - value: $(params.hermetic) - - name: PREFETCH_INPUT - value: $(params.prefetch-input) - - name: IMAGE_EXPIRES_AFTER - value: $(params.image-expires-after) - - name: COMMIT_SHA - value: $(tasks.clone-repository.results.commit) - - name: BUILD_ARGS - value: - - $(params.build-args[*]) - - name: BUILD_ARGS_FILE - value: $(params.build-args-file) - runAfter: - - coverity-availability-check - taskRef: - params: - - name: name - value: sast-coverity-check - - name: bundle - value: quay.io/konflux-ci/tekton-catalog/task-sast-coverity-check:0.3@sha256:9d572d7f7486224318d59de1b166efa68e59e17bac0785e2ecdcd014fe8e44d5 - - name: kind - value: task - resolver: bundles - when: - - input: $(params.skip-checks) - operator: in - values: - - "false" - - input: $(tasks.coverity-availability-check.results.STATUS) - operator: in - values: - - success - workspaces: - - name: source - workspace: workspace - - name: coverity-availability-check - runAfter: - - build-image-index - taskRef: - params: - - name: name - value: coverity-availability-check - - name: bundle - value: quay.io/konflux-ci/tekton-catalog/task-coverity-availability-check:0.2@sha256:db2b267dc15e4ed17f704ee91b8e9b38068e1a35b1018a328fdca621819d74c6 - - name: kind - value: task - resolver: bundles - when: - - input: $(params.skip-checks) - operator: in - values: - - "false" - - name: sast-shell-check - params: - - name: image-digest - value: $(tasks.build-image-index.results.IMAGE_DIGEST) - - name: image-url - value: $(tasks.build-image-index.results.IMAGE_URL) - runAfter: - - build-image-index - taskRef: - params: - - name: name - value: sast-shell-check - - name: bundle - value: quay.io/konflux-ci/tekton-catalog/task-sast-shell-check:0.1@sha256:cdfb0f552b30e7bb38a87c6b10ea3cd7f8dbf2e3b913fe27319cd9588c6d49e6 - - name: kind - value: task - resolver: bundles - when: - - input: $(params.skip-checks) - operator: in - values: - - "false" - workspaces: - - name: workspace - workspace: workspace - - name: sast-unicode-check - params: - - name: image-digest - value: $(tasks.build-image-index.results.IMAGE_DIGEST) - - name: image-url - value: $(tasks.build-image-index.results.IMAGE_URL) - runAfter: - - build-image-index - taskRef: - params: - - name: name - value: sast-unicode-check - - name: bundle - value: quay.io/konflux-ci/tekton-catalog/task-sast-unicode-check:0.3@sha256:23c7a716cf5596d5b09e57a13ad20572de2a13d47bf708b13141f5e341845133 - - name: kind - value: task - resolver: bundles - when: - - input: $(params.skip-checks) - operator: in - values: - - "false" - workspaces: - - name: workspace - workspace: workspace - - name: apply-tags - params: - - name: IMAGE_URL - value: $(tasks.build-image-index.results.IMAGE_URL) - - name: IMAGE_DIGEST - value: $(tasks.build-image-index.results.IMAGE_DIGEST) - runAfter: - - build-image-index - taskRef: - params: - - name: name - value: apply-tags - - name: bundle - value: quay.io/konflux-ci/tekton-catalog/task-apply-tags:0.2@sha256:f44be1bf0262471f2f503f5e19da5f0628dcaf968c86272a2ad6b4871e708448 - - name: kind - value: task - resolver: bundles - - name: push-dockerfile - params: - - name: IMAGE - value: $(tasks.build-image-index.results.IMAGE_URL) - - name: IMAGE_DIGEST - value: $(tasks.build-image-index.results.IMAGE_DIGEST) - - name: DOCKERFILE - value: $(params.dockerfile) - - name: CONTEXT - value: $(params.path-context) - runAfter: - - build-image-index - taskRef: - params: - - name: name - value: push-dockerfile - - name: bundle - value: quay.io/konflux-ci/tekton-catalog/task-push-dockerfile:0.1@sha256:74e982c07a808eaa5b1d8c126cafcbf3cc6ce94c883cf0845b55ce8064674b45 - - name: kind - value: task - resolver: bundles - workspaces: - - name: workspace - workspace: workspace - - name: rpms-signature-scan - params: - - name: image-url - value: $(tasks.build-image-index.results.IMAGE_URL) - - name: image-digest - value: $(tasks.build-image-index.results.IMAGE_DIGEST) - runAfter: - - build-image-index - taskRef: - params: - - name: name - value: rpms-signature-scan - - name: bundle - value: quay.io/konflux-ci/tekton-catalog/task-rpms-signature-scan:0.2@sha256:1b6c20ab3dbfb0972803d3ebcb2fa72642e59400c77bd66dfd82028bdd09e120 - - name: kind - value: task - resolver: bundles - when: - - input: $(params.skip-checks) - operator: in - values: - - "false" - workspaces: - - name: workspace - - name: git-auth - optional: true - - name: netrc - optional: true - taskRunTemplate: - serviceAccountName: build-pipeline-migration-planner-ui - workspaces: - - name: workspace - volumeClaimTemplate: - metadata: - creationTimestamp: - spec: - accessModes: - - ReadWriteOnce - resources: - requests: - storage: 1Gi - status: {} - - name: git-auth - secret: - secretName: '{{ git_auth_secret }}' -status: {} diff --git a/.tekton/migration-planner-ui-pull-request.yaml b/.tekton/migration-planner-ui-pull-request.yaml index b3e4c15..9da32e4 100644 --- a/.tekton/migration-planner-ui-pull-request.yaml +++ b/.tekton/migration-planner-ui-pull-request.yaml @@ -30,10 +30,6 @@ spec: value: build-tools/Dockerfile - name: path-context value: . - - name: build-args - value: - - MIGRATION_PLANNER_UI_GIT_COMMIT={{revision}} - - MIGRATION_PLANNER_UI_VERSION={{revision}} pipelineSpec: description: | This pipeline is ideal for building container images from a Containerfile while reducing network traffic. @@ -197,12 +193,69 @@ spec: workspace: workspace - name: basic-auth workspace: git-auth + - name: update-version + params: + - name: SOURCE_GIT_COMMIT + value: $(tasks.clone-repository.results.commit) + - name: SOURCE_GIT_TAG + value: "{{target_branch}}-pull-request" + runAfter: + - clone-repository + taskSpec: + metadata: + name: update-version-task + labels: + app.kubernetes.io/version: "0.1" + params: + - name: SOURCE_GIT_COMMIT + type: string + - name: SOURCE_GIT_TAG + type: string + workspaces: + - name: source + steps: + - name: update-package-json + image: registry.access.redhat.com/ubi9/ubi-minimal:latest + workingDir: $(workspaces.source.path)/source + script: | + #!/bin/bash + set -e + + # Install jq if not available + microdnf install -y jq + + echo "===== Version Update - Before =====" + echo "Current package.json version fields:" + if [ -f package.json ]; then + jq '{uiVersionName, uiGitCommit}' package.json + else + echo "package.json not found!" + exit 1 + fi + + # Run the version script to update package.json + export SOURCE_GIT_COMMIT=$(params.SOURCE_GIT_COMMIT) + export SOURCE_GIT_TAG=$(params.SOURCE_GIT_TAG) + echo "" + echo "Setting version from parameters:" + echo " SOURCE_GIT_COMMIT=${SOURCE_GIT_COMMIT}" + echo " SOURCE_GIT_TAG=${SOURCE_GIT_TAG}" + echo "" + bash hack/version.sh --update-package-json + + echo "" + echo "===== Version Update - After =====" + echo "Updated package.json version fields:" + jq '{uiVersionName, uiGitCommit}' package.json + workspaces: + - name: source + workspace: workspace - name: prefetch-dependencies params: - name: input value: $(params.prefetch-input) runAfter: - - clone-repository + - update-version taskRef: params: - name: name diff --git a/.tekton/migration-planner-ui-push.yaml b/.tekton/migration-planner-ui-push.yaml index 04c0265..84c834b 100644 --- a/.tekton/migration-planner-ui-push.yaml +++ b/.tekton/migration-planner-ui-push.yaml @@ -27,10 +27,6 @@ spec: value: build-tools/Dockerfile - name: path-context value: . - - name: build-args - value: - - MIGRATION_PLANNER_UI_GIT_COMMIT={{revision}} - - MIGRATION_PLANNER_UI_VERSION={{revision}} pipelineSpec: description: | This pipeline is ideal for building container images from a Containerfile while reducing network traffic. @@ -194,12 +190,69 @@ spec: workspace: workspace - name: basic-auth workspace: git-auth + - name: update-version + params: + - name: SOURCE_GIT_COMMIT + value: $(tasks.clone-repository.results.commit) + - name: SOURCE_GIT_TAG + value: "{{target_branch}}-dev" + runAfter: + - clone-repository + taskSpec: + metadata: + name: update-version-task + labels: + app.kubernetes.io/version: "0.1" + params: + - name: SOURCE_GIT_COMMIT + type: string + - name: SOURCE_GIT_TAG + type: string + workspaces: + - name: source + steps: + - name: update-package-json + image: registry.access.redhat.com/ubi9/ubi-minimal:latest + workingDir: $(workspaces.source.path)/source + script: | + #!/bin/bash + set -e + + # Install jq if not available + microdnf install -y jq + + echo "===== Version Update - Before =====" + echo "Current package.json version fields:" + if [ -f package.json ]; then + jq '{uiVersionName, uiGitCommit}' package.json + else + echo "package.json not found!" + exit 1 + fi + + # Run the version script to update package.json + export SOURCE_GIT_COMMIT=$(params.SOURCE_GIT_COMMIT) + export SOURCE_GIT_TAG=$(params.SOURCE_GIT_TAG) + echo "" + echo "Setting version from parameters:" + echo " SOURCE_GIT_COMMIT=${SOURCE_GIT_COMMIT}" + echo " SOURCE_GIT_TAG=${SOURCE_GIT_TAG}" + echo "" + bash hack/version.sh --update-package-json + + echo "" + echo "===== Version Update - After =====" + echo "Updated package.json version fields:" + jq '{uiVersionName, uiGitCommit}' package.json + workspaces: + - name: source + workspace: workspace - name: prefetch-dependencies params: - name: input value: $(params.prefetch-input) runAfter: - - clone-repository + - update-version taskRef: params: - name: name diff --git a/.tekton/migration-planner-ui-tag.yaml b/.tekton/migration-planner-ui-tag.yaml index 89a71bb..4bbb074 100644 --- a/.tekton/migration-planner-ui-tag.yaml +++ b/.tekton/migration-planner-ui-tag.yaml @@ -22,15 +22,11 @@ spec: - name: revision value: '{{revision}}' - name: output-image - value: quay.io/redhat-user-workloads/assisted-migration-tenant/migration-planner-ui:{{git_tag}} + value: quay.io/redhat-user-workloads/assisted-migration-tenant/migration-planner-ui:{{revision}} - name: dockerfile value: build-tools/Dockerfile - name: path-context value: . - - name: build-args - value: - - MIGRATION_PLANNER_UI_GIT_COMMIT={{revision}} - - MIGRATION_PLANNER_UI_VERSION={{git_tag}} pipelineSpec: description: | This pipeline is ideal for building container images from a Containerfile while reducing network traffic. @@ -194,12 +190,69 @@ spec: workspace: workspace - name: basic-auth workspace: git-auth + - name: update-version + params: + - name: SOURCE_GIT_COMMIT + value: $(tasks.clone-repository.results.commit) + - name: SOURCE_GIT_TAG + value: "{{git_tag}}" + runAfter: + - clone-repository + taskSpec: + metadata: + name: update-version-task + labels: + app.kubernetes.io/version: "0.1" + params: + - name: SOURCE_GIT_COMMIT + type: string + - name: SOURCE_GIT_TAG + type: string + workspaces: + - name: source + steps: + - name: update-package-json + image: registry.access.redhat.com/ubi9/ubi-minimal:latest + workingDir: $(workspaces.source.path)/source + script: | + #!/bin/bash + set -e + + # Install jq if not available + microdnf install -y jq + + echo "===== Version Update - Before =====" + echo "Current package.json version fields:" + if [ -f package.json ]; then + jq '{uiVersionName, uiGitCommit}' package.json + else + echo "package.json not found!" + exit 1 + fi + + # Run the version script to update package.json + export SOURCE_GIT_COMMIT=$(params.SOURCE_GIT_COMMIT) + export SOURCE_GIT_TAG=$(params.SOURCE_GIT_TAG) + echo "" + echo "Setting version from parameters:" + echo " SOURCE_GIT_COMMIT=${SOURCE_GIT_COMMIT}" + echo " SOURCE_GIT_TAG=${SOURCE_GIT_TAG}" + echo "" + bash hack/version.sh --update-package-json + + echo "" + echo "===== Version Update - After =====" + echo "Updated package.json version fields:" + jq '{uiVersionName, uiGitCommit}' package.json + workspaces: + - name: source + workspace: workspace - name: prefetch-dependencies params: - name: input value: $(params.prefetch-input) runAfter: - - clone-repository + - update-version taskRef: params: - name: name diff --git a/Makefile b/Makefile index 220e2bd..0008246 100644 --- a/Makefile +++ b/Makefile @@ -11,10 +11,7 @@ HOST_PORT ?= 8080 CONTAINERFILE_PATH ?= deploy/dev/Containerfile CONTAINERIGNORE_PATH ?= deploy/dev/.containerignore -SOURCE_GIT_COMMIT ?=$(shell git rev-parse "HEAD^{commit}" 2>/dev/null) -SOURCE_GIT_COMMIT_SHORT ?=$(shell git rev-parse --short "HEAD^{commit}" 2>/dev/null) -SOURCE_GIT_TAG ?=$(shell git describe --always --tags --abbrev=7 --match '[0-9]*\.[0-9]*\.[0-9]*' --match 'v[0-9]*\.[0-9]*\.[0-9]*' || echo 'v0.0.0-unknown-$(SOURCE_GIT_COMMIT_SHORT)') -IMAGE_TAG ?= $(SOURCE_GIT_COMMIT) +IMAGE_TAG ?= $(shell git rev-parse "HEAD^{commit}" 2>/dev/null) oc: # Verify oc installed, in linux install it if not already installed ifeq ($(OC_BIN),) @@ -41,28 +38,21 @@ install: build-standalone: install @echo "Building standalone application..." rm -rf dist-standalone - MIGRATION_PLANNER_UI_GIT_COMMIT=$(SOURCE_GIT_COMMIT) \ - MIGRATION_PLANNER_UI_VERSION=$(SOURCE_GIT_TAG) \ - npm run build:standalone + @bash -c '. ./hack/version.sh && npm run build:standalone' @echo "✅ Standalone build completed in dist-standalone/" # Run the standalone application locally run-standalone: install @echo "Running standalone application..." rm -rf dist-standalone - MIGRATION_PLANNER_UI_GIT_COMMIT=$(SOURCE_GIT_COMMIT) \ - MIGRATION_PLANNER_UI_VERSION=$(SOURCE_GIT_TAG) \ - PLANNER_LOCAL_DEV=true \ - npm run start:standalone + @bash -c '. ./hack/version.sh && PLANNER_LOCAL_DEV=true npm run start:standalone' @echo "✅ Standalone run completed" # Legacy build target (federated module) build: install @echo "Building federated module..." rm -rf dist - MIGRATION_PLANNER_UI_GIT_COMMIT=$(SOURCE_GIT_COMMIT) \ - MIGRATION_PLANNER_UI_VERSION=$(SOURCE_GIT_TAG) \ - npm run build + @bash -c '. ./hack/version.sh && npm run build' @echo "✅ Federated build completed in dist/" lint: install diff --git a/hack/version.sh b/hack/version.sh new file mode 100755 index 0000000..8debec9 --- /dev/null +++ b/hack/version.sh @@ -0,0 +1,59 @@ +#!/usr/bin/env bash + +# This script computes version information for the Migration Planner UI. +# It can be sourced to set environment variables or executed to print them. +# +# Usage: +# ./hack/version.sh # Print version variables +# ./hack/version.sh --update-package-json # Update package.json with version info +# source ./hack/version.sh # Set environment variables + +set -o errexit +set -o nounset +set -o pipefail + +# Get the directory of this script +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +REPO_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)" +PACKAGE_JSON="${REPO_ROOT}/package.json" + +# Get git information +GIT_COMMIT="${SOURCE_GIT_COMMIT:-$(git rev-parse HEAD 2>/dev/null || echo 'unknown')}" +GIT_TAG="${SOURCE_GIT_TAG:-$(git describe --tags --always --abbrev=7 --match '[0-9]*\.[0-9]*\.[0-9]*' --match 'v[0-9]*\.[0-9]*\.[0-9]*' 2>/dev/null || echo 'v0.0.0-unknown')}" + +# Export version variables +export MIGRATION_PLANNER_UI_GIT_COMMIT="${GIT_COMMIT}" +export MIGRATION_PLANNER_UI_VERSION="${GIT_TAG}" + +# Function to update package.json +update_package_json() { + echo "Updating ${PACKAGE_JSON} with version information..." + + # Check if jq is installed + if ! command -v jq &> /dev/null; then + echo "Error: jq is required to update package.json. Please install jq." + exit 1 + fi + + # Update package.json using jq + jq --arg version "${MIGRATION_PLANNER_UI_VERSION}" \ + --arg commit "${MIGRATION_PLANNER_UI_GIT_COMMIT}" \ + '.uiVersionName = $version | .uiGitCommit = $commit' \ + "${PACKAGE_JSON}" > "${PACKAGE_JSON}.tmp" + + mv "${PACKAGE_JSON}.tmp" "${PACKAGE_JSON}" + + echo "✅ Updated package.json:" + echo " uiVersionName: ${MIGRATION_PLANNER_UI_VERSION}" + echo " uiGitCommit: ${MIGRATION_PLANNER_UI_GIT_COMMIT}" +} + +# If executed (not sourced), handle command line arguments +if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then + if [[ "${1:-}" == "--update-package-json" ]]; then + update_package_json + else + echo "MIGRATION_PLANNER_UI_GIT_COMMIT=${MIGRATION_PLANNER_UI_GIT_COMMIT}" + echo "MIGRATION_PLANNER_UI_VERSION=${MIGRATION_PLANNER_UI_VERSION}" + fi +fi diff --git a/package.json b/package.json index dfa8815..a9db06f 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,7 @@ { "name": "migration-assessment", + "uiVersionName": "unknown", + "uiGitCommit": "unknown", "private": false, "engines": { "node": ">=18.0.0", diff --git a/src/common/version.ts b/src/common/version.ts index 2e552fc..9c5b0e1 100644 --- a/src/common/version.ts +++ b/src/common/version.ts @@ -1,6 +1,8 @@ import { InfoApi } from '@migration-planner-ui/api-client/apis'; import { Configuration } from '@migration-planner-ui/api-client/runtime'; +import buildManifest from '../../package.json'; + // API info interface based on the migration-planner API response interface ApiInfo { versionName: string; @@ -32,7 +34,9 @@ export interface VersionInfo { */ // eslint-disable-next-line @typescript-eslint/explicit-function-return-type export const getMigrationPlannerUiVersion = () => { - return process.env.MIGRATION_PLANNER_UI_VERSION || 'unknown'; + return ( + process.env.MIGRATION_PLANNER_UI_VERSION || buildManifest.uiVersionName + ); }; /** @@ -40,7 +44,9 @@ export const getMigrationPlannerUiVersion = () => { */ // eslint-disable-next-line @typescript-eslint/explicit-function-return-type export const getGitCommit = () => { - return process.env.MIGRATION_PLANNER_UI_GIT_COMMIT || 'unknown'; + return ( + process.env.MIGRATION_PLANNER_UI_GIT_COMMIT || buildManifest.uiGitCommit + ); }; /**