Skip to content

Commit

Permalink
[skip ci] cicd: update lint and test workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
sunggun-yu committed Feb 22, 2025
1 parent 1243414 commit 9c0d9ea
Showing 1 changed file with 45 additions and 13 deletions.
58 changes: 45 additions & 13 deletions .github/workflows/lint-test.yaml → .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }})
Expand All @@ -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' }}
Expand Down

0 comments on commit 9c0d9ea

Please sign in to comment.