FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Merge pull request #4105 from flatcar/chewi/pr · flatcar/scripts@d2c217c · GitHub

Commit d2c217c

Browse files
authored
Merge pull request #4105 from flatcar/chewi/pr
.github: Several CI-related improvements
2 parents 2aa25ba + 58f16f8 commit d2c217c

7 files changed

Lines changed: 90 additions & 95 deletions

File tree

‎.github/workflows/cacerts-apply-patch.sh‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ source "${GHA_SCRIPTS_DIR}/.github/workflows/common.sh"
66

77
prepare_git_repo
88

9-
if ! check_remote_branch "cacerts-${VERSION_NEW}-${TARGET_BRANCH}"; then
10-
echo "remote branch already exists, nothing to do"
11-
exit 0
12-
fi
13-
149
pushd "${SDK_OUTER_OVERLAY}"
1510

1611
# Parse the Manifest file for already present source files and keep the latest version in the current series
@@ -32,7 +27,4 @@ generate_update_changelog 'ca-certificates' "${VERSION_NEW}" "${URL}" 'ca-certif
3227

3328
commit_changes app-misc/ca-certificates "${VERSION_OLD}" "${VERSION_NEW}"
3429

35-
cleanup_repo
36-
37-
echo "VERSION_OLD=${VERSION_OLD}" >>"${GITHUB_OUTPUT}"
38-
echo 'UPDATE_NEEDED=1' >>"${GITHUB_OUTPUT}"
30+
push_changes_with_rebase

‎.github/workflows/cacerts-release.yaml‎

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@ jobs:
1212
fail-fast: false
1313
runs-on: ubuntu-latest
1414
steps:
15-
- name: Check out main scripts branch for GitHub workflow scripts only
15+
- name: Check out scripts at ${{ github.ref }} for GHA scripts only
1616
uses: actions/checkout@v4
1717
with:
1818
token: ${{ secrets.BOT_PR_TOKEN }}
1919
path: gha
20-
ref: main
2120
- name: Figure out branch
2221
id: figure-out-branch
2322
run: gha/.github/workflows/figure-out-branch.sh '${{ matrix.channel }}'
@@ -55,15 +54,3 @@ jobs:
5554
SDK_NAME: ${{ steps.setup-flatcar-sdk.outputs.SDK_NAME }}
5655
TARGET_BRANCH: ${{ steps.figure-out-branch.outputs.BRANCH }}
5756
run: gha/.github/workflows/cacerts-apply-patch.sh
58-
- name: Create pull request
59-
if: (steps.figure-out-branch.outputs.SKIP == 0) && (steps.apply-patch.outputs.UPDATE_NEEDED == 1)
60-
uses: peter-evans/create-pull-request@v6
61-
with:
62-
token: ${{ secrets.BOT_PR_TOKEN }}
63-
path: work
64-
branch: "cacerts-${{ steps.nss-latest-release.outputs.NSS_VERSION }}-${{ steps.figure-out-branch.outputs.BRANCH }}"
65-
base: ${{ steps.figure-out-branch.outputs.BRANCH }}
66-
title: Update ca-certificates in ${{ steps.figure-out-branch.outputs.BRANCH }} from ${{ steps.apply-patch.outputs.VERSION_OLD }} to ${{ steps.nss-latest-release.outputs.NSS_VERSION }}
67-
body: Subject says it all.
68-
labels: ${{ steps.figure-out-branch.outputs.LABEL }}
69-
signoff: true

