.github: Update multiple golang versions

Usually last two versions are supported, so make sure we keep them
both updated, not only just the latest. But try to also update the
newest unsupported version in case there was a window where the update
happened and then new major version was released.
This commit is contained in:
Krzesimir Nowak 2021-08-09 17:43:17 +02:00
parent 5daf5eb1ca
commit 69ef222c6f
2 changed files with 74 additions and 37 deletions

View File

@ -2,43 +2,77 @@
set -euo pipefail set -euo pipefail
# trim the 3rd part in the input semver, e.g. from 1.14.3 to 1.14 function join_by {
VERSION_SHORT=${VERSION_NEW%.*} local d=${1-} f=${2-}
UPDATE_NEEDED=1 if shift 2; then
printf '%s' "$f" "${@/#/$d}"
fi
}
# create a mapping between short version and new version, e.g. 1.16 -> 1.16.3
declare -A VERSIONS
for version_new in ${VERSIONS_NEW}; do
version_new_trimmed="${version_new%.*}"
if [[ "${version_new_trimmed%.*}" = "${version_new_trimmed}" ]]; then
version_new_trimmed="${version_new}"
fi
VERSIONS["${version_new_trimmed}"]="${version_new}"
done
. .github/workflows/common.sh . .github/workflows/common.sh
prepare_git_repo prepare_git_repo
if ! checkout_branches "go-${VERSION_NEW}-${TARGET}"; then branch_name="go-$(join_by '-and-' ${VERSIONS_NEW})-${TARGET}"
UPDATE_NEEDED=0
if ! checkout_branches "${branch_name}"; then
exit 0 exit 0
fi fi
pushd "${SDK_OUTER_SRCDIR}/third_party/coreos-overlay" >/dev/null || exit
# Parse the Manifest file for already present source files and keep the latest version in the current series # Parse the Manifest file for already present source files and keep the latest version in the current series
# DIST go1.17.src.tar.gz ... => 1.17 # DIST go1.17.src.tar.gz ... => 1.17
# DIST go1.17.1.src.tar.gz ... => 1.17.1 # DIST go1.17.1.src.tar.gz ... => 1.17.1
VERSION_OLD=$(sed -n "s/^DIST go\(${VERSION_SHORT}\.*[0-9]*\)\.src.*/\1/p" dev-lang/go/Manifest | sort -ruV | head -n1) declare -a UPDATED_VERSIONS_OLD UPDATED_VERSIONS_NEW
if [[ "${VERSION_NEW}" = "${VERSION_OLD}" ]]; then any_different=0
echo "already the latest Go, nothing to do" START_NUMBER=1
UPDATE_NEEDED=0 for version_short in "${!VERSIONS[@]}"; do
exit 0 pushd "${SDK_OUTER_SRCDIR}/third_party/coreos-overlay" >/dev/null || exit
VERSION_NEW="${VERSIONS["${version_short}"]}"
VERSION_OLD=$(sed -n "s/^DIST go\(${version_short}\(\.*[0-9]*\)\?\)\.src.*/\1/p" dev-lang/go/Manifest | sort -ruV | head -n1)
if [[ -z "${VERSION_OLD}" ]]; then
echo "${version_short} is not packaged, skipping"
popd >/dev/null || exit
continue
fi fi
if [[ "${VERSION_NEW}" = "${VERSION_OLD}" ]]; then
echo "${version_short} is already at the latest (${VERSION_NEW}), skipping"
popd >/dev/null || exit
continue
fi
UPDATED_VERSIONS_OLD+=("${VERSION_OLD}")
UPDATED_VERSIONS_NEW+=("${VERSION_NEW}")
any_different=1
EBUILD_FILENAME=$(get_ebuild_filename "dev-lang" "go" "${VERSION_OLD}") EBUILD_FILENAME=$(get_ebuild_filename "dev-lang" "go" "${VERSION_OLD}")
git mv "${EBUILD_FILENAME}" "dev-lang/go/go-${VERSION_NEW}.ebuild" git mv "${EBUILD_FILENAME}" "dev-lang/go/go-${VERSION_NEW}.ebuild"
popd >/dev/null || exit popd >/dev/null || exit
URL="https://go.googlesource.com/go/+/refs/tags/go${VERSION_NEW}"
generate_update_changelog 'Go' "${VERSION_NEW}" "${URL}" 'golang'
generate_patches dev-lang go Go generate_patches dev-lang go Go
((START_NUMBER++))
done
if [[ $any_different -eq 0 ]]; then
echo "go packages were already at the latest versions, nothing to do"
exit 0
fi
apply_patches apply_patches
echo ::set-output name=VERSION_OLD::"${VERSION_OLD}" vo_gh="$(join_by ' and ' "${UPDATED_VERSIONS_OLD[@]}")"
echo ::set-output name=UPDATE_NEEDED::"${UPDATE_NEEDED}" vn_gh="$(join_by ' and ' "${UPDATED_VERSIONS_NEW[@]}")"
echo ::set-output name=VERSIONS_OLD::"${vo_gh}"
echo ::set-output name=VERSIONS_NEW::"${vn_gh}"
echo ::set-output name=BRANCH_NAME::"${branch_name}"
echo ::set-output name=UPDATE_NEEDED::"1"

