Skip to content

Instantly share code, notes, and snippets.

@ralphbean
Last active May 22, 2024 19:35
Show Gist options
  • Select an option

  • Save ralphbean/dbee2755b4077caa4056a46660d2907f to your computer and use it in GitHub Desktop.

Select an option

Save ralphbean/dbee2755b4077caa4056a46660d2907f to your computer and use it in GitHub Desktop.

Revisions

  1. ralphbean revised this gist May 22, 2024. 1 changed file with 8 additions and 3 deletions.
    11 changes: 8 additions & 3 deletions expand-taskref.sh
    Original file line number Diff line number Diff line change
    @@ -6,14 +6,19 @@
    filename=$1
    taskname=$2

    task=$(cat "$filename" | yq ".spec.pipelineSpec.tasks[] | select(.name == \"$taskname\")")
    prefix=".spec.pipelineSpec"
    kind=$(yq .kind "$filename")
    if [ $kind == "Pipeline" ]; then
    prefix=".spec"
    fi
    task=$(cat "$filename" | yq "$prefix.tasks[] | select(.name == \"$taskname\")")
    bundle=$(echo "$task" | yq ".taskRef.params[] | select(.name == \"bundle\") | .value")
    bundle=$(echo $bundle | awk -F '@' '{ print $1 }')
    repo=$(echo $bundle | awk -F ':' '{ print $1 }')
    for layer in $(skopeo inspect --no-tags "docker://$bundle" | jq -r '.Layers[]'); do
    spec=$(oras blob fetch --no-tty $repo@$layer -o - | tar zxf - --to-stdout | yq .spec)
    done

    yq -i "del(.spec.pipelineSpec.tasks[] | select(.name == \"$taskname\") | .taskRef)" $filename
    yq -i "(.spec.pipelineSpec.tasks[] | select(.name == \"$taskname\") | .taskSpec) = $spec" $filename
    yq -i "del($prefix.tasks[] | select(.name == \"$taskname\") | .taskRef)" $filename
    yq -i "($prefix.tasks[] | select(.name == \"$taskname\") | .taskSpec) = $spec" $filename
    sed -i 's/\\\\/\\/g' $filename
  2. ralphbean revised this gist May 16, 2024. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions expand-taskref.sh
    Original file line number Diff line number Diff line change
    @@ -16,3 +16,4 @@ done

    yq -i "del(.spec.pipelineSpec.tasks[] | select(.name == \"$taskname\") | .taskRef)" $filename
    yq -i "(.spec.pipelineSpec.tasks[] | select(.name == \"$taskname\") | .taskSpec) = $spec" $filename
    sed -i 's/\\\\/\\/g' $filename
  3. ralphbean revised this gist May 16, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion expand-taskref.sh
    100644 → 100755
    Original file line number Diff line number Diff line change
    @@ -11,7 +11,7 @@ bundle=$(echo "$task" | yq ".taskRef.params[] | select(.name == \"bundle\") | .v
    bundle=$(echo $bundle | awk -F '@' '{ print $1 }')
    repo=$(echo $bundle | awk -F ':' '{ print $1 }')
    for layer in $(skopeo inspect --no-tags "docker://$bundle" | jq -r '.Layers[]'); do
    spec=$(oras blob fetch --no-tty $repo@$layer -o - | tar zxf - --to-stdout)
    spec=$(oras blob fetch --no-tty $repo@$layer -o - | tar zxf - --to-stdout | yq .spec)
    done

    yq -i "del(.spec.pipelineSpec.tasks[] | select(.name == \"$taskname\") | .taskRef)" $filename
  4. ralphbean created this gist Apr 19, 2024.
    18 changes: 18 additions & 0 deletions expand-taskref.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    #!/bin/bash -e
    # Given a filename with a pipelines-as-code pipelinerun and a task name within it
    # remove the bundle taskref and replace it with an inline version of the task definition.
    # For hacking.

    filename=$1
    taskname=$2

    task=$(cat "$filename" | yq ".spec.pipelineSpec.tasks[] | select(.name == \"$taskname\")")
    bundle=$(echo "$task" | yq ".taskRef.params[] | select(.name == \"bundle\") | .value")
    bundle=$(echo $bundle | awk -F '@' '{ print $1 }')
    repo=$(echo $bundle | awk -F ':' '{ print $1 }')
    for layer in $(skopeo inspect --no-tags "docker://$bundle" | jq -r '.Layers[]'); do
    spec=$(oras blob fetch --no-tty $repo@$layer -o - | tar zxf - --to-stdout)
    done

    yq -i "del(.spec.pipelineSpec.tasks[] | select(.name == \"$taskname\") | .taskRef)" $filename
    yq -i "(.spec.pipelineSpec.tasks[] | select(.name == \"$taskname\") | .taskSpec) = $spec" $filename