Simplify Helm versioning to always use Chart.yaml version
Some checks failed
Some checks failed
- Removed automatic version generation from tags or timestamps - Always use version directly from Chart.yaml (single source of truth) - Tag triggers now only determine if it's a release (not version) - Release is triggered when tag matches Chart.yaml version - Manual dispatch version is now for validation only - Removed version modification during packaging - Simplified packaging process to use Chart's own version - Removed --devel flag as all versions are now stable - Better separation: version managed in Chart.yaml, release triggered by tags
This commit is contained in:
@@ -4,13 +4,13 @@ on:
|
||||
push:
|
||||
branches: [main]
|
||||
tags:
|
||||
- 'v*.*.*' # Trigger on version tags like v1.0.0
|
||||
- 'v*.*.*' # Trigger release if tag matches Chart.yaml version
|
||||
pull_request:
|
||||
branches: [main]
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
version:
|
||||
description: 'Chart version to release (e.g., 1.0.1)'
|
||||
description: 'Expected Chart.yaml version (for validation only)'
|
||||
required: false
|
||||
type: string
|
||||
|
||||
@@ -30,29 +30,37 @@ jobs:
|
||||
with:
|
||||
version: "latest"
|
||||
|
||||
- name: Determine version and release type
|
||||
- name: Determine version
|
||||
id: version
|
||||
run: |
|
||||
# Determine if this is a release or regular build
|
||||
# Always get version from Chart.yaml
|
||||
VERSION=$(grep '^version:' helm/api7ee-demo-k8s/Chart.yaml | awk '{print $2}')
|
||||
|
||||
# Determine if this is a release based on triggers
|
||||
IS_RELEASE="false"
|
||||
|
||||
if [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ -n "${{ github.event.inputs.version }}" ]; then
|
||||
# Manual release with specified version
|
||||
VERSION="${{ github.event.inputs.version }}"
|
||||
IS_RELEASE="true"
|
||||
echo "📌 Manual release version: ${VERSION}"
|
||||
elif [[ "${{ github.ref }}" == refs/tags/v* ]]; then
|
||||
# Tag-based release
|
||||
VERSION=${GITEA_REF_NAME#v}
|
||||
IS_RELEASE="true"
|
||||
echo "📌 Tag release version: ${VERSION}"
|
||||
# Check if this is a tag push that matches the chart version
|
||||
if [[ "${{ github.ref }}" == refs/tags/v* ]]; then
|
||||
TAG_VERSION=${GITEA_REF_NAME#v}
|
||||
if [ "$TAG_VERSION" = "$VERSION" ]; then
|
||||
IS_RELEASE="true"
|
||||
echo "📌 Release version (tag matches Chart.yaml): ${VERSION}"
|
||||
else
|
||||
echo "⚠️ Warning: Tag version ($TAG_VERSION) doesn't match Chart.yaml version ($VERSION)"
|
||||
echo "📌 Using Chart.yaml version: ${VERSION}"
|
||||
fi
|
||||
elif [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ -n "${{ github.event.inputs.version }}" ]; then
|
||||
# Manual trigger with version - treat as release if version matches
|
||||
INPUT_VERSION="${{ github.event.inputs.version }}"
|
||||
if [ "$INPUT_VERSION" = "$VERSION" ]; then
|
||||
IS_RELEASE="true"
|
||||
echo "📌 Manual release for version: ${VERSION}"
|
||||
else
|
||||
echo "⚠️ Warning: Input version ($INPUT_VERSION) doesn't match Chart.yaml version ($VERSION)"
|
||||
echo "📌 Using Chart.yaml version: ${VERSION}"
|
||||
fi
|
||||
else
|
||||
# Regular build from main branch
|
||||
VERSION=$(grep '^version:' helm/api7ee-demo-k8s/Chart.yaml | awk '{print $2}')
|
||||
# Append build number or timestamp for dev versions
|
||||
BUILD_SUFFIX="-dev.$(date +%Y%m%d%H%M%S)"
|
||||
VERSION="${VERSION}${BUILD_SUFFIX}"
|
||||
echo "📌 Development version: ${VERSION}"
|
||||
echo "📌 Development build with version: ${VERSION}"
|
||||
fi
|
||||
|
||||
echo "VERSION=${VERSION}" >> $GITHUB_ENV
|
||||
@@ -69,28 +77,24 @@ jobs:
|
||||
# Create a temporary copy of the chart for packaging
|
||||
cp -r helm/api7ee-demo-k8s /tmp/api7ee-demo-k8s-chart
|
||||
|
||||
# Update version in the temporary copy
|
||||
if [ "${IS_RELEASE}" = "true" ]; then
|
||||
# For releases, update Chart.yaml with the release version
|
||||
sed -i "s/^version:.*/version: ${VERSION}/" /tmp/api7ee-demo-k8s-chart/Chart.yaml
|
||||
sed -i "s/^appVersion:.*/appVersion: \"${VERSION}\"/" /tmp/api7ee-demo-k8s-chart/Chart.yaml
|
||||
|
||||
# Update image tags to use the release version
|
||||
sed -i "s|tag: \"main\"|tag: \"v${VERSION}\"|g" /tmp/api7ee-demo-k8s-chart/values.yaml
|
||||
else
|
||||
# For dev builds, just update the version but keep main tag
|
||||
sed -i "s/^version:.*/version: ${VERSION}/" /tmp/api7ee-demo-k8s-chart/Chart.yaml
|
||||
fi
|
||||
|
||||
# Update image registry and repository to match Gitea
|
||||
sed -i "s|registry: gitea.server_url|registry: ${{ gitea.server_url }}|g" /tmp/api7ee-demo-k8s-chart/values.yaml
|
||||
sed -i "s|repository: gitea.repository/|repository: ${{ gitea.repository }}/|g" /tmp/api7ee-demo-k8s-chart/values.yaml
|
||||
|
||||
echo "📝 Chart prepared with version ${VERSION}"
|
||||
# For releases, update image tags to use the version tag
|
||||
if [ "${IS_RELEASE}" = "true" ]; then
|
||||
# Update image tags to use the release version
|
||||
sed -i "s|tag: \"main\"|tag: \"v${VERSION}\"|g" /tmp/api7ee-demo-k8s-chart/values.yaml
|
||||
echo "📝 Chart prepared for release with version ${VERSION}"
|
||||
else
|
||||
# Keep main tag for development builds
|
||||
echo "📝 Chart prepared for development with version ${VERSION}"
|
||||
fi
|
||||
|
||||
- name: Package Helm chart
|
||||
run: |
|
||||
helm package /tmp/api7ee-demo-k8s-chart --version ${VERSION}
|
||||
# Package using the version from Chart.yaml
|
||||
helm package /tmp/api7ee-demo-k8s-chart
|
||||
|
||||
# Store chart filename for later use
|
||||
echo "CHART_FILE=api7ee-demo-k8s-${VERSION}.tgz" >> $GITHUB_ENV
|
||||
@@ -206,6 +210,7 @@ jobs:
|
||||
echo ""
|
||||
echo "- **Version:** ${VERSION}"
|
||||
echo "- **Type:** $([ "${IS_RELEASE}" = "true" ] && echo "Release" || echo "Development Build")"
|
||||
echo "- **Source:** Chart.yaml version (not modified)"
|
||||
echo "- **Chart:** ${CHART_FILE}"
|
||||
echo "- **Registry:** https://${{ gitea.server_url }}/api/packages/${{ gitea.repository_owner }}/helm"
|
||||
echo ""
|
||||
@@ -213,12 +218,7 @@ jobs:
|
||||
echo '```bash'
|
||||
echo "helm repo add api7ee https://${{ gitea.server_url }}/api/packages/${{ gitea.repository_owner }}/helm"
|
||||
echo "helm repo update"
|
||||
if [ "${IS_RELEASE}" = "true" ]; then
|
||||
echo "helm install my-api7ee api7ee/api7ee-demo-k8s --version ${VERSION}"
|
||||
else
|
||||
echo "# For development version:"
|
||||
echo "helm install my-api7ee api7ee/api7ee-demo-k8s --version ${VERSION} --devel"
|
||||
fi
|
||||
echo "helm install my-api7ee api7ee/api7ee-demo-k8s --version ${VERSION}"
|
||||
echo '```'
|
||||
|
||||
lint-only:
|
||||
|
||||
Reference in New Issue
Block a user