Simplify Helm workflow to build on main branch only
- Removed tag-based triggers and release creation - Renamed workflow from helm-release.yml to helm-build.yml - Simplified to always build and publish on main branch push - Version always comes from Chart.yaml (no modifications) - Removed all release-related logic and conditions - Kept PR linting for validation - Cleaner and simpler workflow focused on continuous delivery - Updated README to reflect the new workflow structure
This commit is contained in:
101
.gitea/workflows/helm-build.yml
Normal file
101
.gitea/workflows/helm-build.yml
Normal file
@@ -0,0 +1,101 @@
|
||||
name: Helm Chart Build
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
pull_request:
|
||||
branches: [main]
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
build-helm:
|
||||
runs-on: ubuntu-latest
|
||||
# Only run on main branch pushes (not on PRs)
|
||||
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0 # Fetch all history for proper versioning
|
||||
|
||||
- name: Install Helm
|
||||
uses: azure/setup-helm@v3
|
||||
with:
|
||||
version: "latest"
|
||||
|
||||
- name: Get chart version
|
||||
run: |
|
||||
# Get version from Chart.yaml
|
||||
VERSION=$(grep '^version:' helm/api7ee-demo-k8s/Chart.yaml | awk '{print $2}')
|
||||
echo "📌 Chart version: ${VERSION}"
|
||||
echo "VERSION=${VERSION}" >> $GITHUB_ENV
|
||||
|
||||
- name: Lint Helm chart
|
||||
run: |
|
||||
helm lint helm/api7ee-demo-k8s/
|
||||
|
||||
- name: Prepare and package Helm chart
|
||||
run: |
|
||||
# Create a temporary copy of the chart for packaging
|
||||
cp -r helm/api7ee-demo-k8s /tmp/api7ee-demo-k8s-chart
|
||||
|
||||
# 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
|
||||
|
||||
# Package the chart
|
||||
helm package /tmp/api7ee-demo-k8s-chart
|
||||
|
||||
# Store chart filename
|
||||
echo "CHART_FILE=api7ee-demo-k8s-${VERSION}.tgz" >> $GITHUB_ENV
|
||||
echo "📦 Packaged chart: api7ee-demo-k8s-${VERSION}.tgz"
|
||||
|
||||
- name: Push Helm chart to Gitea Package Registry
|
||||
run: |
|
||||
# Upload Helm chart to Gitea package registry
|
||||
echo "📤 Uploading chart to Gitea Package Registry..."
|
||||
|
||||
curl --fail-with-body \
|
||||
-H "Authorization: token ${{ secrets.PACKAGES_PUSH_TOKEN }}" \
|
||||
-X POST \
|
||||
-F "chart=@${CHART_FILE}" \
|
||||
https://${{ gitea.server_url }}/api/packages/${{ gitea.repository_owner }}/helm/api/charts
|
||||
|
||||
echo "✅ Helm chart pushed successfully to Gitea Package Registry"
|
||||
echo "📦 Chart: ${CHART_FILE}"
|
||||
echo "🔗 Registry URL: https://${{ gitea.server_url }}/api/packages/${{ gitea.repository_owner }}/helm"
|
||||
|
||||
|
||||
- name: Summary
|
||||
run: |
|
||||
echo "## 📦 Helm Chart Published"
|
||||
echo ""
|
||||
echo "- **Version:** ${VERSION}"
|
||||
echo "- **Chart:** ${CHART_FILE}"
|
||||
echo "- **Registry:** https://${{ gitea.server_url }}/api/packages/${{ gitea.repository_owner }}/helm"
|
||||
echo ""
|
||||
echo "### Installation"
|
||||
echo '```bash'
|
||||
echo "helm repo add api7ee https://${{ gitea.server_url }}/api/packages/${{ gitea.repository_owner }}/helm"
|
||||
echo "helm repo update"
|
||||
echo "helm install my-api7ee api7ee/api7ee-demo-k8s --version ${VERSION}"
|
||||
echo '```'
|
||||
|
||||
lint-only:
|
||||
runs-on: ubuntu-latest
|
||||
# Only run on PRs
|
||||
if: github.event_name == 'pull_request'
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install Helm
|
||||
uses: azure/setup-helm@v3
|
||||
with:
|
||||
version: "latest"
|
||||
|
||||
- name: Lint Helm chart
|
||||
run: |
|
||||
echo "🔍 Linting Helm chart for PR..."
|
||||
helm lint helm/api7ee-demo-k8s/
|
||||
echo "✅ Helm chart linting passed"
|
||||
@@ -1,241 +0,0 @@
|
||||
name: Helm Chart Build and Release
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
tags:
|
||||
- 'v*.*.*' # Trigger release if tag matches Chart.yaml version
|
||||
pull_request:
|
||||
branches: [main]
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
version:
|
||||
description: 'Expected Chart.yaml version (for validation only)'
|
||||
required: false
|
||||
type: string
|
||||
|
||||
jobs:
|
||||
build-and-release-helm:
|
||||
runs-on: ubuntu-latest
|
||||
# Only run on main branch pushes or tags (not on PRs)
|
||||
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0 # Fetch all history for proper versioning
|
||||
|
||||
- name: Install Helm
|
||||
uses: azure/setup-helm@v3
|
||||
with:
|
||||
version: "latest"
|
||||
|
||||
- name: Determine version
|
||||
id: version
|
||||
run: |
|
||||
# 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"
|
||||
|
||||
# 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
|
||||
echo "📌 Development build with version: ${VERSION}"
|
||||
fi
|
||||
|
||||
echo "VERSION=${VERSION}" >> $GITHUB_ENV
|
||||
echo "IS_RELEASE=${IS_RELEASE}" >> $GITHUB_ENV
|
||||
echo "version=${VERSION}" >> $GITHUB_OUTPUT
|
||||
echo "is_release=${IS_RELEASE}" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Lint Helm chart
|
||||
run: |
|
||||
helm lint helm/api7ee-demo-k8s/
|
||||
|
||||
- name: Prepare Helm chart for packaging
|
||||
run: |
|
||||
# Create a temporary copy of the chart for packaging
|
||||
cp -r helm/api7ee-demo-k8s /tmp/api7ee-demo-k8s-chart
|
||||
|
||||
# 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
|
||||
|
||||
# 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: |
|
||||
# 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
|
||||
|
||||
echo "📦 Packaged chart: api7ee-demo-k8s-${VERSION}.tgz"
|
||||
|
||||
- name: Push Helm chart to Gitea Package Registry
|
||||
run: |
|
||||
# Upload Helm chart to Gitea package registry
|
||||
echo "📤 Uploading chart to Gitea Package Registry..."
|
||||
|
||||
curl --fail-with-body \
|
||||
-H "Authorization: token ${{ secrets.PACKAGES_PUSH_TOKEN }}" \
|
||||
-X POST \
|
||||
-F "chart=@${CHART_FILE}" \
|
||||
https://${{ gitea.server_url }}/api/packages/${{ gitea.repository_owner }}/helm/api/charts
|
||||
|
||||
echo "✅ Helm chart pushed successfully to Gitea Package Registry"
|
||||
echo "📦 Chart: ${CHART_FILE}"
|
||||
echo "🔗 Registry URL: https://${{ gitea.server_url }}/api/packages/${{ gitea.repository_owner }}/helm"
|
||||
|
||||
- name: Create Release (for tagged versions only)
|
||||
if: env.IS_RELEASE == 'true'
|
||||
run: |
|
||||
echo "🎉 Creating release for version ${VERSION}"
|
||||
|
||||
# Generate release notes
|
||||
cat > RELEASE_NOTES.md << EOF
|
||||
## Helm Chart Release v${VERSION}
|
||||
|
||||
### Installation
|
||||
|
||||
\`\`\`bash
|
||||
# Add the Helm repository
|
||||
helm repo add api7ee https://${{ gitea.server_url }}/api/packages/${{ gitea.repository_owner }}/helm
|
||||
helm repo update
|
||||
|
||||
# Install the chart
|
||||
helm install my-api7ee api7ee/api7ee-demo-k8s --version ${VERSION}
|
||||
|
||||
# Install with custom values
|
||||
helm install my-api7ee api7ee/api7ee-demo-k8s --version ${VERSION} -f values.yaml
|
||||
\`\`\`
|
||||
|
||||
### Upgrade
|
||||
|
||||
\`\`\`bash
|
||||
helm upgrade my-api7ee api7ee/api7ee-demo-k8s --version ${VERSION}
|
||||
\`\`\`
|
||||
|
||||
### Docker Images
|
||||
|
||||
This chart uses the following Docker images:
|
||||
- Web: \`${{ gitea.server_url }}/${{ gitea.repository }}/web:v${VERSION}\`
|
||||
- API: \`${{ gitea.server_url }}/${{ gitea.repository }}/api:v${VERSION}\`
|
||||
|
||||
### Chart Download
|
||||
|
||||
Direct download: [api7ee-demo-k8s-${VERSION}.tgz](https://${{ gitea.server_url }}/${{ gitea.repository }}/releases/download/v${VERSION}/api7ee-demo-k8s-${VERSION}.tgz)
|
||||
EOF
|
||||
|
||||
# Create release using Gitea API
|
||||
RELEASE_DATA=$(jq -n \
|
||||
--arg tag "v${VERSION}" \
|
||||
--arg name "v${VERSION}" \
|
||||
--arg body "$(cat RELEASE_NOTES.md)" \
|
||||
--arg target "${{ gitea.sha }}" \
|
||||
'{
|
||||
tag_name: $tag,
|
||||
target_commitish: $target,
|
||||
name: $name,
|
||||
body: $body,
|
||||
draft: false,
|
||||
prerelease: false
|
||||
}')
|
||||
|
||||
# Create the release
|
||||
RELEASE_RESPONSE=$(curl -s -X POST \
|
||||
-H "Authorization: token ${{ secrets.PACKAGES_PUSH_TOKEN }}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "${RELEASE_DATA}" \
|
||||
"https://${{ gitea.server_url }}/api/v1/repos/${{ gitea.repository }}/releases")
|
||||
|
||||
# Get release ID
|
||||
RELEASE_ID=$(echo $RELEASE_RESPONSE | jq -r '.id')
|
||||
|
||||
if [ "$RELEASE_ID" != "null" ] && [ -n "$RELEASE_ID" ]; then
|
||||
echo "✅ Release created with ID: $RELEASE_ID"
|
||||
|
||||
# Upload chart file as release asset
|
||||
curl -X POST \
|
||||
-H "Authorization: token ${{ secrets.PACKAGES_PUSH_TOKEN }}" \
|
||||
-H "Content-Type: application/gzip" \
|
||||
--data-binary "@${CHART_FILE}" \
|
||||
"https://${{ gitea.server_url }}/api/v1/repos/${{ gitea.repository }}/releases/${RELEASE_ID}/assets?name=api7ee-demo-k8s-${VERSION}.tgz"
|
||||
|
||||
# Upload release notes as asset
|
||||
curl -X POST \
|
||||
-H "Authorization: token ${{ secrets.PACKAGES_PUSH_TOKEN }}" \
|
||||
-H "Content-Type: text/markdown" \
|
||||
--data-binary "@RELEASE_NOTES.md" \
|
||||
"https://${{ gitea.server_url }}/api/v1/repos/${{ gitea.repository }}/releases/${RELEASE_ID}/assets?name=RELEASE_NOTES.md"
|
||||
|
||||
echo "✅ Release assets uploaded successfully"
|
||||
else
|
||||
echo "⚠️ Failed to create release"
|
||||
echo "Response: $RELEASE_RESPONSE"
|
||||
fi
|
||||
|
||||
- name: Summary
|
||||
run: |
|
||||
echo "## 🎉 Helm Chart Build Summary"
|
||||
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 ""
|
||||
echo "### Installation Commands"
|
||||
echo '```bash'
|
||||
echo "helm repo add api7ee https://${{ gitea.server_url }}/api/packages/${{ gitea.repository_owner }}/helm"
|
||||
echo "helm repo update"
|
||||
echo "helm install my-api7ee api7ee/api7ee-demo-k8s --version ${VERSION}"
|
||||
echo '```'
|
||||
|
||||
lint-only:
|
||||
runs-on: ubuntu-latest
|
||||
# Only run on PRs
|
||||
if: github.event_name == 'pull_request'
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install Helm
|
||||
uses: azure/setup-helm@v3
|
||||
with:
|
||||
version: "latest"
|
||||
|
||||
- name: Lint Helm chart
|
||||
run: |
|
||||
echo "🔍 Linting Helm chart for PR..."
|
||||
helm lint helm/api7ee-demo-k8s/
|
||||
echo "✅ Helm chart linting passed"
|
||||
11
README.md
11
README.md
@@ -97,17 +97,16 @@ The CI/CD workflows automatically:
|
||||
3. Tags images with branch name
|
||||
4. Implements layer caching for faster builds
|
||||
|
||||
**`.gitea/workflows/helm-release.yml`**:
|
||||
**`.gitea/workflows/helm-build.yml`**:
|
||||
1. Packages Helm charts on every main branch push
|
||||
2. Creates development versions for main branch builds
|
||||
3. Creates release versions for tags (v*.*.*)
|
||||
4. Publishes charts to Gitea Helm registry
|
||||
5. Creates GitHub releases for tagged versions
|
||||
2. Uses version from Chart.yaml (single source of truth)
|
||||
3. Publishes charts to Gitea Helm registry
|
||||
4. Validates charts on pull requests (lint only)
|
||||
|
||||
**Triggers:**
|
||||
- Any branch push (Docker images)
|
||||
- Push to main branch (Helm chart)
|
||||
- Version tags (Helm releases)
|
||||
- Pull requests (Helm lint only)
|
||||
- Manual dispatch
|
||||
|
||||
**Registry:** `git.commandware.com/demos/api7-demo`
|
||||
|
||||
Reference in New Issue
Block a user