Skip to content

Commit

Permalink
This patch splits git-rebase task from the git directory
Browse files Browse the repository at this point in the history
Changes include:
  - moves git-rebase task to the task directory
  - copies and modifies readme file for git-rebase from git directory
  - copies examples and tests directory from git directory

Issue: tektoncd#386

Signed-off-by: Puneet Punamiya <[email protected]>
  • Loading branch information
PuneetPunamiya authored and popcor255 committed Jul 14, 2020
1 parent b4ce0b6 commit fcd33d4
Show file tree
Hide file tree
Showing 13 changed files with 678 additions and 0 deletions.
68 changes: 68 additions & 0 deletions task/git-rebase/0.1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Git Task

This `Task` is Git task to work with repositories used by other tasks
in your Pipeline.

## `git-rebase`

This [task](../git/git-rebase.yaml) will `rebase` the branch based
on the user input. Before rebase, if `squashing` of the commits is required,
then it can be done by providing the `squash count` i.e number of commits to squash.

### Workspaces

* **source**: A workspace that contains the fetched git repository.

### Parameters

* **SQUASH_COUNT**: Number of commits to squash in the branch.
(_only required if squashing needs to be performed_).
* **COMMIT_MSG**: Commit message to add in commit after the
squashing is done (_only required if squashing needs to be performed_).
* **GIT_USER_NAME**: Git user name to use for rebase (_required_).
* **GIT_USER_EMAIL**: Git user email to use for rebase (_required_).
* **PULL_REMOTE_NAME**: Git remote name from which we have to pull
and rebase.(_default_: `origin`).
* **PULL_REMOTE_URL**: Git remote URL from which we have to
pull and rebase (_required to set remote_).
* **PULL_BRANCH_NAME**: Git branch name from which we have to
pull and rebase (_required_).
* **PUSH_REMOTE_NAME**: Git remote name to push after rebase(_default_: `origin`).
* **PUSH_REMOTE_URL**: Git remote URL to push after rebase(_required_).
* **PUSH_BRANCH_NAME**: Git branch name to push after rebase (_required_).

### Results

* **commit**: The precise commit SHA after the rebase.

### Usage

This task needs authentication to git in order to push after the rebase.
This can be done via `secrets` and `service account`. Refer [this](../git/git-rebase-example)
example to create secret and service account for the git authentication.

[Git Rebase](../git/git-rebase-example) pipeline has two tasks, one to clone a
git repository in the provided workspace and other to perform rebase operation.
Here, [git-clone](../git/git-clone.yaml) task is used to clone the repository.

A workspace called "shared-workspace" is passed first to the `git-clone`
Task for the code to be checked out on and then to the `git-rebase` Task
to perform the rebase operation.

Remote name, Remote URL and Branch name needs to provided in the input
to set the remote in order to perfrom push and pull operations.

[Git Rebase](../git/git-rebase-example/run.yaml) pipeline can be referred to
create a `pipeline` and `pipelinerun`.

**NOTE**

* If `two factor authentication` is enabled in your git account, then
`access-token` for the respective git platform must be provided
in the `password` field while adding secrets.

* In the params for `git-clone` task, make sure that param value
for `depth` must be greater than param value for `SQUASH_COUNT` in `git-rebase` task.

* If there are chances for `merge conflicts`, then that needs to resolved before
doing rebase through this task as task will fail, if any merge conflict is found.
63 changes: 63 additions & 0 deletions task/git-rebase/0.1/examples/git-cli/pipeline.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
---
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
name: git-pipeline
spec:
workspaces:
- name: shared-workspace
- name: input
tasks:
- name: fetch-repository
taskRef:
name: git-clone
workspaces:
- name: output
workspace: shared-workspace
params:
- name: url
value: https://github.com/kelseyhightower/nocode
- name: subdirectory
value: ""
- name: deleteExisting
value: "true"
- name: git-cli
taskRef:
name: git-cli
runAfter:
- fetch-repository
workspaces:
- name: source
workspace: shared-workspace
- name: input
workspace: input
params:
- name: GIT_USER_NAME
value: git_username
- name: GIT_USER_EMAIL
value: git_email
- name: GIT_SCRIPT
value: |
cp $(workspaces.input.path)/* $(workspaces.source.path)
git add .
git commit -m 'Add sample file'
git push origin master
results:
- name: commit
---
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
name: git-pipeline-run
spec:
serviceAccountName: git-service-account
pipelineRef:
name: git-pipeline
workspaces:
- name: shared-workspace
persistentvolumeclaim:
claimName: source-pvc
- name: input
configmap:
name: files
11 changes: 11 additions & 0 deletions task/git-rebase/0.1/examples/git-cli/pvc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: source-pvc
spec:
resources:
requests:
storage: 500Mi
accessModes:
- ReadWriteOnce
13 changes: 13 additions & 0 deletions task/git-rebase/0.1/examples/git-cli/secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
apiVersion: v1
kind: Secret
metadata:
name: github-auth
annotations:
# Replace with the desired domain name.
tekton.dev/git-0: https://github.com
type: kubernetes.io/basic-auth
stringData:
username: git_username
# Access token should be provided here, if 2 factor authentication is enabled.
password: git_password
7 changes: 7 additions & 0 deletions task/git-rebase/0.1/examples/git-cli/service-account.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: git-service-account
secrets:
- name: github-auth
86 changes: 86 additions & 0 deletions task/git-rebase/0.1/examples/git-clone-checking-out-a-branch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
name: cat-branch-readme
spec:
description: |
cat-branch-readme takes a git repository and a branch name and
prints the README.md file from that branch. This is an example
Pipeline demonstrating the following:
- Using the git-clone catalog Task to clone a branch
- Passing a cloned repo to subsequent Tasks using a Workspace.
- Ordering Tasks in a Pipeline using "runAfter" so that
git-clone completes before we try to read from the Workspace.
- Using a volumeClaimTemplate Volume as a Workspace.
- Avoiding hard-coded paths by using a Workspace's path
variable instead.
params:
- name: repo-url
type: string
description: The git repository URL to clone from.
- name: branch-name
type: string
description: The git branch to clone.
workspaces:
- name: shared-data
description: |
This workspace will receive the cloned git repo and be passed
to the next Task for the repo's README.md file to be read.
tasks:
- name: fetch-repo
taskRef:
name: git-clone
workspaces:
- name: output
workspace: shared-data
params:
- name: url
value: $(params.repo-url)
- name: revision
value: $(params.branch-name)
- name: cat-readme
runAfter: ["fetch-repo"] # Wait until the clone is done before reading the readme.
workspaces:
- name: source
workspace: shared-data
taskSpec:
workspaces:
- name: source
steps:
- image: zshusers/zsh:4.3.15
script: |
#!/usr/bin/env zsh
cat $(workspaces.source.path)/README.md
---
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
name: git-clone-checking-out-a-branch
spec:
podTemplate:
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: "tekton.dev/pipelineRun"
operator: In
values:
- git-clone-checking-out-a-branch
topologyKey: kubernetes.io/hostname
pipelineRef:
name: cat-branch-readme
workspaces:
- name: shared-data
volumeClaimTemplate:
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
params:
- name: repo-url
value: https://github.com/tektoncd/pipeline.git
- name: branch-name
value: release-v0.12.x
87 changes: 87 additions & 0 deletions task/git-rebase/0.1/examples/git-clone-checking-out-a-commit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
name: checking-out-a-revision
spec:
description: |
checking-out-a-revision takes a git repository and a commit SHA
and validates that cloning the revision succeeds. This is an example
Pipeline demonstrating the following:
- Using the git-clone catalog Task to clone a specific commit
- Passing a cloned repo to subsequent Tasks using a Workspace.
- Ordering Tasks in a Pipeline using "runAfter" so that
git-clone completes before we try to read from the Workspace.
- Using a volumeClaimTemplate Volume as a Workspace.
- Avoiding hard-coded paths by using a Workspace's path
variable instead.
params:
- name: repo-url
type: string
description: The git repository URL to clone from.
- name: commit
type: string
description: The git commit to fetch.
workspaces:
- name: shared-data
description: |
This workspace will receive the cloned git repo and be passed
to the next Task for the commit to be checked.
tasks:
- name: fetch-repo
taskRef:
name: git-clone
workspaces:
- name: output
workspace: shared-data
params:
- name: url
value: $(params.repo-url)
- name: revision
value: $(params.commit)
- name: compare-received-commit-to-expected
runAfter: ["fetch-repo"] # Wait until the clone is done before reading the readme.
params:
- name: expected-commit
value: $(params.commit)
workspaces:
- name: source
workspace: shared-data
taskSpec:
params:
- name: expected-commit
workspaces:
- name: source
steps:
- image: alpine/git:v2.24.3
script: |
#!/usr/bin/env sh
cd $(workspaces.source.path)
receivedCommit=$(git rev-parse HEAD)
if [ $receivedCommit != $(params.expected-commit) ]; then
echo "Expected commit $(params.expected-commit) but received $receivedCommit."
exit 1
else
echo "Received commit $receivedCommit as expected."
fi
---
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
generateName: git-clone-checking-out-a-commit-
spec:
pipelineRef:
name: checking-out-a-revision
workspaces:
- name: shared-data
volumeClaimTemplate:
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 500Mi
params:
- name: repo-url
value: https://github.com/tektoncd/pipeline.git
- name: commit
value: 301b41380e95382a18b391c2165fa3a6a3de93b0 # Tekton Pipeline's first ever commit!
Loading

0 comments on commit fcd33d4

Please sign in to comment.