From a379b268087079738fef4b00e4546239ec6f5510 Mon Sep 17 00:00:00 2001 From: "d.viti" Date: Fri, 3 Oct 2025 02:35:16 +0200 Subject: [PATCH] Consolidate all Helm build and release tasks into single workflow - Removed build-helm job from build.yml (Docker builds only now) - Created comprehensive helm-release.yml that handles: - Development builds on main branch pushes (with dev suffix) - Release builds on version tags (v*.*.*) - Manual releases via workflow_dispatch - PR linting without publishing - Added intelligent version detection: - Development versions get timestamp suffix - Release versions use clean semver - Manual dispatch can specify custom version - Improved release process with proper Gitea API integration - Added conditional release creation only for tagged versions - Updated README to document the new workflow structure - Separated concerns: build.yml for Docker, helm-release.yml for Helm --- .gitea/workflows/build.yml | 64 ---------- .gitea/workflows/helm-release.yml | 205 ++++++++++++++++++++---------- README.md | 14 +- 3 files changed, 150 insertions(+), 133 deletions(-) diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml index 64c3bb3..cb63af4 100644 --- a/.gitea/workflows/build.yml +++ b/.gitea/workflows/build.yml @@ -79,67 +79,3 @@ jobs: labels: ${{ steps.meta-api.outputs.labels }} cache-from: type=registry,ref=${{ vars.PACKAGES_REGISTRY || gitea.server_url }}/${{ gitea.repository }}/api:buildcache cache-to: type=registry,ref=${{ vars.PACKAGES_REGISTRY || gitea.server_url }}/${{ gitea.repository }}/api:buildcache,mode=max - - build-helm: - runs-on: ubuntu-latest - needs: [build-web, build-api] - if: github.event_name == 'push' && github.ref == 'refs/heads/main' - 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: Lint Helm chart - run: | - helm lint helm/api7ee-demo-k8s/ - - - name: Package Helm chart - run: | - # Get version from Chart.yaml - CHART_VERSION=$(grep '^version:' helm/api7ee-demo-k8s/Chart.yaml | awk '{print $2}') - echo "Chart version: ${CHART_VERSION}" - - # 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 in the copy's 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 - - # Package the modified chart - helm package /tmp/api7ee-demo-k8s-chart --version ${CHART_VERSION} - - # Store chart filename for later use - echo "CHART_FILE=api7ee-demo-k8s-${CHART_VERSION}.tgz" >> $GITHUB_ENV - - - name: Push Helm chart to Gitea Package Registry - run: | - # Upload Helm chart to Gitea package registry - # Format: https://{gitea-server}/api/packages/{owner}/helm/api/charts - 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 Helm index - if: success() - run: | - # Create or update the Helm repository index - echo "📝 Helm chart repository information:" - echo "To add this repository:" - echo " helm repo add api7ee https://${{ gitea.server_url }}/api/packages/${{ gitea.repository_owner }}/helm" - echo " helm repo update" - echo "" - echo "To install the chart:" - echo " helm install my-api7ee api7ee/api7ee-demo-k8s" diff --git a/.gitea/workflows/helm-release.yml b/.gitea/workflows/helm-release.yml index 29d4c40..004a360 100644 --- a/.gitea/workflows/helm-release.yml +++ b/.gitea/workflows/helm-release.yml @@ -1,71 +1,127 @@ -name: Helm Chart Release +name: Helm Chart Build and Release on: push: branches: [main] + tags: + - 'v*.*.*' # Trigger on version tags like v1.0.0 pull_request: branches: [main] workflow_dispatch: + inputs: + version: + description: 'Chart version to release (e.g., 1.0.1)' + required: false + type: string jobs: - release-helm: + 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-depth: 0 # Fetch all history for proper versioning - name: Install Helm uses: azure/setup-helm@v3 with: version: "latest" - - name: Determine version + - name: Determine version and release type id: version run: | - if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then + # Determine if this is a release or regular build + 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 }}" - else - # Extract version from tag (remove 'v' prefix) + 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}" + 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}" fi - echo "VERSION=${VERSION}" - # Export for subsequent steps + echo "VERSION=${VERSION}" >> $GITHUB_ENV - echo "📌 Chart version: ${VERSION}" - - - name: Update Chart version - run: | - # Update Chart.yaml with the new version - sed -i "s/^version:.*/version: ${VERSION}/" helm/api7ee-demo-k8s/Chart.yaml - - # Update appVersion to match - sed -i "s/^appVersion:.*/appVersion: \"${VERSION}\"/" helm/api7ee-demo-k8s/Chart.yaml - - # Update image tags in values.yaml to use this version - sed -i "s|tag: \"main\"|tag: \"v${VERSION}\"|g" helm/api7ee-demo-k8s/values.yaml - - # Update registry and repository to Gitea values - sed -i "s|registry: gitea.server_url|registry: ${{ gitea.server_url }}|g" helm/api7ee-demo-k8s/values.yaml - sed -i "s|repository: gitea.repository/|repository: ${{ gitea.repository }}/|g" helm/api7ee-demo-k8s/values.yaml - - echo "📝 Updated Chart.yaml and values.yaml with version ${VERSION}" + 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 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}" + - name: Package Helm chart run: | - helm package helm/api7ee-demo-k8s/ --version ${VERSION} + helm package /tmp/api7ee-demo-k8s-chart --version ${VERSION} + + # Store chart filename for later use echo "CHART_FILE=api7ee-demo-k8s-${VERSION}.tgz" >> $GITHUB_ENV - # Generate chart README with installation instructions - cat > CHART_README.md << EOF - # API7 Enterprise Edition Helm Chart v${VERSION} + echo "📦 Packaged chart: api7ee-demo-k8s-${VERSION}.tgz" - ## Installation + - 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 @@ -79,48 +135,40 @@ jobs: helm install my-api7ee api7ee/api7ee-demo-k8s --version ${VERSION} -f values.yaml \`\`\` - ## Upgrade + ### Upgrade \`\`\`bash helm upgrade my-api7ee api7ee/api7ee-demo-k8s --version ${VERSION} \`\`\` - ## Docker Images + ### 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 - - name: Push Helm chart to Gitea Package Registry - run: | - # Upload versioned Helm chart - 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 v${VERSION} pushed to Gitea Package Registry" - - - name: Create Release - if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') - run: | # Create release using Gitea API - RELEASE_DATA=$(cat <