diff --git a/.github/workflows/go-apply-patch.sh b/.github/workflows/go-apply-patch.sh new file mode 100755 index 0000000000..f22dfd1b1f --- /dev/null +++ b/.github/workflows/go-apply-patch.sh @@ -0,0 +1,69 @@ +#!/bin/bash + +set -euo pipefail + +source "${GHA_SCRIPTS_DIR}/.github/workflows/common.sh" + +prepare_git_repo + +# 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 + +branch_name="go-$(join_by '-and-' ${VERSIONS_NEW})-main" + +# 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.1.src.tar.gz ... => 1.17.1 +declare -a UPDATED_VERSIONS_OLD UPDATED_VERSIONS_NEW +any_different=0 +for version_short in "${!VERSIONS[@]}"; do + pushd "${SDK_OUTER_OVERLAY}" + 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 + continue + fi + if [[ "${VERSION_NEW}" = "${VERSION_OLD}" ]]; then + echo "${version_short} is already at the latest (${VERSION_NEW}), skipping" + popd + 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}") + git mv "${EBUILD_FILENAME}" "dev-lang/go/go-${VERSION_NEW}.ebuild" + + popd + + URL="https://go.dev/doc/devel/release#go${VERSION_NEW}" + + generate_update_changelog 'Go' "${VERSION_NEW}" "${URL}" 'go' + + commit_changes dev-lang/go "${VERSION_OLD}" "${VERSION_NEW}" +done + +cleanup_repo + +if [[ $any_different -eq 0 ]]; then + echo "go packages were already at the latest versions, nothing to do" + exit 0 +fi + +vo_gh="$(join_by ' and ' "${UPDATED_VERSIONS_OLD[@]}")" +vn_gh="$(join_by ' and ' "${UPDATED_VERSIONS_NEW[@]}")" + +echo "VERSIONS_OLD=${vo_gh}" >>"${GITHUB_OUTPUT}" +echo "VERSIONS_NEW=${vn_gh}" >>"${GITHUB_OUTPUT}" +echo "BRANCH_NAME=${branch_name}" >>"${GITHUB_OUTPUT}" +echo 'UPDATE_NEEDED=1' >>"${GITHUB_OUTPUT}" diff --git a/.github/workflows/go-current-major-versions.sh b/.github/workflows/go-current-major-versions.sh new file mode 100755 index 0000000000..d279161b76 --- /dev/null +++ b/.github/workflows/go-current-major-versions.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +set -euo pipefail + +source "${GHA_SCRIPTS_DIR}/.github/workflows/common.sh" + +pushd "${SDK_OUTER_OVERLAY}" + +versions=() +for ebuild in dev-lang/go/go-*.ebuild; do + version="${ebuild##*/go-}" # 1.20.1-r1.ebuild or 1.19.ebuild + version="${version%.ebuild}" # 1.20.1-r1 or 1.19 + version="${version%%-*}" # 1.20.1 or 1.19 + short_version="${version%.*}" # 1.20 or 1 + if [[ "${short_version%.*}" = "${short_version}" ]]; then + # fix short version + short_version="${version}" + fi + + versions+=($(git ls-remote --tags https://github.com/golang/go | \ + cut -f2 | \ + sed --quiet "/refs\/tags\/go${short_version}\(\.[0-9]*\)\?$/s/^refs\/tags\/go//p" | \ + grep --extended-regexp --invert-match --regexp='(beta|rc)' | \ + sort --reverse --unique --version-sort | \ + head --lines=1)) +done + +popd + +echo "VERSIONS_NEW=${versions[*]}" >>"${GITHUB_OUTPUT}" diff --git a/.github/workflows/go-release-main.yaml b/.github/workflows/go-release-main.yaml new file mode 100644 index 0000000000..e2e43310e1 --- /dev/null +++ b/.github/workflows/go-release-main.yaml @@ -0,0 +1,47 @@ +name: Get the latest Go release for main +on: + schedule: + - cron: '15 7 * * 1' + workflow_dispatch: + +jobs: + get-go-releases: + runs-on: ubuntu-latest + steps: + - name: Check out scripts + uses: actions/checkout@v3 + with: + token: ${{ secrets.GITHUB_TOKEN }} + path: scripts + - name: Figure out latest Go release versions + id: go-latest-release + env: + GHA_SCRIPTS_DIR: "${{ github.workspace }}/scripts" + WORK_SCRIPTS_DIR: "${{ github.workspace }}/scripts" + run: scripts/.github/workflows/go-current-major-versions.sh + - name: Set up Flatcar SDK + id: setup-flatcar-sdk + env: + WORK_SCRIPTS_DIR: "${{ github.workspace }}/scripts" + CHANNEL: main + run: scripts/.github/workflows/setup-flatcar-sdk.sh + - name: Apply patch for main + id: apply-patch-main + env: + GHA_SCRIPTS_DIR: "${{ github.workspace }}/scripts" + WORK_SCRIPTS_DIR: "${{ github.workspace }}/scripts" + VERSIONS_NEW: ${{ steps.go-latest-release.outputs.VERSIONS_NEW }} + PACKAGES_CONTAINER: ${{ steps.setup-flatcar-sdk.outputs.PACKAGES_CONTAINER }} + SDK_NAME: ${{ steps.setup-flatcar-sdk.outputs.SDK_NAME }} + run: scripts/.github/workflows/go-apply-patch.sh + - name: Create pull request for main + uses: peter-evans/create-pull-request@v5 + if: steps.apply-patch-main.outputs.UPDATE_NEEDED == 1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + path: scripts + branch: ${{ steps.apply-patch-main.outputs.BRANCH_NAME }} + base: main + title: Upgrade Go from ${{ steps.apply-patch-main.outputs.VERSIONS_OLD }} to ${{ steps.apply-patch-main.outputs.VERSIONS_NEW }} + body: Subject says it all. + labels: main