Skip to content

SDK version upgrade #1871

SDK version upgrade

SDK version upgrade #1871

Workflow file for this run

name: SDK version upgrade
on:
schedule:
- cron: "0 */12 * * *"
jobs:
check:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
run: |
git config --global url."https://${{ secrets.GH_TOKEN }}:@github.com/".insteadOf "https://github.com/"
git clone https://github.com/actions-hub/kubectl .
- name: Check if new version exist
id: check
run: |
SDK_VERSION=$(curl --silent "https://api.github.com/repos/kubernetes/kubernetes/releases" | jq '.[] | select(.prerelease==false) | .tag_name' | sort -V -r | head -n 1 | tr -d '"')
LATEST_VERSION=$(curl --silent "https://api.github.com/repos/actions-hub/kubectl/releases/latest" | tac | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
DOCKER_VERSION=$(cat $GITHUB_WORKSPACE/Dockerfile | grep "ARG KUBE_VERSION=" | sed -E 's/ARG KUBE_VERSION=//' | tr -d '"')
echo "Provider tag: ${SDK_VERSION}"
echo "Current tag: ${LATEST_VERSION}"
echo "Docker tag: ${DOCKER_VERSION}"
if [ "$SDK_VERSION" != "$LATEST_VERSION" ]; then
if [ "$LATEST_VERSION" = "`echo -e "$SDK_VERSION\n$LATEST_VERSION" | sort -V | head -n1`" ]; then
if [ "$DOCKER_VERSION" == "$LATEST_VERSION" ]; then
echo "New version detected: $SDK_VERSION. Latest in this repo: $LATEST_VERSION. Updating..."
echo ::set-output name=newest::"yes"
echo "SDK_VERSION=${SDK_VERSION}" >> $GITHUB_ENV
echo "LATEST_VERSION=${LATEST_VERSION}" >> $GITHUB_ENV
else
echo ::error::"Tag version in Dockerfile ($DOCKER_VERSION) is not the same as the latest release ($LATEST_VERSION)."
exit 1
fi
else
echo ::set-output name=newest::"no"
fi
else
echo ::set-output name=newest::"no"
fi
- name: Check if version tag is semver and if docker hub has it
id: test
if: steps.check.outputs.newest == 'yes'
run: |
if [[ $SDK_VERSION =~ ^v[0-9]+(\.[0-9]+){2,3}$ ]]; then
echo "$SDK_VERSION it's semver"
else
echo ::error::"$SDK_VERSION it's not semver!"
exit 1
fi
echo "Checking if release with $SDK_VERSION tag is available"
status_code=$(curl --silent -I https://storage.googleapis.com/kubernetes-release/release/v1.24.0/bin/linux/amd64/kubectl | grep -E "^HTTP" | awk -F " " '{print $2}')
echo "Docker hub respond with $status_code"
if [ "$status_code" == "200" ] ; then
echo ::set-output name=exist::"yes"
echo "Newest version available"
else
echo ::set-output name=exist::"no"
echo "Docker hub returns $status_code"
fi
- name: Modify Dockerfile
id: modify
if: success() && steps.check.outputs.newest == 'yes' && steps.test.outputs.exist == 'yes'
run: |
git config --global url."https://${{ secrets.GH_TOKEN }}:@github.com/".insteadOf "https://github.com/"
git config --global user.name "Serhiy Mytrovtsiy"
git config --global user.email "[email protected]"
git checkout master
FROM_LINE="ARG KUBE_VERSION=\"$LATEST_VERSION\""
TO_LINE="ARG KUBE_VERSION=\"$SDK_VERSION\""
sed -i "s/${FROM_LINE}/${TO_LINE}/" $GITHUB_WORKSPACE/Dockerfile
git add $GITHUB_WORKSPACE/Dockerfile
git commit -m "updated kubectl to $SDK_VERSION"
git push
echo ::set-output name=tag::$SDK_VERSION
- name: Create new release
if: success() && steps.modify.outputs.tag != '0'
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
with:
tag_name: ${{ steps.modify.outputs.tag }}
release_name: ${{ steps.modify.outputs.tag }}
draft: false
prerelease: false