Skip to content

Commit

Permalink
Merge pull request #412 from intershop/develop/icm
Browse files Browse the repository at this point in the history
Release changes develop/icm
  • Loading branch information
khauser authored Oct 17, 2023
2 parents cbaeb0f + e607de2 commit 933952e
Show file tree
Hide file tree
Showing 29 changed files with 296 additions and 165 deletions.
108 changes: 69 additions & 39 deletions .github/callBump2version.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,51 @@
import sys
import subprocess
from enum import EnumMeta, Enum
from functools import total_ordering

class MyEnumMeta(EnumMeta):

def __contains__(self, other):
try:
self(other)
except ValueError:
return False
else:
return True
def __contains__(self, other):
try:
self(other)
except ValueError:
return False
else:
return True

@total_ordering
class UpgradeType(Enum, metaclass=MyEnumMeta):
NONE = 'none'
PATCH = 'patch'
MINOR = 'minor'
MAJOR = 'major'
PATCH = 'patch'
MINOR = 'minor'
MAJOR = 'major'
def __lt__(self, other):
if self.__class__ is other.__class__:
order = {
UpgradeType.PATCH: 0,
UpgradeType.MINOR: 1,
UpgradeType.MAJOR: 2
}
return order[self] < order[other]
return NotImplemented

class ProductType(Enum, metaclass=MyEnumMeta):
NONE = 'none'
IOM = 'iom'
PWA = 'pwa'
ICM_REPLICATION = 'icm-replication'
ICM = 'icm'
ICM_AS = 'icm-as'
ICM_JOB = 'icm-job'
ICM_WEB = 'icm-web'
PWA = 'pwa'
ICM_REPLICATION = 'icm-replication'
ICM = 'icm'
ICM_AS = 'icm-as'
ICM_JOB = 'icm-job'
ICM_WEB = 'icm-web'

# key is a ProductType
# value is a list of ProductType which depend on the key
dependencies = {
ProductType.PWA: [],
ProductType.ICM_REPLICATION: [],
ProductType.ICM: [ProductType.ICM_REPLICATION],
ProductType.ICM_AS: [ProductType.ICM],
ProductType.ICM_JOB: [ProductType.ICM_AS],
ProductType.ICM_WEB: [ProductType.ICM]
}

def handle_subprocess_error(subprocess_result, error_message):
if subprocess_result.returncode != 0:
Expand All @@ -38,29 +57,40 @@ def handle_subprocess_error(subprocess_result, error_message):
print(str(subprocess_result.stdout, "UTF-8"))
exit(1)

def main(argv):
chart = ProductType.NONE
upgrade = UpgradeType.NONE

for label in argv:
if label in ProductType:
chart = ProductType(label)

for label in argv:
if label in UpgradeType:
upgrade = UpgradeType(label)

if upgrade == UpgradeType.NONE or chart == ProductType.NONE:
print("No need for a version bump detected")
exit(0)

print(f"Bumping version of \'{chart.value}\' to next \'{upgrade.value}\' value.")
bumpver_process = subprocess.run(f"bump2version {upgrade.value}",
def bumpVersion(chart, bump):
print(f"Bumping version of \'{chart.value}\' to next \'{bump.value}\' value.")
bumpver_process = subprocess.run(f"bump2version --allow-dirty {bump.value}",
shell=True,
cwd=f"./charts/{chart.value}",
capture_output=True)
handle_subprocess_error(bumpver_process, "Could not execute version bump.")
handle_subprocess_error(bumpver_process, "Could not execute version bump.")

# recursively adds all dependents of chart to dict, overriding the previous value
# if upgrade is bigger than the existing entry
def addAllDependencies(chart: ProductType, upgrade: UpgradeType, dict: dict):
if chart not in dict or dict[chart] < upgrade:
dict[chart] = upgrade
for dep in dependencies[chart]:
addAllDependencies(dep, upgrade, dict)

# argv must be in the format "chart1:upgrade1 chart2:upgrade2"
# dependent charts are computed and do not have to be specified
# note: this cannot be used for the iom chart since they don't use bump2version
def main(argv):
# parse arguments and figure out dependencies
deps = dict()
for arg in argv:
split_arg = arg.split(":")

if split_arg[0] in ProductType and split_arg[1] in UpgradeType:
product = ProductType(split_arg[0])
upgrade = UpgradeType(split_arg[1])
addAllDependencies(product, upgrade, deps)
else:
raise Exception("Illegal input: " + arg)
# do the actual updates
for chart, upgrade in deps.items():
bumpVersion(chart, upgrade)

if __name__ == "__main__":
main(sys.argv[1:])
main(sys.argv[1:])
18 changes: 18 additions & 0 deletions .github/template/bump-version/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: bump-version
description: Bump chart versions

inputs:
changes:
description: |
A string of charts and their required update, e.g. "icm-as:minor icm-web:patch".
Dependent charts don't have to be specified and will be bumped automatically.
required: true

runs:
using: "composite"
steps:
- name: Bump Version
shell: bash
run: |
pip install --no-cache-dir bump2version
python ./.github/callBump2version.py ${{inputs.changes}}
40 changes: 0 additions & 40 deletions .github/workflows/bump-version.yml

This file was deleted.

49 changes: 49 additions & 0 deletions .github/workflows/main-develop-sync.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: sync develop with main
# creates both a branch and a PR to sync changes from main back to the develop branches
on:
push:
branches:
- main
jobs:
sync:
strategy:
fail-fast: false
matrix:
branch:
- icm
- iom
- pwa
- common
runs-on: ubuntu-latest
permissions:
pull-requests: write
contents: write
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Create integration branch
shell: bash
run: |
INTEGRATE="feature/${{ matrix.branch }}/integrate-main"
# delete previous if exists
git branch --delete $INTEGRATE || true
git branch $INTEGRATE
git checkout $INTEGRATE
# force push to override a previously existing branch, if it exists
git push --force --set-upstream origin $INTEGRATE
- name: Create PR if necessary
shell: bash
run: |
SUBJECT="chore: integrate main to develop/${{ matrix.branch }}"
BODY="Automated Sync PR"
# this may fail if a PR already exists, this is ignored
gh pr create --base "develop/${{ matrix.branch }}" --title "$SUBJECT" --body "$BODY" || true
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Enable PR automerge
shell: bash
run: |
gh pr merge --merge --auto
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
45 changes: 45 additions & 0 deletions .github/workflows/release-branch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Create Release Branch
# creates a release branch, creates a PR and bumps all versions as specified
on:
workflow_dispatch:
inputs:
changes:
description: |
A string of charts and their required update, e.g. "icm-as:minor icm-web:patch".
Dependent charts don't have to be specified and will be bumped automatically.
This action cannot be used for the iom charts, since they don't use bump2version.
required: true
type: string


jobs:
release:
permissions:
pull-requests: write
contents: write
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with: #fetch all commits, not just the last one
fetch-depth: 0
- name: Bump versions
uses: ./.github/template/bump-version
with:
changes: ${{ inputs.changes }}
- name: Create Release Branch & PR
id: pr
uses: peter-evans/create-pull-request@v5
with: # commits all changes and creates the release branch and PR. If one already exists, it is updated.
branch: release/${{ github.ref_name }}
base: main
title: Release ${{ inputs.changes }}
commit-message: "chore: bump versions ${{ inputs.changes }} and dependent charts"
delete-branch: true
labels: automated pr
- name: Enable Pull Request Automerge
shell: bash
run: |
gh pr merge --merge --subject "release: ${{ inputs.changes }}" --auto ${{ steps.pr.outputs.pull-request-number }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
10 changes: 7 additions & 3 deletions .github/workflows/release-charts.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
name: Release Charts

# releases the main branch
# the new versions must already be specified in all Chart.yaml files
# before merging to main
on:
workflow_dispatch:
push:
branches:
- main

jobs:
release:
Expand Down Expand Up @@ -35,7 +39,7 @@ jobs:
helm repo add intershop https://intershop.github.io/helm-charts
- name: Run chart-releaser
uses: helm/chart-releaser-action@v1.4.1
uses: helm/chart-releaser-action@v1.5.0
with:
charts_dir: "charts"
env:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
**/charts/*.tgz
**/requirements.lock
**/Chart.lock
environment/tmp_repo/**
build/**
.idea/
Expand Down
14 changes: 9 additions & 5 deletions charts/icm-as/.bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
[bumpversion]
current_version = 1.3.0
commit = true
tag = false
message = Bump icm-as chart version: {current_version} → {new_version}

# note: the indent after "search" is required to signal bump2version that the pattern continues
[bumpversion:file:Chart.yaml]
search = version: {current_version}
replace = version: {new_version}
search = name: icm-as
version: {current_version}
replace = {new_version}

[bumpversion:file:../icm/Chart.yaml]
search = name: icm-as
version: {current_version}
replace = {new_version}
3 changes: 2 additions & 1 deletion charts/icm-as/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
apiVersion: v2
# name and version must be in this exact order, otherwise bump2version won't work
name: icm-as
version: 1.3.0
description: Intershop Commerce Management - AppServer
type: application
version: 1.3.0
appVersion: 11.2.1
dependencies:
- name: icm-job
Expand Down
7 changes: 5 additions & 2 deletions charts/icm-as/templates/as-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@ metadata:
app: {{ include "icm-as.fullname" .}}
spec:
progressDeadlineSeconds: 600
replicas: {{ .Values.replicaCount }}
replicas: {{ .Values.replicaCount | default 1 }}
revisionHistoryLimit: 10
selector:
matchLabels:
app: icm-as
release: {{ include "icm-as.fullname" . }}
strategy:
type: {{ .Values.updateStrategy }}
type: {{ .Values.updateStrategy | default "RollingUpdate" }}
rollingUpdate:
maxUnavailable: 0
maxSurge: 1
template:
metadata:
{{- if include "icm-as.podData" . }}
Expand Down
4 changes: 4 additions & 0 deletions charts/icm-as/templates/ssl-certificate-spc.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{{- if .Values.sslCertificateRetrieval.enabled }}
{{- if .Values.sslCertificateRetrieval.supportV1 }}
apiVersion: secrets-store.csi.x-k8s.io/v1
{{- else }}
apiVersion: secrets-store.csi.x-k8s.io/v1alpha1
{{- end }}
kind: SecretProviderClass
metadata:
name: {{ include "icm-as.fullname" . }}-cert
Expand Down
4 changes: 3 additions & 1 deletion charts/icm-as/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

# define the number of replicas beeing deployed (int, > 0, default=1)
replicaCount: 1

# define update strategy
# define the update strategy (possible values: Recreate, RollingUpdate; default=RollingUpdate)
updateStrategy: RollingUpdate

# define where the application shall run on
Expand Down Expand Up @@ -335,6 +336,7 @@ webLayer:

sslCertificateRetrieval:
enabled: false
supportV1: false
# secretName: <explicit-ssl-secret-name>
keyvault:
tenantId: <tenant-ID-of-the-KeyVault>
Expand Down
Loading

0 comments on commit 933952e

Please sign in to comment.