‎.github/workflows/ci.yaml‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,30 @@ jobs:
279279
path: |
280280
scripts/image-changes-reports*.txt
281281
282+
- name: Post reports to PR
283+
if: github.event.pull_request
284+
uses: actions/github-script@v7
285+
with:
286+
script: |
287+
const fs = require('fs');
288+
const globber = await glob.create('scripts/image-changes-reports*.txt');
289+
let body = `### Image changes reports (${{ matrix.arch }})\n\n`;
290+
for await (const file of globber.globGenerator()) {
291+
const name = require('path').basename(file, '.txt');
292+
const content = fs.readFileSync(file, 'utf8').trim();
293+
if (content) {
294+
body += `<details><summary>${name}</summary>\n\n\`\`\`diff\n${content}\n\`\`\`\n\n</details>\n\n`;
295+
}
296+
}
297+
if (body.includes('<details>')) {
298+
await github.rest.issues.createComment({
299+
owner: context.repo.owner,
300+
repo: context.repo.repo,
301+
issue_number: context.issue.number,
302+
body: body,
303+
});
304+
}
305+
282306
# Clean up what we uploaded already so the "vendor images" wildcard
283307
# works when uploading artifacts in the next step.
284308
- name: Remove update, generic and devcontainer images

‎.github/workflows/common.sh‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,16 @@ function commit_changes() {
191191
popd
192192
}
193193

194+
# Push the changes to the current remote and branch. If this fails, clean up
195+
# (rebase needs this), pull, and rebase before trying again.
196+
function push_changes_with_rebase() {
197+
if ! git -C "${SDK_OUTER_TOPDIR}" push; then
198+
cleanup_repo
199+
git -C "${SDK_OUTER_TOPDIR}" pull --rebase --depth=500
200+
git -C "${SDK_OUTER_TOPDIR}" push
201+
fi
202+
}
203+
194204
# Prints the status of the git repo and cleans it up - reverts
195205
# uncommitted changes, removes untracked files. It's usually called at
196206
# the end of a script making changes to the repository in order to

‎.github/workflows/kernel-release.yaml‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@ jobs:
1212
fail-fast: false
1313
runs-on: ubuntu-latest
1414
steps:
15-
- name: Check out main scripts branch for GitHub workflow scripts only
15+
- name: Check out scripts at ${{ github.ref }} for GHA scripts only
1616
uses: actions/checkout@v4
1717
with:
1818
token: ${{ secrets.BOT_PR_TOKEN }}
1919
path: gha
20-
ref: main
2120
- name: Figure out branch
2221
id: figure-out-branch
2322
run: gha/.github/workflows/figure-out-branch.sh '${{ matrix.channel }}'
@@ -66,5 +65,5 @@ jobs:
6665
base: ${{ steps.figure-out-branch.outputs.BRANCH }}
6766
title: Upgrade Linux Kernel for ${{ steps.figure-out-branch.outputs.BRANCH }} from ${{ steps.apply-patch.outputs.VERSION_OLD }} to ${{ steps.kernel-latest-release.outputs.KERNEL_VERSION }}
6867
body: Subject says it all.
69-
labels: ${{ steps.figure-out-branch.outputs.LABEL }}
68+
labels: ${{ steps.figure-out-branch.outputs.LABEL }},auto-ci
7069
signoff: true
Lines changed: 23 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,52 @@
11
name: Get the latest mantle release for branch
22
on:
33
workflow_dispatch:
4-
push:
5-
branches:
6-
- main
74
schedule:
85
- cron: '0 7 * * 1'
96

