From 3f27013b6959f57446a7eae8723c36eb506b8863 Mon Sep 17 00:00:00 2001 From: "buu.nguyen" Date: Thu, 21 Nov 2024 04:59:47 +0700 Subject: [PATCH] Add CI --- ...ction.yaml => docker_action.yaml.disabled} | 0 ...elease.yaml => helm-release.yaml.disabled} | 0 ...nse-eyes.yml => license-eyes.yml.disabled} | 0 .github/workflows/release-charts.yaml | 87 +++++++++++++++++++ 4 files changed, 87 insertions(+) rename .github/workflows/{docker_action.yaml => docker_action.yaml.disabled} (100%) rename .github/workflows/{helm-release.yaml => helm-release.yaml.disabled} (100%) rename .github/workflows/{license-eyes.yml => license-eyes.yml.disabled} (100%) create mode 100644 .github/workflows/release-charts.yaml diff --git a/.github/workflows/docker_action.yaml b/.github/workflows/docker_action.yaml.disabled similarity index 100% rename from .github/workflows/docker_action.yaml rename to .github/workflows/docker_action.yaml.disabled diff --git a/.github/workflows/helm-release.yaml b/.github/workflows/helm-release.yaml.disabled similarity index 100% rename from .github/workflows/helm-release.yaml rename to .github/workflows/helm-release.yaml.disabled diff --git a/.github/workflows/license-eyes.yml b/.github/workflows/license-eyes.yml.disabled similarity index 100% rename from .github/workflows/license-eyes.yml rename to .github/workflows/license-eyes.yml.disabled diff --git a/.github/workflows/release-charts.yaml b/.github/workflows/release-charts.yaml new file mode 100644 index 00000000..ef63b685 --- /dev/null +++ b/.github/workflows/release-charts.yaml @@ -0,0 +1,87 @@ +name: Release Charts + +on: + push: + branches: + - main + tags: + - helm-v* + paths: + - charts/** + - .github/workflows/release-charts.yaml + + workflow_dispatch: + +jobs: + release: + if: startsWith(github.ref, 'refs/tags/helm-v') + runs-on: homelab-runner + env: + CHARTS_DIR: helm-charts + CHARTS_OWNER: thealtoclef + CHARTS_REPO: thealtoclef-charts + CHARTS_PAGES_BRANCH: main + steps: + - name: Get Infisical credentials + run: | + echo "::add-mask::$INFISICAL_CLIENT_ID" + echo "INFISICAL_CLIENT_ID=$INFISICAL_CLIENT_ID" >> $GITHUB_ENV + echo "::add-mask::$INFISICAL_CLIENT_SECRET" + echo "INFISICAL_CLIENT_SECRET=$INFISICAL_CLIENT_SECRET" >> $GITHUB_ENV + + - name: Ingest CI secrets + uses: Infisical/secrets-action@v1.0.7 + with: + client-id: ${{ env.INFISICAL_CLIENT_ID }} + client-secret: ${{ env.INFISICAL_CLIENT_SECRET }} + env-slug: "prod" + project-slug: "homelab-058-n" + secret-path: "/ci" + + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + path: source + + - name: Checkout Helm charts repo + uses: actions/checkout@v4 + with: + path: helm-charts + repository: ${{ env.CHARTS_OWNER }}/${{ env.CHARTS_REPO }} + token: ${{ env.CR_TOKEN }} + + - name: Setup Helm + uses: azure/setup-helm@v4 + + - name: Add dependency chart repos + working-directory: source + run: | + for dir in $(ls -d ${{ env.CHARTS_DIR }}/*/); do + helm dependency list $dir 2> /dev/null | tail +2 | head -n -1 | awk '{ print "helm repo add " $1 " " $3 }' | while read cmd; do $cmd; done + done + + - name: Create tag in Helm charts repo + working-directory: helm-charts + run: | + git tag ${GITHUB_REF#refs/tags/} + git push --tags --porcelain + + - name: Run chart-releaser to create release + uses: thealtoclef/chart-releaser-action@main + env: + CR_TOKEN: ${{ env.CR_TOKEN }} + with: + owner: ${{ env.CHARTS_OWNER }} + repo: ${{ env.CHARTS_REPO }} + pages_branch: ${{ env.CHARTS_PAGES_BRANCH }} + skip_upload: true + workdir: source + charts_dir: ${{ env.CHARTS_DIR }} + + - name: Update index.yaml + working-directory: helm-charts + run: | + git config user.name "${{ github.actor }}" + git config user.email "${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com" + cr index -o ${{ env.CHARTS_OWNER }} -r ${{ env.CHARTS_REPO }} --pages-branch ${{ env.CHARTS_PAGES_BRANCH }} --package-path ../source/.cr-release-packages --index-path . --push