Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions stepaction/git-clone/git-clone.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ spec:
name: url
- description: The epoch timestamp of the commit that was fetched by this StepAction.
name: committer-date
- description: The Git tag pointing at the fetched commit, or a fallback (git describe
/ shortsha).
name: commit-tag
image: $(params.gitInitImage)
env:
- name: HOME
Expand Down Expand Up @@ -261,3 +264,10 @@ spec:
printf "%s" "${RESULT_COMMITTER_DATE}" > "$(step.results.committer-date.path)"
printf "%s" "${RESULT_SHA}" > "$(step.results.commit.path)"
printf "%s" "${PARAM_URL}" > "$(step.results.url.path)"

git fetch origin 'refs/tags/*:refs/tags/*' --depth=1 2>/dev/null || git fetch origin 'refs/tags/*:refs/tags/*' 2>/dev/null || true
COMMIT_TAG="$(git tag --points-at HEAD | head -n1)"
if [ -z "${COMMIT_TAG}" ] ; then
COMMIT_TAG="$(git describe --tags --always 2>/dev/null || echo "no-tag")"
fi
Comment on lines +268 to +272
printf "%s" "${COMMIT_TAG}" > "$(step.results.commit-tag.path)"
27 changes: 27 additions & 0 deletions stepaction/git-clone/tests/run.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,30 @@ spec:
workspaces:
- name: output
emptyDir: {}
---
apiVersion: tekton.dev/v1
kind: TaskRun
metadata:
name: git-clone-stepaction-commit-tag
spec:
taskSpec:
workspaces:
- name: output
steps:
- ref:
name: git-clone
params:
- name: url
value: https://github.com/kelseyhightower/nocode
- name: revision
value: "1.0.0"
- name: depth
value: "0"
- name: output-path
value: $(workspaces.output.path)
podTemplate:
securityContext:
fsGroup: 65532
workspaces:
- name: output
emptyDir: {}
1 change: 1 addition & 0 deletions task/git-clone/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ spec:
| `commit` | The precise commit SHA that was fetched |
| `url` | The precise URL that was fetched |
| `committer-date` | The epoch timestamp of the fetched commit |
| `commit-tag` | The Git tag pointing at the fetched commit, or a fallback (git describe / shortsha) |

## Platforms

Expand Down
9 changes: 9 additions & 0 deletions task/git-clone/git-clone.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ spec:
name: url
- description: The epoch timestamp of the commit that was fetched by this Task.
name: committer-date
- description: The Git tag pointing at the fetched commit, or a fallback (git describe / shortsha).
name: commit-tag
Comment on lines +120 to +121
steps:
- env:
- name: HOME
Expand Down Expand Up @@ -249,6 +251,13 @@ spec:
printf "%s" "${RESULT_COMMITTER_DATE}" > "$(results.committer-date.path)"
printf "%s" "${RESULT_SHA}" > "$(results.commit.path)"
printf "%s" "${PARAM_URL}" > "$(results.url.path)"

git fetch origin 'refs/tags/*:refs/tags/*' --depth=1 2>/dev/null || git fetch origin 'refs/tags/*:refs/tags/*' 2>/dev/null || true
COMMIT_TAG="$(git tag --points-at HEAD | head -n1)"
if [ -z "${COMMIT_TAG}" ] ; then
COMMIT_TAG="$(git describe --tags --always 2>/dev/null || echo "no-tag")"
fi
Comment on lines +255 to +259
printf "%s" "${COMMIT_TAG}" > "$(results.commit-tag.path)"
securityContext:
runAsNonRoot: true
runAsUser: 65532
Expand Down
21 changes: 21 additions & 0 deletions task/git-clone/tests/run.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,24 @@ spec:
value: https://github.com/kelseyhightower/nocode
- name: sparseCheckoutDirectories
value: "CONTRIBUTING.md,STYLE.md"
---
apiVersion: tekton.dev/v1
kind: TaskRun
metadata:
name: git-clone-run-commit-tag
spec:
workspaces:
- name: output
emptyDir: {}
taskRef:
name: git-clone
podTemplate:
securityContext:
fsGroup: 65532
params:
- name: url
value: https://github.com/kelseyhightower/nocode
- name: revision
value: 1.0.0
- name: depth
value: "0"