From f5d7891effdcfdd3a257fabede3902cbc4c80acd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=E1=B4=87=CA=80=C9=B4=E1=B4=85=20S=E1=B4=84=CA=9C?= =?UTF-8?q?=E1=B4=8F=CA=80=C9=A2=E1=B4=87=CA=80s?= Date: Wed, 27 Jul 2022 11:15:03 +0200 Subject: [PATCH] =?UTF-8?q?ci:=20=F0=9F=A7=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/charts-lint.yaml | 16 ----- .github/workflows/charts-release.yaml | 93 +++++++++++++++++---------- 2 files changed, 59 insertions(+), 50 deletions(-) diff --git a/.github/workflows/charts-lint.yaml b/.github/workflows/charts-lint.yaml index 7a43f67f..633c16b3 100644 --- a/.github/workflows/charts-lint.yaml +++ b/.github/workflows/charts-lint.yaml @@ -6,9 +6,6 @@ on: checkoutCommit: required: true type: string - chartChangesDetected: - required: true - type: string chartChanges: required: true type: string @@ -37,19 +34,6 @@ jobs: - name: Set up chart-testing uses: helm/chart-testing-action@v2.2.1 - # - name: Collect changes - # id: list-changed - # if: inputs.chartChangesDetected == 'true' - # run: | - # EXCLUDED=$(yq eval -o=json '.excluded-charts // []' .ci/ct/ct-lint.yaml) - # CHARTS=$(ct list-changed --config .ci/ct/ct-lint.yaml) - # CHARTS_JSON=$(echo "${CHARTS}" | jq -R -s -c 'split("\n")[:-1]') - # OUTPUT_JSON=$(echo "{\"excluded\": ${EXCLUDED}, \"all\": ${CHARTS_JSON}}" | jq -c '.all-.excluded') - # echo ::set-output name=charts::${OUTPUT_JSON} - # if [[ $(echo ${OUTPUT_JSON} | jq -c '. | length') -gt 0 ]]; then - # echo "::set-output name=detected::true" - # fi - - name: Run chart-testing (lint) id: lint if: inputs.chartChanges != '' diff --git a/.github/workflows/charts-release.yaml b/.github/workflows/charts-release.yaml index 325ade59..aa15240b 100644 --- a/.github/workflows/charts-release.yaml +++ b/.github/workflows/charts-release.yaml @@ -11,8 +11,53 @@ on: - "charts/**" jobs: + collect-changes: + runs-on: ubuntu-22.04 + + outputs: + changesDetected: ${{ steps.filter.outputs.chartsAddedOrModified }} + addedOrModifiedCharts: ${{ steps.filter-charts.outputs.addedOrModifiedCharts }} + + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + token: ${{ steps.get-app-token.outputs.token }} + + - name: Collect changes + uses: dorny/paths-filter@v2 + id: filter + with: + list-files: shell + filters: | + chartsAddedOrModified: + - added|modified: 'charts/*/**' + + - name: Collect changed charts + if: | + steps.filter.outputs.chartsAddedOrModified == 'true' + id: filter-charts + shell: bash + run: | + CHARTS=() + PATHS=(${{ steps.filter.outputs.chartsAddedOrModified_files }}) + # Get only the chart paths + for CHARTPATH in "${PATHS[@]}" + do + IFS='/' read -r -a path_parts <<< "${CHARTPATH}" + CHARTS+=("${path_parts[1]}/${path_parts[2]}") + done + # Remove duplicates + CHARTS=( `printf "%s\n" "${CHARTS[@]}" | sort -u` ) + # Set output to changed charts + printf "::set-output name=addedOrModifiedCharts::%s\n" "${CHARTS[*]}" + release-charts: runs-on: ubuntu-22.04 + needs: + - collect-changes + if: + needs.collect-changes.outputs.changesDetected == 'true' steps: - name: Get k8s-at-home token id: get-app-token @@ -44,9 +89,8 @@ jobs: env: SRC_DIR: "src/charts" DEST_DIR: "dest" + CHARTS: "${{ needs.collect-changes.outputs.addedOrModifiedCharts }}" run: | - CHARTS=$(find "$SRC_DIR" -type f -name 'Chart.yaml' | sed -r 's|/[^/]+$||' | sort | uniq) - for CHART in $CHARTS ; do mapfile -t CHART_PATH_PARTS < <(echo "$CHART" | tr '/' '\n') CHART_TYPE=${CHART_PATH_PARTS[2]} @@ -55,38 +99,19 @@ jobs: helm package "$CHART" -u -d "$DEST_DIR/$CHART_TYPE" done - - name: Login to GitHub Container Registry - uses: docker/login-action@v1 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Push Charts to GHCR + - name: Create new index shell: bash - env: - DEST_DIR: "dest" + working-directory: dest run: | - for pkg in $DEST_DIR/**/*; do - if [ -z "${pkg:-}" ]; then - break - fi - helm push "${pkg}" oci://ghcr.io/${GITHUB_REPOSITORY_OWNER}/helm-charts - done + helm repo index . --url https://bjw-s.github.io/helm-charts/ - # - name: Create new index - # shell: bash - # working-directory: dest - # run: | - # helm repo index . --url https://bjw-s.github.io/helm-charts/ - - # - name: Push changes - # shell: bash - # working-directory: dest - # run: | - # git config user.name "bjw-s-bot[bot]" - # git config user.email "bjw-s-bot <87358111+bjw-s-bot[bot]@users.noreply.github.com>" - # git add $(git ls-files -o --exclude-standard) - # git add index.yaml - # git commit -m "Updated from ref: $GITHUB_SHA" - # git push + - name: Push changes + shell: bash + working-directory: dest + run: | + git config user.name "bjw-s-bot[bot]" + git config user.email "bjw-s-bot <87358111+bjw-s-bot[bot]@users.noreply.github.com>" + git add $(git ls-files -o --exclude-standard) + git add index.yaml + git commit -m "Updated from ref: $GITHUB_SHA" + git push