Skip to content
This repository was archived by the owner on May 30, 2023. It is now read-only.

.github: auto-merge PRs of Kernel and ca-certificates #2534

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions .github/workflows/cacerts-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
steps:
- uses: actions/checkout@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
token: ${{ secrets.AUTOMERGE_TOKEN }}
- name: Figure out branch
id: figure-out-branch
run: .github/workflows/figure-out-branch.sh '${{ matrix.branch }}'
Expand Down Expand Up @@ -42,14 +42,23 @@ jobs:
SDK_NAME: ${{ steps.setup-flatcar-sdk.outputs.SDK_NAME }}
run: .github/workflows/cacerts-apply-patch.sh
- name: Create pull request
id: cpr
if: (steps.figure-out-branch.outputs.SKIP == 0) && (steps.apply-patch.outputs.UPDATE_NEEDED == 1)
uses: peter-evans/create-pull-request@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
token: ${{ secrets.AUTOMERGE_TOKEN }}
base: ${{ steps.figure-out-branch.outputs.BRANCH }}
branch: ${{ steps.apply-patch.outputs.BRANCH_NAME }}
delete-branch: true
author: Flatcar Buildbot <[email protected]>
committer: Flatcar Buildbot <[email protected]>
title: Upgrade ca-certificates in ${{ steps.figure-out-branch.outputs.BRANCH }} from ${{ steps.apply-patch.outputs.VERSION_OLD }} to ${{ steps.fetch-latest-release.outputs.NSS_VERSION }}
body: Subject says it all.
labels: ${{ steps.figure-out-branch.outputs.LABEL }}
- name: Enable Pull Request Automerge
if: steps.cpr.outputs.pull-request-operation == 'created'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need a way to stop the auto merging because it could lead to breaking all builds all the time. For that I think it would be good enough to have a delay of ~30 minutes before the auto merge, and then a check whether a 'on-hold' label is present on the PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could require the PRs to pass a GH actions CI build / test; automation for scripts should be ready in a few days, and we could add automation for coreos-overlay right after that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need a way to stop the auto merging because it could lead to breaking all builds all the time. For that I think it would be good enough to have a delay of ~30 minutes before the auto merge, and then a check whether a 'on-hold' label is present on the PR.