View File

@ -5,21 +5,24 @@ on:
workflow_dispatch: workflow_dispatch:
jobs: jobs:
get-go-release: get-go-releases:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
with: with:
token: ${{ secrets.GITHUB_TOKEN }} token: ${{ secrets.GITHUB_TOKEN }}
- name: Fetch latest Go release - name: Fetch latest Go releases
id: fetch-latest-release id: fetch-latest-releases
env: env:
GO_VERSION: "1.17" GO_VERSIONS: "1.16 1.17 1.18"
run: | run: |
git clone --depth=1 --no-checkout https://github.com/golang/go git clone --depth=1 --no-checkout https://github.com/golang/go
versionMain=$(git -C go ls-remote --tags origin | cut -f2 | sed -n "/refs\/tags\/go${GO_VERSION}\.[0-9]*$/s/^refs\/tags\/go//p" | egrep -v -e '(beta|rc)' | sort -ruV | head -1) versionsMain=()
for goversion in ${GO_VERSIONS}; do
versionsMain+=($(git -C go ls-remote --tags origin | cut -f2 | sed -n "/refs\/tags\/go${goversion}\(\.[0-9]*\)\?$/s/^refs\/tags\/go//p" | egrep -v -e '(beta|rc)' | sort -ruV | head -1))
done
rm -rf go rm -rf go
echo ::set-output name=VERSION_MAIN::$(echo ${versionMain}) echo ::set-output name=VERSIONS_MAIN::$(echo ${versionsMain[*]})
echo ::set-output name=BASE_BRANCH_MAIN::main echo ::set-output name=BASE_BRANCH_MAIN::main
- name: Set up Flatcar SDK - name: Set up Flatcar SDK
id: setup-flatcar-sdk id: setup-flatcar-sdk
@ -28,20 +31,20 @@ jobs:
id: apply-patch-main id: apply-patch-main
env: env:
TARGET: main TARGET: main
BASE_BRANCH: ${{ steps.fetch-latest-release.outputs.BASE_BRANCH_MAIN }} BASE_BRANCH: ${{ steps.fetch-latest-releases.outputs.BASE_BRANCH_MAIN }}
PATH: ${{ steps.setup-flatcar-sdk.outputs.path }} PATH: ${{ steps.setup-flatcar-sdk.outputs.path }}
VERSION_NEW: ${{ steps.fetch-latest-release.outputs.VERSION_MAIN }} VERSIONS_NEW: ${{ steps.fetch-latest-releases.outputs.VERSIONS_MAIN }}
run: .github/workflows/go-apply-patch.sh run: .github/workflows/go-apply-patch.sh
- name: Create pull request for main - name: Create pull request for main
uses: peter-evans/create-pull-request@v3 uses: peter-evans/create-pull-request@v3
if: steps.apply-patch-main.outputs.UPDATE_NEEDED == 1 if: steps.apply-patch-main.outputs.UPDATE_NEEDED == 1
with: with:
token: ${{ secrets.GITHUB_TOKEN }} token: ${{ secrets.GITHUB_TOKEN }}
base: ${{ steps.fetch-latest-release.outputs.BASE_BRANCH_MAIN }} base: ${{ steps.fetch-latest-releases.outputs.BASE_BRANCH_MAIN }}
branch: go-${{ steps.fetch-latest-release.outputs.VERSION_MAIN }}-main branch: ${{ steps.apply-patch-main.outputs.BRANCH_NAME }}
author: Flatcar Buildbot <buildbot@flatcar-linux.org> author: Flatcar Buildbot <buildbot@flatcar-linux.org>
committer: Flatcar Buildbot <buildbot@flatcar-linux.org> committer: Flatcar Buildbot <buildbot@flatcar-linux.org>
title: Upgrade Go in main from ${{ steps.apply-patch-main.outputs.VERSION_OLD }} to ${{ steps.fetch-latest-release.outputs.VERSION_MAIN }} title: Upgrade Go from ${{ steps.apply-patch-main.outputs.VERSIONS_OLD }} to ${{ steps.apply-patch-main.outputs.VERSIONS_NEW }}
commit-message: Upgrade Go in main from ${{ steps.apply-patch-main.outputs.VERSION_OLD }} to ${{ steps.fetch-latest-release.outputs.VERSION_MAIN }} commit-message: Upgrade Go from ${{ steps.apply-patch-main.outputs.VERSIONS_OLD }} to ${{ steps.apply-patch-main.outputs.VERSIONS_NEW }}
body: Upgrade Go in main from ${{ steps.apply-patch-main.outputs.VERSION_OLD }} to ${{ steps.fetch-latest-release.outputs.VERSION_MAIN }} body: Upgrade Go from ${{ steps.apply-patch-main.outputs.VERSIONS_OLD }} to ${{ steps.apply-patch-main.outputs.VERSIONS_NEW }}
labels: main labels: main