107
jobs:
118
get-mantle-release:
129
strategy:
1310
matrix:
14-
branch: [main,alpha,beta,stable,lts,lts-old]
11+
channel: [main,alpha,beta,stable,lts,lts-old]
1512
fail-fast: false
1613
runs-on: ubuntu-latest
1714
steps:
15+
- name: Check out scripts at ${{ github.ref }} for GHA scripts only
16+
uses: actions/checkout@v4
17+
with:
18+
token: ${{ secrets.BOT_PR_TOKEN }}
19+
path: gha
1820
- name: Figure out branch
1921
id: figure-out-branch
20-
run: |
21-
set -euo pipefail # The line with major=$(curl | awk) requires pipefail for error handling
22-
skip=0
23-
branch=''
24-
if [ ${{ matrix.branch }} = "main" ]; then
25-
branch='main'
26-
elif [[ ${{ matrix.branch }} = 'lts-old' ]]; then
27-
curl -fsSLO --retry-delay 1 --retry 60 --retry-connrefused --retry-max-time 60 --connect-timeout 20 'https://lts.release.flatcar-linux.net/lts-info'
28-
if [[ $(grep -e ':supported' lts-info | wc -l) -le 1 ]]; then
29-
# Only one supported LTS, skip this workflow run
30-
# as 'lts' matrix branch will handle updating the only
31-
# supported LTS.
32-
skip=1
33-
else
34-
major=$(grep -e ':supported' lts-info | sort -V | head -n 1 | awk -F: '{print $1}')
35-
branch="flatcar-${major}"
36-
# Drop this corner case when 2605 is not supported.
37-
if [[ ${major} -eq 2605 ]]; then
38-
branch='flatcar-lts-2605'
39-
fi
40-
fi
41-
rm -f lts-info
42-
else
43-
major=$(curl -fsSL --retry-delay 1 --retry 60 --retry-connrefused --retry-max-time 60 --connect-timeout 20 https://${{ matrix.branch }}.release.flatcar-linux.net/amd64-usr/current/version.txt | awk -F= '/FLATCAR_BUILD=/{ print $2 }')
44-
branch="flatcar-${major}"
45-
fi
46-
echo "BRANCH=${branch}" >>"${GITHUB_OUTPUT}"
47-
echo "SKIP=${skip}" >>"${GITHUB_OUTPUT}"
48-
- uses: actions/checkout@v4
49-
if: ${{ steps.figure-out-branch.outputs.SKIP == 0 }}
22+
run: gha/.github/workflows/figure-out-branch.sh '${{ matrix.channel }}'
23+
- name: Check out work scripts branch for updating
24+
if: steps.figure-out-branch.outputs.SKIP == 0
25+
uses: actions/checkout@v4
5026
with:
5127
token: ${{ secrets.BOT_PR_TOKEN }}
28+
path: work
5229
ref: ${{ steps.figure-out-branch.outputs.BRANCH }}
5330
- name: Fetch latest mantle hash
54-
if: ${{ steps.figure-out-branch.outputs.SKIP == 0 }}
31+
if: steps.figure-out-branch.outputs.SKIP == 0
5532
id: fetch-latest-mantle
5633
run: |
5734
set -euo pipefail
5835
commit=$(git ls-remote https://github.com/flatcar/mantle refs/heads/main | cut -f1)
5936
echo "COMMIT=${commit}" >>"${GITHUB_OUTPUT}"
6037
- name: Try to apply patch
61-
if: ${{ steps.figure-out-branch.outputs.SKIP == 0 }}
38+
if: steps.figure-out-branch.outputs.SKIP == 0
39+
env:
40+
WORK_SCRIPTS_DIR: "${{ github.workspace }}/work"
6241
run: |
6342
set -euo pipefail
43+
source gha/.github/workflows/common.sh
6444
set -x
45+
cd "${WORK_SCRIPTS_DIR}"
6546
commit=${{ steps.fetch-latest-mantle.outputs.COMMIT }}
66-
if ! grep -q "ghcr.io/flatcar/mantle:git-${commit}" sdk_container/.repo/manifests/mantle-container; then
67-
echo "ghcr.io/flatcar/mantle:git-${commit}" > sdk_container/.repo/manifests/mantle-container
68-
git add sdk_container/.repo/manifests/mantle-container
69-
fi
70-
- name: Create pull request for branch
71-
if: ${{ steps.figure-out-branch.outputs.SKIP == 0 }}
72-
uses: peter-evans/create-pull-request@v6
73-
with:
74-
token: ${{ secrets.BOT_PR_TOKEN }}
75-
base: ${{ steps.figure-out-branch.outputs.BRANCH }}
76-
branch: mantle-update-${{ steps.figure-out-branch.outputs.BRANCH }}
77-
author: Flatcar Buildbot <buildbot@flatcar-linux.org>
78-
committer: Flatcar Buildbot <buildbot@flatcar-linux.org>
79-
title: Upgrade mantle container image to latest HEAD in ${{ steps.figure-out-branch.outputs.BRANCH }}
80-
commit-message: Update mantle container image to latest HEAD
81-
delete-branch: true
82-
signoff: true
47+
file=sdk_container/.repo/manifests/mantle-container
48+
echo "ghcr.io/flatcar/mantle:git-${commit}" > "${file}"
49+
git status --porcelain "${file}" | grep -q "^ M" || exit 0
50+
prepare_git_repo
51+
git commit --signoff -m "Update mantle container image to latest HEAD" "${file}"
52+
push_changes_with_rebase

‎.github/workflows/pr-workflows.yaml‎

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,40 +10,53 @@ concurrency:
1010
cancel-in-progress: true
1111

1212
jobs:
13-
pre_check:
14-
name: "Check if we need to update the SDK"
13+
approval_gate:
14+
name: "Wait for approval"
1515
runs-on: ubuntu-latest
16-
# Setting the environment is the more important reason we need this job.
17-
# We use this job as a gate, so we can approve the PR workflow only once. If
16+
# Use this job as a gate, so we can approve the PR workflow only once. If
1817
# we set this in the update_sdk job and in the build_image job, we would have
1918
# to approve the workflow for every job that kicks off. Given that the jobs
2019
# are sequenced, this is cumbersome. Use this job as a gate and make the rest
2120
# dependent on it.
22-
environment: development
23-
outputs:
24-
sdk_changes: ${{ steps.step1.outputs.sdk_changes }}
21+
#
22+
# Skip the environment gate for auto-ci PRs from the bot to allow
23+
# automatic triggering without manual approval.
24+
environment: ${{ (github.actor != 'flatcar-infra' || !contains(github.event.pull_request.labels.*.name, 'auto-ci')) && 'development' || null }}
2525
steps:
26-
- name: Set outputs
27-
id: step1
28-
shell: bash
29-
run: |
30-
echo "sdk_changes=${{ contains(github.event.pull_request.body, '/update-sdk') }}" >> $GITHUB_OUTPUT
26+
- run: 'true'
3127

3228
update_sdk:
3329
name: "Build an updated SDK container"
34-
needs: [ pre_check ]
35-
if: needs.pre_check.outputs.sdk_changes == 'true'
30+
needs: [ approval_gate ]
31+
if: "!contains(github.event.pull_request.labels.*.name, 'jenkins-ci') && contains(github.event.pull_request.body, '/update-sdk')"
3632
# SDK build needs access to bincache ssh secret
3733
secrets: inherit
3834
uses: ./.github/workflows/update-sdk.yaml
3935

4036
build_image:
41-
needs: [ update_sdk ]
37+
needs: [ approval_gate, update_sdk ]
4238
# The update-sdk job may be skipped, which is fine. We only care if it tried to
4339
# run, but failed.
44-
if: (always() && !cancelled()) && needs.update_sdk.result != 'failure'
40+
if: "!contains(github.event.pull_request.labels.*.name, 'jenkins-ci') && always() && !cancelled() && needs.approval_gate.result == 'success' && needs.update_sdk.result != 'failure'"
4541
name: "Build the OS image"
4642
uses: ./.github/workflows/ci.yaml
4743
with:
4844
custom_sdk_version: ${{ needs.update_sdk.outputs.sdk_version }}
4945
image_formats: qemu_uefi pxe
46+
47+
jenkins_ci:
48+
name: "Trigger Jenkins CI"
49+
needs: [ approval_gate ]
50+
if: contains(github.event.pull_request.labels.*.name, 'jenkins-ci')
51+
runs-on: ubuntu-latest
52+
steps:
53+
- name: Trigger Jenkins build
54+
run: |
55+
curl -fsSL \
56+
https://jenkins.flatcar.org/buildByToken/buildWithParameters \
57+
--data-urlencode "token=${{ secrets.JENKINS_REMOTE_TRIGGER_TOKEN }}" \
58+
--data-urlencode "job=container/packages_all_arches" \
59+
--data-urlencode "cause=${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" \
60+
--data-urlencode "version=main-9999.0.${{ github.run_number }}-github-${{ github.event.pull_request.number }}" \
61+
--data-urlencode "scripts_ref=${{ github.event.pull_request.head.sha }}" \
62+
--data-urlencode "git_sha=${{ github.event.pull_request.head.sha }}"

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL