From 9c0d9eab894e6102aa95edd57119555106e7bbcd Mon Sep 17 00:00:00 2001 From: Sunggun Yu Date: Sat, 22 Feb 2025 12:42:11 -0500 Subject: [PATCH] [skip ci] cicd: update lint and test workflow --- .../workflows/{lint-test.yaml => test.yaml} | 58 ++++++++++++++----- 1 file changed, 45 insertions(+), 13 deletions(-) rename .github/workflows/{lint-test.yaml => test.yaml} (56%) diff --git a/.github/workflows/lint-test.yaml b/.github/workflows/test.yaml similarity index 56% rename from .github/workflows/lint-test.yaml rename to .github/workflows/test.yaml index 95b7ff0..3baae64 100644 --- a/.github/workflows/lint-test.yaml +++ b/.github/workflows/test.yaml @@ -9,15 +9,48 @@ on: types: - opened - synchronize - workflow_dispatch: + push: + branches: + - main + paths: + - "charts/**" env: # make install test false for now DO_INSTALL_TEST: false jobs: + # The pre-check job determines whether the workflow should proceed based on the event type and associated PRs: + # - true if the commit is not associated with any PR if it is a push event + # - true if the event is a PR event + # so that, we can skip the following job if the commit is associated with a PR when it is merged to main branch + # - to prevent running the job twice + pre-check: + runs-on: ubuntu-latest + outputs: + run_workflow: ${{ steps.check-commit.outputs.result }} + steps: + - uses: actions/github-script@v7 + if: github.event_name == 'push' + id: check-commit + with: + script: | + const associatedPRs = await github.rest.repos.listPullRequestsAssociatedWithCommit({ + owner: context.repo.owner, + repo: context.repo.repo, + commit_sha: context.sha + }); + return associatedPRs.data.length == 0; + result-encoding: string + + # Set default output for PR events + - if: github.event_name == 'pull_request' + id: pr-event + run: echo "result=true" >> $GITHUB_OUTPUT + lint-test: - if: github.head_ref != 'release-please--branches--main' + needs: pre-check + if: needs.pre-check.outputs.run_workflow == 'true' || github.head_ref != 'release-please--branches--main' runs-on: ubuntu-latest steps: - name: Checkout @@ -38,7 +71,11 @@ jobs: - name: Set up chart-testing uses: helm/chart-testing-action@v2 - - name: Run chart-testing (list-changed) + - name: Install Helm Unittest plugin + run: | + helm plugin install https://github.com/helm-unittest/helm-unittest.git + + - name: List changed charts id: list-changed run: | changed=$(ct list-changed --target-branch ${{ github.event.repository.default_branch }}) @@ -47,21 +84,16 @@ jobs: echo "charts=$(echo "$changed" | tr '\n' ' ')" >> "$GITHUB_OUTPUT" fi - - name: Run chart-testing (lint) + - name: Lint charts if: steps.list-changed.outputs.changed == 'true' run: ct lint --config .github/config/chart-testing.yaml - - name: Run chart-testing (template) + - name: Unit testing if: steps.list-changed.outputs.changed == 'true' - id: update-dependencies + id: unittest run: | - for updated_chart in ${{ steps.list-changed.outputs.charts }}; do - echo "================================================================================" - echo " templating $updated_chart" - echo "================================================================================" - helm dependency update $updated_chart - helm template $updated_chart - done + helm dependency update ${{ steps.list-changed.outputs.charts }} + helm unittest ${{ steps.list-changed.outputs.charts }} - name: Create kind cluster if: ${{ steps.list-changed.outputs.changed == 'true' && env.DO_INSTALL_TEST == 'true' }}