Skip to content

Commit

Permalink
creating git metadata task/replacing normal timestamp with latest com…
Browse files Browse the repository at this point in the history
…mit ts
  • Loading branch information
SiddharthRajaraman committed May 28, 2024
1 parent 50502fd commit 3db49f6
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 27 deletions.
37 changes: 22 additions & 15 deletions .tekton/ansible-ai-connect-service-pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -215,19 +215,6 @@ spec:
workspace: workspace
- name: git-basic-auth
workspace: git-auth

- name: get-timestamp
taskSpec:
steps:
- name: output-timestamp
image: busybox
command: ["/bin/sh", "-c"]
args:
- echo -n $(date "+%Y%m%d%H%M") > $(results.time-stamp.path)
results:
- name: time-stamp


- name: build-container
params:
- name: IMAGE
Expand All @@ -247,7 +234,7 @@ spec:
- name: BUILD_ARGS_FILE
value: $(params.build-args-file)
- name: BUILD_ARGS
value: ["IMAGE_TAGS=pr-{{pull_request_number}} pr-{{pull_request_number}}.$(tasks.get-timestamp.results.time-stamp)", "GIT_COMMIT=$(tasks.clone-repository.results.commit)"]
value: ["IMAGE_TAGS=pr-{{pull_request_number}} pr-{{pull_request_number}}.$(tasks.git-metadata.results.commit-timestamp)", "GIT_COMMIT=$(tasks.clone-repository.results.commit)"]
runAfter:
- prefetch-dependencies
taskRef:
Expand All @@ -272,7 +259,7 @@ spec:
- name: IMAGE
value: $(tasks.build-container.results.IMAGE_URL)
- name: ADDITIONAL_TAGS
value: ["pr-{{pull_request_number}}", "pr-{{pull_request_number}}.$(tasks.get-timestamp.results.time-stamp)"]
value: ["pr-{{pull_request_number}}", "pr-{{pull_request_number}}.$(tasks.git-metadata.results.commit-timestamp)"]
runAfter:
- build-container
taskRef:
Expand All @@ -284,6 +271,26 @@ spec:
- name: kind
value: task
resolver: bundles
- name: git-metadata
runAfter:
- clone-repository
workspaces:
- name: source
workspace: workspace
taskSpec:
workspaces:
- name: source
steps:
- name: get-commit-timestamp
image: alpine/git
script: |
#!/bin/sh
set -euo pipefail
cd "$(workspaces.source.path)/source"
echo $(date -d @$(git log -1 --format=%at) "+%Y%m%d%H%M") > $(results.commit-timestamp.path)
results:
- name: commit-timestamp
- name: build-source-image
params:
- name: BINARY_IMAGE
Expand Down
34 changes: 22 additions & 12 deletions .tekton/ansible-ai-connect-service-push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -208,16 +208,6 @@ spec:
workspace: workspace
- name: git-basic-auth
workspace: git-auth
- name: get-timestamp
taskSpec:
steps:
- name: output-timestamp
image: busybox
command: ["/bin/sh", "-c"]
args:
- echo -n $(date "+%Y%m%d%H%M") > $(results.time-stamp.path)
results:
- name: time-stamp
- name: build-container
params:
- name: IMAGE
Expand All @@ -237,7 +227,7 @@ spec:
- name: BUILD_ARGS_FILE
value: $(params.build-args-file)
- name: BUILD_ARGS
value: ["IMAGE_TAGS=latest 1.0.$(tasks.get-timestamp.results.time-stamp)", "GIT_COMMIT=$(tasks.clone-repository.results.commit)"]
value: ["IMAGE_TAGS=latest 1.0.$(tasks.git-metadata.results.commit-timestamp)", "GIT_COMMIT=$(tasks.clone-repository.results.commit)"]
runAfter:
- prefetch-dependencies
taskRef:
Expand All @@ -262,7 +252,7 @@ spec:
- name: IMAGE
value: $(tasks.build-container.results.IMAGE_URL)
- name: ADDITIONAL_TAGS
value: ["latest", "1.0.$(tasks.get-timestamp.results.time-stamp)"]
value: ["latest", "1.0.$(tasks.git-metadata.results.commit-timestamp)"]
runAfter:
- build-container
taskRef:
Expand All @@ -274,6 +264,26 @@ spec:
- name: kind
value: task
resolver: bundles
- name: git-metadata
runAfter:
- clone-repository
workspaces:
- name: source
workspace: workspace
taskSpec:
workspaces:
- name: source
steps:
- name: get-commit-timestamp
image: alpine/git
script: |
#!/bin/sh
set -euo pipefail
cd "$(workspaces.source.path)/source"
echo $(date -d @$(git log -1 --format=%at) "+%Y%m%d%H%M") > $(results.commit-timestamp.path)
results:
- name: commit-timestamp
- name: build-source-image
params:
- name: BINARY_IMAGE
Expand Down

0 comments on commit 3db49f6

Please sign in to comment.