Simplify Helm versioning to always use Chart.yaml version
Some checks failed
Helm Chart Build and Release / lint-only (push) Has been skipped
Helm Chart Build and Release / build-and-release-helm (push) Failing after 11s
Build and Deploy / build-web (push) Successful in 37s
Build and Deploy / build-api (push) Successful in 36s

- 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:
d.viti
2025-10-03 02:37:50 +02:00
parent a379b26808
commit 20c9d2eaf4

View File

@@ -4,13 +4,13 @@ on:
push: push:
branches: [main] branches: [main]
tags: tags:
- 'v*.*.*' # Trigger on version tags like v1.0.0 - 'v*.*.*' # Trigger release if tag matches Chart.yaml version
pull_request: pull_request:
branches: [main] branches: [main]
workflow_dispatch: workflow_dispatch:
inputs: inputs:
version: version:
description: 'Chart version to release (e.g., 1.0.1)' description: 'Expected Chart.yaml version (for validation only)'
required: false required: false
type: string type: string
@@ -30,29 +30,37 @@ jobs:
with: with:
version: "latest" version: "latest"
- name: Determine version and release type - name: Determine version
id: version id: version
run: | 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" IS_RELEASE="false"
if [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ -n "${{ github.event.inputs.version }}" ]; then # Check if this is a tag push that matches the chart version
# Manual release with specified version if [[ "${{ github.ref }}" == refs/tags/v* ]]; then
VERSION="${{ github.event.inputs.version }}" TAG_VERSION=${GITEA_REF_NAME#v}
IS_RELEASE="true" if [ "$TAG_VERSION" = "$VERSION" ]; then
echo "📌 Manual release version: ${VERSION}" IS_RELEASE="true"
elif [[ "${{ github.ref }}" == refs/tags/v* ]]; then echo "📌 Release version (tag matches Chart.yaml): ${VERSION}"
# Tag-based release else
VERSION=${GITEA_REF_NAME#v} echo "⚠️ Warning: Tag version ($TAG_VERSION) doesn't match Chart.yaml version ($VERSION)"
IS_RELEASE="true" echo "📌 Using Chart.yaml version: ${VERSION}"
echo "📌 Tag release 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 else
# Regular build from main branch echo "📌 Development build with version: ${VERSION}"
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}"
fi fi
echo "VERSION=${VERSION}" >> $GITHUB_ENV echo "VERSION=${VERSION}" >> $GITHUB_ENV
@@ -69,28 +77,24 @@ jobs:
# Create a temporary copy of the chart for packaging # Create a temporary copy of the chart for packaging
cp -r helm/api7ee-demo-k8s /tmp/api7ee-demo-k8s-chart 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 # 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|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 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 - name: Package Helm chart
run: | 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 # Store chart filename for later use
echo "CHART_FILE=api7ee-demo-k8s-${VERSION}.tgz" >> $GITHUB_ENV echo "CHART_FILE=api7ee-demo-k8s-${VERSION}.tgz" >> $GITHUB_ENV
@@ -206,6 +210,7 @@ jobs:
echo "" echo ""
echo "- **Version:** ${VERSION}" echo "- **Version:** ${VERSION}"
echo "- **Type:** $([ "${IS_RELEASE}" = "true" ] && echo "Release" || echo "Development Build")" echo "- **Type:** $([ "${IS_RELEASE}" = "true" ] && echo "Release" || echo "Development Build")"
echo "- **Source:** Chart.yaml version (not modified)"
echo "- **Chart:** ${CHART_FILE}" echo "- **Chart:** ${CHART_FILE}"
echo "- **Registry:** https://${{ gitea.server_url }}/api/packages/${{ gitea.repository_owner }}/helm" echo "- **Registry:** https://${{ gitea.server_url }}/api/packages/${{ gitea.repository_owner }}/helm"
echo "" echo ""
@@ -213,12 +218,7 @@ jobs:
echo '```bash' echo '```bash'
echo "helm repo add api7ee https://${{ gitea.server_url }}/api/packages/${{ gitea.repository_owner }}/helm" echo "helm repo add api7ee https://${{ gitea.server_url }}/api/packages/${{ gitea.repository_owner }}/helm"
echo "helm repo update" echo "helm repo update"
if [ "${IS_RELEASE}" = "true" ]; then echo "helm install my-api7ee api7ee/api7ee-demo-k8s --version ${VERSION}"
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 '```' echo '```'
lint-only: lint-only: