-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(RELEASE-1252): make run-file-updates task idempotent
Signed-off-by: Jing Qi <jinqi@redhat.com> The PR is to make the task idempotent by ensuring that a new MR isn't created unnecessarily when one already exists with the same content in the seed and replacements of paths parameter. And it added some logic to check the keys in the paths parameter. If the keys exist but their content does not require any replacement, return success.
- Loading branch information
Showing
4 changed files
with
191 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
...ks/process-file-updates-task/tests/test-process-file-updates-replacements-idempotent.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
--- | ||
apiVersion: tekton.dev/v1 | ||
kind: Pipeline | ||
metadata: | ||
name: test-process-file-updates-replacements-idempotent | ||
spec: | ||
description: | | ||
Run the process-file-updates task with replacements. No commit | ||
is created if there is a mocked MR with the same content. | ||
workspaces: | ||
- name: tests-workspace | ||
tasks: | ||
- name: setup | ||
workspaces: | ||
- name: pipeline | ||
workspace: tests-workspace | ||
taskSpec: | ||
workspaces: | ||
- name: pipeline | ||
steps: | ||
- name: setup-values | ||
image: quay.io/konflux-ci/release-service-utils:e633d51cd41d73e4b3310face21bb980af7a662f | ||
script: | | ||
#!/usr/bin/env bash | ||
set -eux | ||
mkdir -p "$(workspaces.pipeline.path)/$(context.pipelineRun.uid)/file-updates" | ||
cd "$(workspaces.pipeline.path)/$(context.pipelineRun.uid)/file-updates" | ||
mkdir replace-idempotent | ||
cd replace-idempotent | ||
git config --global init.defaultBranch main | ||
git init . | ||
git config --global user.email "test@test.com" | ||
git config --global user.name "tester" | ||
mkdir addons | ||
cat > "addons/my-addon2.yaml" << EOF | ||
indexImage: | ||
name: test | ||
EOF | ||
git add addons/my-addon2.yaml | ||
git commit -m "prior commit" | ||
- name: run-task | ||
taskRef: | ||
name: process-file-updates-task | ||
params: | ||
- name: upstream_repo | ||
value: "https://some.gitlab/test/replace-idempotent" | ||
- name: repo | ||
value: "https://some.gitlab/test/replace-idempotent" | ||
- name: ref | ||
value: "main" | ||
- name: paths | ||
value: >- | ||
[{"path":"addons/my-addon2.yaml","replacements":[{"key":".indexImage", | ||
"replacement":"|indexImage.*|indexImage: Jack|"}]}] | ||
- name: application | ||
value: "scott" | ||
- name: file_updates_secret | ||
value: "file-updates-secret" | ||
- name: tempDir | ||
value: "$(workspaces.pipeline.path)/$(context.pipelineRun.uid)/file-updates" | ||
- name: internalRequestPipelineRunName | ||
value: $(context.pipelineRun.name) | ||
workspaces: | ||
- name: pipeline | ||
workspace: tests-workspace | ||
runAfter: | ||
- setup | ||
- name: check-result | ||
runAfter: | ||
- run-task | ||
params: | ||
- name: fileUpdatesInfo | ||
value: $(tasks.run-task.results.fileUpdatesInfo) | ||
- name: fileUpdatesState | ||
value: $(tasks.run-task.results.fileUpdatesState) | ||
- name: tempDir | ||
value: "$(workspaces.pipeline.path)/$(context.pipelineRun.uid)/file-updates" | ||
taskSpec: | ||
params: | ||
- name: fileUpdatesInfo | ||
type: string | ||
- name: fileUpdatesState | ||
type: string | ||
- name: tempDir | ||
type: string | ||
steps: | ||
- name: check-result | ||
image: quay.io/konflux-ci/release-service-utils:e633d51cd41d73e4b3310face21bb980af7a662f | ||
script: | | ||
#!/usr/bin/env bash | ||
set -eux | ||
cd "$(params.tempDir)/replace-idempotent" | ||
commits=$(git log --oneline | wc -l) | ||
|
||
echo "Test no more commit created except the one in setup step" | ||
test "${commits}" == "1" | ||
rm -rf "$(params.tempDir)" | ||
|
||
workspaces: | ||
- name: pipeline | ||
workspace: tests-workspace |