From 2c5381ccc1b544b02fdc3daf7f6cd4fd705f0562 Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Thu, 6 Apr 2023 14:48:50 +0200 Subject: [PATCH] .github: Port containerd update action from old coreos-overlay --- .github/workflows/containerd-apply-patch.sh | 45 +++++++++++++++++ .../workflows/containerd-release-main.yaml | 49 +++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100755 .github/workflows/containerd-apply-patch.sh create mode 100644 .github/workflows/containerd-release-main.yaml diff --git a/.github/workflows/containerd-apply-patch.sh b/.github/workflows/containerd-apply-patch.sh new file mode 100755 index 0000000000..f7e8f07f52 --- /dev/null +++ b/.github/workflows/containerd-apply-patch.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +set -euo pipefail + +source "${GHA_SCRIPTS_DIR}/.github/workflows/common.sh" + +prepare_git_repo + +pushd "${SDK_OUTER_OVERLAY}" + +VERSION_OLD=$(sed -n "s/^DIST containerd-\([0-9]*\.[0-9]*\.[0-9]*\).*/\1/p" app-emulation/containerd/Manifest | sort -ruV | head -n1) +if [[ "${VERSION_NEW}" = "${VERSION_OLD}" ]]; then + echo "already the latest Containerd, nothing to do" + exit 0 +fi + +# we need to update not only the main ebuild file, but also its CONTAINERD_COMMIT, +# which needs to point to COMMIT_HASH that matches with $VERSION_NEW from upstream containerd. +containerdEbuildOldSymlink=$(get_ebuild_filename app-emulation/containerd "${VERSION_OLD}") +containerdEbuildNewSymlink="app-emulation/containerd/containerd-${VERSION_NEW}.ebuild" +containerdEbuildMain="app-emulation/containerd/containerd-9999.ebuild" +git mv "${containerdEbuildOldSymlink}" "${containerdEbuildNewSymlink}" +sed -i "s/CONTAINERD_COMMIT=\"\(.*\)\"/CONTAINERD_COMMIT=\"${COMMIT_HASH}\"/g" "${containerdEbuildMain}" +sed -i "s/v${VERSION_OLD}/v${VERSION_NEW}/g" "${containerdEbuildMain}" + + +DOCKER_VERSION=$(sed -n "s/^DIST docker-\([0-9]*\.[0-9]*\.[0-9]*\).*/\1/p" app-emulation/docker/Manifest | sort -ruV | head -n1) +# torcx ebuild file has a docker version with only major and minor versions, like 19.03. +versionTorcx=${DOCKER_VERSION%.*} +torcxEbuildFile=$(get_ebuild_filename app-torcx/docker "${versionTorcx}") +sed -i "s/containerd-${VERSION_OLD}/containerd-${VERSION_NEW}/g" "${torcxEbuildFile}" + +popd + +URL="https://github.com/containerd/containerd/releases/tag/v${VERSION_NEW}" + +generate_update_changelog 'containerd' "${VERSION_NEW}" "${URL}" 'containerd' + +commit_changes app-emulation/containerd "${VERSION_OLD}" "${VERSION_NEW}" \ + app-torcx/docker + +cleanup_repo + +echo "VERSION_OLD=${VERSION_OLD}" >>"${GITHUB_OUTPUT}" +echo 'UPDATE_NEEDED=1' >>"${GITHUB_OUTPUT}" diff --git a/.github/workflows/containerd-release-main.yaml b/.github/workflows/containerd-release-main.yaml new file mode 100644 index 0000000000..34677ba60c --- /dev/null +++ b/.github/workflows/containerd-release-main.yaml @@ -0,0 +1,49 @@ +name: Get the latest Containerd release for main +on: + schedule: + - cron: '00 8 * * 5' + workflow_dispatch: + +jobs: + get-containerd-release: + runs-on: ubuntu-latest + steps: + - name: Check out scripts + uses: actions/checkout@v3 + with: + token: ${{ secrets.GITHUB_TOKEN }} + path: scripts + - name: Figure out latest Containerd release version + id: containerd-latest-release + run: | + versionCommitPair=( $(git ls-remote --tags https://github.com/containerd/containerd | grep 'refs/tags/v[0-9]*\.[0-9]*\.[0-9]*$' | sed -e 's#^\([0-9a-fA-F]*\)[[:space:]]*refs/tags/v\(.*\)$#\2 \1#g' | sort --reverse --unique --version-sort | head --lines 1) ) + + echo "VERSION_NEW=${versionCommitPair[0]}" >>"${GITHUB_OUTPUT}" + echo "COMMIT_HASH=${versionCommitPair[1]}" >>"${GITHUB_OUTPUT}" + - 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" + VERSION_NEW: ${{ steps.containerd-latest-release.outputs.VERSION_NEW }} + COMMIT_HASH: ${{ steps.containerd-latest-release.outputs.COMMIT_HASH }} + PACKAGES_CONTAINER: ${{ steps.setup-flatcar-sdk.outputs.PACKAGES_CONTAINER }} + SDK_NAME: ${{ steps.setup-flatcar-sdk.outputs.SDK_NAME }} + run: scripts/.github/workflows/containerd-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: "containerd-${{ steps.containerd-latest-release.outputs.VERSION_NEW }}-main" + base: main + title: Upgrade Containerd in main from ${{ steps.apply-patch-main.outputs.VERSION_OLD }} to ${{ steps.containerd-latest-release.outputs.VERSION_NEW }} + body: Subject says it all. + labels: main