From 813139432b93b29bcbc91a5511ce707f22758a93 Mon Sep 17 00:00:00 2001 From: Ultradesu Date: Wed, 4 Feb 2026 14:45:39 +0200 Subject: [PATCH] Added CI --- .github/workflows/publish-charts.yml | 212 ++++++++++----------------- 1 file changed, 80 insertions(+), 132 deletions(-) diff --git a/.github/workflows/publish-charts.yml b/.github/workflows/publish-charts.yml index 5c20e91..c6197a2 100644 --- a/.github/workflows/publish-charts.yml +++ b/.github/workflows/publish-charts.yml @@ -11,152 +11,100 @@ env: GITEA_OWNER: ab jobs: - detect-charts: + build-and-publish: runs-on: ubuntu-latest - outputs: - charts: ${{ steps.list_charts.outputs.charts }} steps: - name: Checkout uses: actions/checkout@v4 with: fetch-depth: 0 - - name: Detect charts - id: list_charts + - name: Set up Helm + uses: azure/setup-helm@v4 + with: + version: v3.14.0 + + - name: Find and process charts + env: + GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} run: | - CHARTS=() + echo "๐Ÿ” Searching for Helm charts..." + CHARTS_FOUND=0 # Find all directories with Chart.yaml in root for dir in */; do if [ -f "${dir}Chart.yaml" ]; then - CHARTS+=("${dir%/}") + CHART_NAME="${dir%/}" + echo "๐Ÿ“ฆ Found chart: $CHART_NAME" + + # Lint chart + echo "๐Ÿ”ง Linting chart: $CHART_NAME" + helm lint "$CHART_NAME/" + + # Template test + echo "๐Ÿงช Template testing chart: $CHART_NAME" + helm template test "$CHART_NAME/" --debug > /dev/null + + # Get chart info + VERSION=$(helm show chart "$CHART_NAME/" | grep '^version:' | awk '{print $2}') + NAME=$(helm show chart "$CHART_NAME/" | grep '^name:' | awk '{print $2}') + echo "Chart: $NAME, Version: $VERSION" + + # Only publish on main/master branch + if [[ "$GITHUB_REF" == "refs/heads/main" || "$GITHUB_REF" == "refs/heads/master" ]]; then + echo "๐Ÿ“ค Publishing chart: $CHART_NAME" + + # Create packages directory + mkdir -p packages + + # Package chart + helm package "$CHART_NAME/" --destination ./packages/ + + CHART_FILE="packages/$NAME-$VERSION.tgz" + + # Publish to Gitea Registry + if [ -n "$GITEA_TOKEN" ]; then + echo "Publishing $CHART_FILE to registry..." + + HTTP_CODE=$(curl -w "%{http_code}" -s -o /dev/null \ + -H "Authorization: token $GITEA_TOKEN" \ + -X POST \ + --upload-file "$CHART_FILE" \ + "$GITEA_URL/api/packages/$GITEA_OWNER/helm/api/charts") + + if [[ "$HTTP_CODE" =~ ^2[0-9][0-9]$ ]]; then + echo "โœ… Chart $CHART_NAME published successfully! (HTTP $HTTP_CODE)" + + # Verify publication + echo "๐Ÿ” Verifying publication..." + sleep 5 + + if curl -s -H "Authorization: token $GITEA_TOKEN" \ + "$GITEA_URL/api/packages/$GITEA_OWNER/helm/index.yaml" \ + | grep -q "$NAME-$VERSION"; then + echo "โœ… Chart $CHART_NAME verified in registry!" + else + echo "โš ๏ธ Chart $CHART_NAME not found in registry index yet (may take time to index)" + fi + else + echo "โŒ Failed to publish chart $CHART_NAME. HTTP status: $HTTP_CODE" + exit 1 + fi + else + echo "โš ๏ธ GITEA_TOKEN not set, skipping publication" + fi + else + echo "โ„น๏ธ Skipping publication (not on main/master branch)" + fi + + CHARTS_FOUND=$((CHARTS_FOUND + 1)) fi done - echo "Found charts: ${CHARTS[*]}" - - # Convert to JSON array manually for compatibility - if [ ${#CHARTS[@]} -eq 0 ]; then - echo "charts=[]" >> $GITHUB_OUTPUT - else - CHARTS_JSON="[" - for i in "${!CHARTS[@]}"; do - if [ $i -gt 0 ]; then - CHARTS_JSON="${CHARTS_JSON}," - fi - CHARTS_JSON="${CHARTS_JSON}\"${CHARTS[$i]}\"" - done - CHARTS_JSON="${CHARTS_JSON}]" - echo "charts=${CHARTS_JSON}" >> $GITHUB_OUTPUT - fi - - lint-test: - needs: detect-charts - runs-on: ubuntu-latest - if: needs.detect-charts.outputs.charts != '[]' && needs.detect-charts.outputs.charts != '' - strategy: - matrix: - chart: ${{ fromJSON(needs.detect-charts.outputs.charts) }} - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Set up Helm - uses: azure/setup-helm@v4 - with: - version: v3.14.0 - - - name: Lint chart - ${{ matrix.chart }} - run: | - echo "Linting chart: ${{ matrix.chart }}" - helm lint ${{ matrix.chart }}/ - - - name: Template test - ${{ matrix.chart }} - run: | - echo "Template testing chart: ${{ matrix.chart }}" - helm template test ${{ matrix.chart }}/ --debug - - publish: - needs: [detect-charts, lint-test] - runs-on: ubuntu-latest - if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' - strategy: - matrix: - chart: ${{ fromJSON(needs.detect-charts.outputs.charts) }} - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Set up Helm - uses: azure/setup-helm@v4 - with: - version: v3.14.0 - - - name: Get chart info - ${{ matrix.chart }} - id: chart_info - run: | - VERSION=$(helm show chart ${{ matrix.chart }}/ | grep '^version:' | awk '{print $2}') - NAME=$(helm show chart ${{ matrix.chart }}/ | grep '^name:' | awk '{print $2}') - echo "version=$VERSION" >> $GITHUB_OUTPUT - echo "name=$NAME" >> $GITHUB_OUTPUT - echo "Chart: $NAME, Version: $VERSION" - - - name: Create packages directory - run: mkdir -p packages - - - name: Package chart - ${{ matrix.chart }} - run: | - echo "Packaging chart: ${{ matrix.chart }}" - helm package ${{ matrix.chart }}/ --destination ./packages/ - - - name: Publish to Gitea Registry - ${{ matrix.chart }} - env: - GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} - run: | - CHART_FILE="packages/${{ steps.chart_info.outputs.name }}-${{ steps.chart_info.outputs.version }}.tgz" - - echo "Publishing chart: $CHART_FILE" - - response=$(curl -w "%{http_code}" -s -H "Authorization: token $GITEA_TOKEN" \ - -X POST \ - --upload-file "$CHART_FILE" \ - "$GITEA_URL/api/packages/$GITEA_OWNER/helm/api/charts") - - if [[ "$response" =~ ^2[0-9][0-9]$ ]]; then - echo "โœ… Chart ${{ matrix.chart }} published successfully!" - else - echo "โŒ Failed to publish chart ${{ matrix.chart }}. HTTP status: $response" + if [ $CHARTS_FOUND -eq 0 ]; then + echo "โŒ No Helm charts found in repository root" exit 1 - fi - - - name: Verify publication - ${{ matrix.chart }} - env: - GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} - run: | - echo "Checking if chart ${{ matrix.chart }} is available in registry..." - - # Wait for indexing - sleep 10 - - if curl -s -H "Authorization: token $GITEA_TOKEN" \ - "$GITEA_URL/api/packages/$GITEA_OWNER/helm/index.yaml" \ - | grep -q "${{ steps.chart_info.outputs.name }}-${{ steps.chart_info.outputs.version }}"; then - echo "โœ… Chart ${{ matrix.chart }} verified in registry!" else - echo "โš ๏ธ Chart ${{ matrix.chart }} not found in registry index yet" - fi - - summary: - needs: [detect-charts, publish] - runs-on: ubuntu-latest - if: always() && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master') - steps: - - name: Summary - run: | - echo "๐Ÿ“ฆ Helm Charts Publication Summary" - echo "Charts processed: ${{ join(fromJSON(needs.detect-charts.outputs.charts), ', ') }}" - echo "Registry: $GITEA_URL/packages/$GITEA_OWNER" \ No newline at end of file + echo "๐Ÿ“Š Summary: Processed $CHARTS_FOUND chart(s)" + echo "๐ŸŒ Registry: $GITEA_URL/packages/$GITEA_OWNER" + fi \ No newline at end of file