Files
api7-demo/.gitea/workflows/helm-release.yml
d.viti e9528217f8
Some checks failed
Helm Chart Release / release-helm (push) Failing after 29s
Build and Deploy / build-web (push) Successful in 38s
Build and Deploy / build-api (push) Successful in 48s
Build and Deploy / build-helm (push) Failing after 7s
Refactor Helm workflows to trigger on main branch and streamline versioning process
2025-10-03 02:09:06 +02:00

168 lines
6.4 KiB
YAML

name: Helm Chart Release
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
jobs:
release-helm:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install Helm
uses: azure/setup-helm@v3
with:
version: "latest"
- name: Determine version
id: version
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
VERSION="${{ github.event.inputs.version }}"
else
# Extract version from tag (remove 'v' prefix)
VERSION=${GITEA_REF_NAME#v}
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/Chart.yaml
# Update appVersion to match
sed -i "s/^appVersion:.*/appVersion: \"${VERSION}\"/" helm/api7ee/Chart.yaml
# Update image tags in values.yaml to use this version
sed -i "s|tag: \"main\"|tag: \"v${VERSION}\"|g" helm/api7ee/values.yaml
# Update registry to Gitea URL
sed -i "s|registry: gitea.server_url|registry: ${{ gitea.server_url }}|g" helm/api7ee/values.yaml
echo "📝 Updated Chart.yaml and values.yaml with version ${VERSION}"
- name: Lint Helm chart
run: |
helm lint helm/api7ee/
- name: Package Helm chart
run: |
helm package helm/api7ee/ --version ${VERSION}
echo "CHART_FILE=api7ee-${VERSION}.tgz" >> $GITHUB_ENV
# Generate chart README with installation instructions
cat > CHART_README.md << EOF
# API7 Enterprise Edition Helm Chart 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 --version ${VERSION}
# Install with custom values
helm install my-api7ee api7ee/api7ee --version ${VERSION} -f values.yaml
\`\`\`
## Upgrade
\`\`\`bash
helm upgrade my-api7ee api7ee/api7ee --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}\`
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 <<EOF
{
"tag_name": "v${VERSION}",
"target_commitish": "${{ gitea.sha }}",
"name": "v${VERSION}",
"body": "## Helm Chart Release v${VERSION}\n\n### Installation\n\`\`\`bash\nhelm repo add api7ee https://${{ gitea.server_url }}/api/packages/${{ gitea.repository_owner }}/helm\nhelm repo update\nhelm install my-api7ee api7ee/api7ee --version ${VERSION}\n\`\`\`\n\n### Docker Images\n- Web: \`${{ gitea.server_url }}/${{ gitea.repository }}/web:v${VERSION}\`\n- API: \`${{ gitea.server_url }}/${{ gitea.repository }}/api:v${VERSION}\`\n\n### Chart Package\n- Download: [api7ee-${VERSION}.tgz](https://${{ gitea.server_url }}/${{ gitea.repository }}/releases/download/v${VERSION}/api7ee-${VERSION}.tgz)",
"draft": false,
"prerelease": false
}
EOF
)
# Create the release
RELEASE_RESPONSE=$(curl -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-${VERSION}.tgz"
# Upload README as release asset
curl -X POST \
-H "Authorization: token ${{ secrets.PACKAGES_PUSH_TOKEN }}" \
-H "Content-Type: text/markdown" \
--data-binary "@CHART_README.md" \
"https://${{ gitea.server_url }}/api/v1/repos/${{ gitea.repository }}/releases/${RELEASE_ID}/assets?name=CHART_README.md"
echo "✅ Release assets uploaded successfully"
else
echo "⚠️ Failed to create release"
echo "Response: $RELEASE_RESPONSE"
fi
- name: Summary
run: |
echo "## 🎉 Helm Chart Release Summary"
echo ""
echo "- **Version:** v${VERSION}"
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 --version ${VERSION}"
echo '```'