Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: Bump image version in the Harvester repo when tagging #174

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 6 additions & 0 deletions .github/branch-mappings.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# branch mapping from this repo to harvester
Copy link

@innobead innobead Dec 31, 2024

Choose a reason for hiding this comment

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

This is good.

Can we have this for all independently released components?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm struggling with this. To centralize in one place or controlled in each repo.

Choose a reason for hiding this comment

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

Can we add an action in the harvester repo to regularly scan these component repos, check for any new tags or releases, and update the related tags accordingly?

Copy link
Member Author

Choose a reason for hiding this comment

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

The initial idea is repo-based. The intention is just to make the owner's life easier.
I'll close this one and see what I can.

Copy link
Collaborator

Choose a reason for hiding this comment

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

How about the submodule to handle the whole components update?
If we centralize this thing, maybe we could use other ways, not just bash-based GHA.
Could we do it easier?

Copy link
Member Author

Choose a reason for hiding this comment

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

The reason to keep this inside a repo is the workflow can be run after images are successfully published. Or even run after some tests (if there are any) defined by the repo.
Using a separate job to scan all component repos will be more complicated, we'll need to check if CI is running well when the tag was happening.

How about creating an action, and every repo just needs to use the action?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I am ok with that.
Just one thing I would like to confirm again. Suppose we use the centralized GitHub action. That means we need to use the same branch naming, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

no, a branch_mapping mapping file should be kept in the individual repo (just like this PR). I prefer this rather than keeping it in a centralized place. The advantage is the repo owner can know and update the mapping when working on the repo, no need to jump to the centralized repo. The drawback is we don't have a place to know all the mappings for all projects in one place.

mappings:
v0.5.x: v1.2
v0.6.x: v1.3
v0.7.x: v1.4
v0.8.x: v1.5
87 changes: 87 additions & 0 deletions .github/workflows/create-image-bump-pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: Create PR to bump image tags in the Harvester repo

on:
workflow_call:
inputs:
component:
description: 'The component to bump images'
required: true
type: string
version:
description: 'The version of the image to bump'
required: true
type: string
harvester_repo:
description: 'The repository to bump the image in'
default: 'harvester/harvester'
required: false
type: string

jobs:
create:
runs-on: ubuntu-latest
steps:
- name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"
- uses: actions/checkout@v4
with:
path: ${{ github.event.repository.name }}
# checkout the default branch to get the branch mappings, so we don't need to update
# every supported branch.
ref: ${{ github.event.repository.default_branch }}
- name: Get corresponding harvester branch
id: detect
run: |
version="${{ inputs.version }}"
echo "version: $version"

cd ${{ github.event.repository.name }}

# Find the branch name from a tag name in the current repo: v7.7.7 -> v7.7.x
# And find the corresponding branch name in the harvester repo: v7.7.x -> v1.4
repo_branch="$(echo "$version" | sed -E 's/(v[0-9]+\.[0-9]+)\.[0-9]+/\1.x/g')"
echo "repo_branch: $repo_branch"
harvester_branch="$(branch="$repo_branch" yq ".mappings.[env(branch)] // \"\"" .github/branch-mappings.yaml)"
if [ -z "$harvester_branch" ]; then
echo "[ERROR] No corresponding Harvester branch found for version $version, branch $repo_branch"
echo "[ERROR] Check the branch mappings in .github/branch-mappings.yaml"
exit 1
fi

echo "::notice title=Branch Mapping::repo_branch: $repo_branch, harvester_branch=$harvester_branch"
echo "harvester_branch=$harvester_branch" >> "$GITHUB_OUTPUT"

- name: Clone harvester/harvester repo
uses: actions/checkout@v4
with:
repository: ${{ inputs.harvester_repo }}
ref: ${{ steps.detect.outputs.harvester_branch }}
path: harvester
- name: Update image tags in the values file
run: |
set -x

cd harvester
# Search for a component and replace all the "tag: xxx" occurrences in the section
# We first search the component name as the start line
# And find the next component name as the end line
sed -i '/${{ inputs.component }}:/,/^[^ #].*:$/s/tag:\s.*/tag: ${{ inputs.version }}/' deploy/charts/harvester/values.yaml
git --no-pager diff --no-color
- name: Create harvester PR
uses: peter-evans/create-pull-request@v7
with:
path: harvester
token: ${{ secrets.HARVESTER_BOT_TOKEN }}
commit-message: Bump ${{ inputs.component }} to ${{ inputs.version }}
committer: GitHub <[email protected]>
author: Harvester Bot <[email protected]>
signoff: false
branch: bump-${{ inputs.component }}-${{ inputs.version }}
delete-branch: false
title: Bump ${{ inputs.component }} to ${{ inputs.version }}
draft: false
body: |
Bump ${{ inputs.component }} to ${{ inputs.version }}.

10 changes: 9 additions & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,12 @@ jobs:
with:
tag: ${{ github.ref_name }}
push: true
secrets: inherit
secrets: inherit
create-harvester-pr:
needs: build-for-release
uses: ./.github/workflows/create-image-bump-pr.yaml
with:
component: harvester-node-disk-manager
version: ${{ github.ref_name }}
harvester_repo: harvester/harvester
secrets: inherit
Loading