Step: ocm-ci-fastforward

This workflow fast forwards a source branch to a destination branch in a GitHub repo.

Container image used for this step: open-cluster-management/builder:go1.16-linux

open-cluster-management/builder:go1.16-linux resolves to an image imported from the specified imagestream tag on the build farm (documentation).

Environment

In addition to the default environment, the step exposes the following:

Variable Name Type Variable Content
GITHUB_USER Parameter[?] The GitHub user name. (default: acm-cicd-prow-bot)
GITHUB_TOKEN_FILE Parameter[?] The file that stores the GitHub token. Should match credentials stanza mount path. (default: /etc/acm-cicd-github/token)
SOURCE_BRANCH Parameter[?] The branch that you want to fast forward FROM. Default is "main". (default: main)
DESTINATION_BRANCH Parameter[?] The branch that you want to fast forward TO.

Source Code

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
#!/bin/bash

shopt -s extglob

ocm_dir=$(mktemp -d -t ocm-XXXXX)
cd "$ocm_dir" || exit 1
export HOME="$ocm_dir"

log_file="${ARTIFACT_DIR}/deploy.log"
log() {
    local ts
    ts=$(date --iso-8601=seconds)
    echo "$ts" "$@" | tee -a "$log_file"
}

log "INFO Checking settings"
log "    REPO_OWNER         = $REPO_OWNER"
log "    REPO_NAME          = $REPO_NAME"
log "    JOB_TYPE           = $JOB_TYPE"
log "    GITHUB_USER        = $GITHUB_USER"
log "    GITHUB_TOKEN_FILE  = $GITHUB_TOKEN_FILE"
log "    SOURCE_BRANCH      = $SOURCE_BRANCH"
log "    DESTINATION_BRANCH = $DESTINATION_BRANCH"

if [[ "$REPO_OWNER" == "openshift" ]]; then
    log "INFO This test is being run as a rehearsal. Exiting"
    exit 0
fi

if [[ "$JOB_TYPE" != "postsubmit" ]]; then
    log "ERROR This workflow may only be run as a postsubmit job"
    exit 1
fi

if [[ -z "$GITHUB_USER" ]]; then
    log "ERROR GITHUB_USER may not be empty"
    exit 1
fi

if [[ ! -r "${GITHUB_TOKEN_FILE}" ]]; then
    log "ERROR GITHUB_TOKEN_FILE missing or not readable"
    exit 1
fi

if [[ -z "$SOURCE_BRANCH" ]]; then
    log "ERROR SOURCE_BRANCH may not be empty"
    exit 1
fi

if [[ -z "$DESTINATION_BRANCH" ]]; then
    log "ERROR DESTINATION_BRANCH may not be empty"
    exit 1
fi

log "INFO Cloning DESTINATION_BRANCH"
token=$(cat "$GITHUB_TOKEN_FILE")
repo="github.com/$REPO_OWNER/$REPO_NAME"
repo_url="https://${GITHUB_USER}:${token}@${repo}.git"

if ! git clone -b "$DESTINATION_BRANCH" "$repo_url" ; then
    log "INFO DESTINATION_BRANCH does not exist. Will create it"
    log "INFO Cloning SOURCE_BRANCH"
    if ! git clone -b "$SOURCE_BRANCH" "$repo_url" ; then
        log "ERROR Could not clone SOURCE_BRANCH"
        log "      repo_url = $repo_url"
        exit 1
    fi

    log "INFO Changing into repo directory"
    cd "$REPO_NAME" || exit 1

    log "INFO Checking out new DESTINATION_BRANCH"
    if ! git checkout -b "$DESTINATION_BRANCH" ; then
        log "ERROR Could not checkout DESTINATION_BRANCH"
        exit 1
    fi

    log "INFO Pushing DESTINATION_BRANCH to origin"
    if ! git push -u origin "$DESTINATION_BRANCH" ; then
        log "ERROR Could not push to origin DESTINATION_BRANCH"
        exit 1
    fi

    log "INFO Fast forward complete"
    exit 0
fi

log "INFO Changing into repo directory"
cd "$REPO_NAME" || exit 1

log "INFO Pulling from SOURCE_BRANCH into DESTINATION_BRANCH"
if ! git pull --ff-only origin "$SOURCE_BRANCH" ; then
    log "ERROR Could not pull from SOURCE_BRANCH"
    exit 1
fi

log "INFO Pushing to origin/DESTINATION_BRANCH"
if ! git push ; then
    log "ERROR Could not push to DESTINATION_BRANCH"
    exit 1
fi

log "INFO Fast forward complete"

Properties

Property Value Description
Resource requests (cpu) 100m Used in .resources.requests of the pod running this step.
Resource requests (memory) 100Mi Used in .resources.requests of the pod running this step.

GitHub Link:

https://github.com/openshift/release/blob/master/ci-operator/step-registry/ocm/ci/fastforward/ocm-ci-fastforward-ref.yaml

Owners:

Approvers:

Source code for this page located on GitHub