Exactly, that's what I would like to achieve. For example, create 2 different workflows, merge-autolabel-kernel, which reacts on PR events to actually merge the PR, and autolabel-kernel which periodically gives a label 'automerge` to every open PR, daily ~4pm. In theory that sounds like a good idea. In practice, however it was not so trivial for the latter workflow to get actually a PR number, after create-pull-request all finished. That's where I gave up. Let me do other experiments about that.

uses: peter-evans/enable-pull-request-automerge@v2
with:
token: ${{ secrets.AUTOMERGE_TOKEN }}
pull-request-number: ${{ steps.cpr.outputs.pull-request-number }}
merge-method: merge
15 changes: 15 additions & 0 deletions .github/workflows/ci-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: ci-check

on:
pull_request:
workflow_dispatch:

jobs:
ci-check:
name: ci-check
runs-on: ubuntu-latest
steps:
- name: ci-check
shell: bash
working-directory: ${{ github.workspace }}
run: /bin/true
37 changes: 37 additions & 0 deletions .github/workflows/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,40 @@ function apply_patches() {
git am "${SDK_OUTER_SRCDIR}"/third_party/coreos-overlay/0*.patch
rm -f "${SDK_OUTER_SRCDIR}"/third_party/coreos-overlay/0*.patch
}

# Return 0 (i.e. true) if VER1 >= VER2
function semver_is_bigger() {
local VER1="${1}"
local VER2="${2}"

if [[ "${VER1}" = "$(echo -e "${VER1}\n${VER2}" | sort -V | tail -n1)" ]]; then
return 0
fi

return 1
}

# Determine if the given version is a correct version for the next Kernel for the Stable channel.
# Returns 0 (i.e. true) if Stable kernel version <= the given version <= Beta kernel version.
function is_next_stable_kernel() {
local INPUT_VERSION="${1}"
local URL_STABLE_PACKAGES="https://stable.release.flatcar-linux.net/amd64-usr/current/flatcar_production_image_packages.txt"
local URL_BETA_PACKAGES="https://beta.release.flatcar-linux.net/amd64-usr/current/flatcar_production_image_packages.txt"

curl -fsSL -o /tmp/stable-packages.txt ${URL_STABLE_PACKAGES}
curl -fsSL -o /tmp/beta-packages.txt ${URL_BETA_PACKAGES}

# parse a line like sys-kernel/coreos-kernel-5.15.98::coreos
local STABLE_KV=$(sed -n "s/^sys-kernel\/coreos-kernel-\([0-9]*\.[0-9]*\.[0-9]*\)::.*/\1/p" /tmp/stable-packages.txt)
local BETA_KV=$(sed -n "s/^sys-kernel\/coreos-kernel-\([0-9]*\.[0-9]*\.[0-9]*\)::.*/\1/p" /tmp/beta-packages.txt)

if semver_is_bigger "${INPUT_VERSION}" "${STABLE_KV}"; then
if semver_is_bigger "${BETA_KV}" "${INPUT_VERSION}"; then
return 0
fi
fi

rm -f /tmp/stable-packages.txt /tmp/beta-packages.txt

return 1
}
6 changes: 6 additions & 0 deletions .github/workflows/kernel-apply-patch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ generate_patches sys-kernel coreos-sources Kernel

apply_patches

AUTOMERGEABLE=1
if [[ "${CHANNEL}" = "stable" ]] && ! is_next_stable_kernel ${VERSION_NEW}; then
AUTOMERGEABLE=0
fi

echo "VERSION_OLD=${VERSION_OLD}" >>"${GITHUB_OUTPUT}"
echo "UPDATE_NEEDED=1" >>"${GITHUB_OUTPUT}"
echo "AUTOMERGEABLE=${AUTOMERGEABLE}" >>"${GITHUB_OUTPUT}"
echo "BRANCH_NAME=${BRANCH_NAME}" >>"${GITHUB_OUTPUT}"
16 changes: 13 additions & 3 deletions .github/workflows/kernel-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
steps:
- uses: actions/checkout@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
token: ${{ secrets.AUTOMERGE_TOKEN }}
- name: Figure out branch
id: figure-out-branch
run: .github/workflows/figure-out-branch.sh '${{ matrix.branch }}'
Expand Down Expand Up @@ -42,20 +42,30 @@ jobs:
env:
TARGET: ${{ steps.figure-out-branch.outputs.BRANCH }}
BASE_BRANCH: ${{ steps.figure-out-branch.outputs.BRANCH }}
CHANNEL: ${{ matrix.branch }}
PATH: ${{ steps.setup-flatcar-sdk.outputs.path }}
VERSION_NEW: ${{ steps.fetch-latest-release.outputs.KERNEL_VERSION }}
PACKAGES_CONTAINER: ${{ steps.setup-flatcar-sdk.outputs.PACKAGES_CONTAINER }}
SDK_NAME: ${{ steps.setup-flatcar-sdk.outputs.SDK_NAME }}
run: .github/workflows/kernel-apply-patch.sh
- name: Create pull request
if: (steps.figure-out-branch.outputs.SKIP == 0) && (steps.apply-patch.outputs.UPDATE_NEEDED == 1)
id: cpr
if: (steps.figure-out-branch.outputs.SKIP == 0) && (steps.apply-patch.outputs.UPDATE_NEEDED == 1) && (steps.apply-patch.outputs.AUTOMERGEABLE == 1)
uses: peter-evans/create-pull-request@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
token: ${{ secrets.AUTOMERGE_TOKEN }}
base: ${{ steps.figure-out-branch.outputs.BRANCH }}
branch: ${{ steps.apply-patch.outputs.BRANCH_NAME }}
delete-branch: true
author: Flatcar Buildbot <[email protected]>
committer: Flatcar Buildbot <[email protected]>
title: Upgrade Linux Kernel for ${{ steps.figure-out-branch.outputs.BRANCH }} from ${{ steps.apply-patch.outputs.VERSION_OLD }} to ${{ steps.fetch-latest-release.outputs.KERNEL_VERSION }}
body: Subject says it all.
labels: ${{ steps.figure-out-branch.outputs.LABEL }}
- name: Enable Pull Request Automerge
if: steps.cpr.outputs.pull-request-operation == 'created'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, we need a way to stop this from happening if we can't update for whatever reason

uses: peter-evans/enable-pull-request-automerge@v2
with:
token: ${{ secrets.AUTOMERGE_TOKEN }}
pull-request-number: ${{ steps.cpr.outputs.pull-request-number }}
merge-method: merge