Skip to content

Commit

Permalink
Add mechanism to run a sed script directly without using jq
Browse files Browse the repository at this point in the history
It also introduces the release_tag strategy in order to make testing easier

Fixes kairos-io/kairos#1934
  • Loading branch information
mauromorales committed Oct 24, 2023
1 parent e78455b commit 393a530
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 0 deletions.
14 changes: 14 additions & 0 deletions extensions/autobump-github/luet-autobump-github
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ for i in $(echo "$PKG_LIST" | jq -rc '.packages[]'); do
# Best effort: get original package name from labels
GITHUB_REPO=$(yq r $DEFINITION_FILE "${YQ_ARGS}labels.\"github.repo\"")
GITHUB_OWNER=$(yq r $DEFINITION_FILE "${YQ_ARGS}labels.\"github.owner\"")
GITHUB_TAG=$(yq r $DEFINITION_FILE "${YQ_ARGS}labels.\"github.tag\"")

# Strategy can be: release, tags or "refs"
# Refs parses thru git tags
Expand All @@ -203,6 +204,9 @@ for i in $(echo "$PKG_LIST" | jq -rc '.packages[]'); do
# A json map of replace rules
STRING_REPLACE=$(yq r $DEFINITION_FILE "${YQ_ARGS}labels.\"autobump.string_replace\"")

# A sed script to run after the version has been retrieved
SED_REPLACE=$(yq r $DEFINITION_FILE "${YQ_ARGS}labels.\"autobump.sed_script\"")


# A json list of strings contained in the releases to skip (e.g. betas)
SKIP_IF_CONTAIN=$(yq r $DEFINITION_FILE "${YQ_ARGS}labels.\"autobump.skip_if_contains\"")
Expand Down Expand Up @@ -280,6 +284,12 @@ for i in $(echo "$PKG_LIST" | jq -rc '.packages[]'); do
fi
elif [ "${AUTOBUMP_STRATEGY}" == "sabayon" ]; then
LATEST_TAG=$(latest_sabayon $ORIGINAL_PACKAGE_NAME $ORIGINAL_PACKAGE_CATEGORY)
elif [[ "$AUTOBUMP_STRATEGY" == "release_tag" ]] && [ -n "${GITHUB_OWNER}" ] && [ -n "${GITHUB_REPO}" ] && [ -n "${GITHUB_TAG}" ]; then
if [ -n "$TOKEN" ]; then
LATEST_TAG=$(curl -H "Authorization: token $TOKEN" https://api.github.com/repos/$GITHUB_OWNER/$GITHUB_REPO/releases/tags/$GITHUB_TAG -s | jq .tag_name -r)
else
LATEST_TAG=$(curl https://api.github.com/repos/$GITHUB_OWNER/$GITHUB_REPO/releases/tags/$GITHUB_TAG -s | jq .tag_name -r )
fi
elif [ -n "${GITHUB_OWNER}" ] && [ -n "${GITHUB_REPO}" ]; then
if [ -n "$TOKEN" ]; then
LATEST_TAG=$(curl -H "Authorization: token $TOKEN" https://api.github.com/repos/$GITHUB_OWNER/$GITHUB_REPO/tags -s | jq -r '.[].name | select(. | test("'$VERSION_CONTAINS'"))' -r | head -1 )
Expand All @@ -288,6 +298,10 @@ for i in $(echo "$PKG_LIST" | jq -rc '.packages[]'); do
fi
fi

if [ -n "$SED_REPLACE" ]; then
LATEST_TAG=$(echo "$LATEST_TAG" | sed -r "$SED_REPLACE")
fi

ORIGINAL_NEW_TAG=${LATEST_TAG}
LATEST_TAG=${LATEST_TAG#v} # semver
LATEST_TAG=${LATEST_TAG#$TRIM_PREFIX} # go..
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
packages:
- name: k3s-openrc
category: k8s
version: "1.25.2"
k3s_version: "2"
labels:
github.owner: "k3s-io"
github.repo: "k3s"
github.tag: "v1.28.2+k3s1"
autobump.strategy: "release_tag"
autobump.sed_script: 's/\+k3s1//g'
uri:
- https://github.com/k3s-io/k3s
license: "APL-2"
description: " Lightweight Kubernetes "
- name: k3s-openrc
category: k8s
version: "1.26.3"
k3s_version: "2"
labels:
github.owner: "k3s-io"
github.repo: "k3s"
autobump.strategy: "release"
autobump.sed_replace: "s/+k3s1//g"
uri:
- https://github.com/k3s-io/k3s
license: "APL-2"
description: " Lightweight Kubernetes "
- name: k3s-openrc
category: k8s
version: "1.27.3"
k3s_version: "2"
labels:
github.owner: "k3s-io"
github.repo: "k3s"
autobump.strategy: "release"
autobump.sed_replace: "s/+k3s1//g"
uri:
- https://github.com/k3s-io/k3s
license: "APL-2"
description: " Lightweight Kubernetes "
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
packages:
- name: k3s-openrc
category: k8s
version: "1.28.2"
k3s_version: "2"
labels:
github.owner: "k3s-io"
github.repo: "k3s"
github.tag: "v1.28.2+k3s1"
autobump.strategy: "release_tag"
autobump.sed_script: 's/\+k3s1//g'
uri:
- https://github.com/k3s-io/k3s
license: "APL-2"
description: " Lightweight Kubernetes "
- name: k3s-openrc
category: k8s
version: "1.26.3"
k3s_version: "2"
labels:
github.owner: "k3s-io"
github.repo: "k3s"
autobump.strategy: "release"
autobump.sed_replace: "s/+k3s1//g"
uri:
- https://github.com/k3s-io/k3s
license: "APL-2"
description: " Lightweight Kubernetes "
- name: k3s-openrc
category: k8s
version: "1.27.3"
k3s_version: "2"
labels:
github.owner: "k3s-io"
github.repo: "k3s"
autobump.strategy: "release"
autobump.sed_replace: "s/+k3s1//g"
uri:
- https://github.com/k3s-io/k3s
license: "APL-2"
description: " Lightweight Kubernetes "

0 comments on commit 393a530

Please sign in to comment.