Skip to content

feat: add k8s deps

feat: add k8s deps #1

Workflow file for this run

on:
pull_request:
branches:
- main
push:
branches:
- main
jobs:
diff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- id: diff
uses: technote-space/get-diff-action@v6
outputs:
CHANGED_FILE: ${{ steps.diff.outputs.diff }}
deps:
needs: diff
runs-on: ubuntu-latest
container:
image: kusionstack/kusion:latest
env:
changePaths: ${{needs.diff.outputs.CHANGED_FILE}}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- id: deps
shell: bash
run: |
echo "changed paths from git diff action: ${changePaths}"
echo "remove single quotes from changed paths"
changePaths=${changePaths//\'/}
echo "removed paths: ${changePaths}"
affected_stacks=""
affected_projs=""
deps_stack_exit_code=0
deps_proj_exit_code=0
# 1. check if the changed paths empty
if [ -z "${changePaths}" ]; then
# got empty change paths:
echo "got empty changed paths, not deps will be tested"
else
# 2. parse and get affected stacks and projects
# 2.1 convert change paths to --focus option
change_paths_array=$(echo "$changePaths" | tr '\n' ' ')
focus_files=$(printf -- "--focus %s " $change_paths_array)
# 2.2 execute deps command
# affected stacks
deps_cmd_stack="kusion deps --direct down --only stack $focus_files"
echo "get affected stacks: running cmd: $deps_cmd_stack"
affected_stacks=$($deps_cmd_stack)
deps_stack_exit_code=$?
# affected projects
deps_cmd_proj="kusion deps --direct down $focus_files"
echo "get affected projects: running cmd: $deps_cmd_proj"
affected_projs=$($deps_cmd_proj)
deps_proj_exit_code=$?
fi
# 3. set output
echo "affected stacks: $affected_stacks"
echo "affected projects: $affected_projs"
# escape the newline symbol in the results:
affected_stacks="${affected_stacks//$'\n'/'%0A'}"
affected_projs="${affected_projs//$'\n'/'%0A'}"
echo "::set-output name=affected_stacks::$affected_stacks"
echo "::set-output name=affected_projs::$affected_projs"
# 4. If deps cli failed, exit with the actual exit code
[ $deps_stack_exit_code -eq 0 ] && echo "deps command --only stack was successful" || exit "deps command --only stack failed"
[ $deps_proj_exit_code -eq 0 ] && echo "deps command --only project was successful" || exit "deps command --only project failed"
- name: get output result
run: |
echo "affected stacks: ${{ steps.deps.outputs.affected_stacks }}"
echo "affected projects: ${{ steps.deps.outputs.affected_projs }}"
outputs:
affected_stacks: ${{ steps.deps.outputs.affected_stacks }}
affected_projs: ${{ steps.deps.outputs.affected_projs }}
lint:
needs: deps
runs-on: ubuntu-latest
container:
image: kusionstack/kusion:latest
env:
CHANGED_FILE: ${{needs.diff.outputs.CHANGED_FILE}}
AFFECTED_STACKS: ${{needs.deps.outputs.affected_stacks}}
AFFECTED_PROJECTS: ${{needs.deps.outputs.affected_projs}}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v4
with:
python-version: '3.9'
- id: install-pytest-html
run: |
python3 -m pip install pytest-html pytest-xdist ruamel.yaml -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
# todo: the following script is to workaround "missing kclvm_cli" error, after the problem solved in the kclvm v0.4.6, this can be removed
apt -y install wget
wget -c https://github.com/KusionStack/KCLVM/releases/download/v0.4.6.2/kclvm-v0.4.6.2-linux-amd64.tar.gz -qO - | tar xz -C ./
- id: lint-check
run: |
export PATH=$PATH:$(pwd)/kclvm/bin
python3 -m pytest -v -n 5 hack/lint_check.py --junitxml ./hack/report/lint.xml --html=./hack/report/lint.html
- id: upload-lint-report
if: always()
uses: actions/upload-artifact@v2
with:
name: lint-report
path: |
hack/report/lint.xml
hack/report/lint.html
structure-check:
needs: deps
runs-on: ubuntu-latest
container:
image: kusionstack/kusion:latest
env:
CHANGED_FILE: ${{needs.diff.outputs.CHANGED_FILE}}
AFFECTED_STACKS: ${{needs.deps.outputs.affected_stacks}}
AFFECTED_PROJECTS: ${{needs.deps.outputs.affected_projs}}
steps:
- uses: actions/checkout@v2
- id: install-pytest-html
run: python3 -m pip install pytest-html pyyaml -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
- id: structure-check
run: python3 -m pytest -v hack/verify-project-structure.py --junitxml ./hack/report/structure-check.xml --html=./hack/report/structure-check.html
- id: upload-structure-check-report
if: always()
uses: actions/upload-artifact@v2
with:
name: structure-check-report
path: |
hack/report/structure-check.xml
hack/report/structure-check.html
test:
needs: deps
runs-on: ubuntu-latest
container:
image: kusionstack/kusion:latest
env:
CHANGED_FILE: ${{needs.diff.outputs.CHANGED_FILE}}
AFFECTED_STACKS: ${{needs.deps.outputs.affected_stacks}}
AFFECTED_PROJECTS: ${{needs.deps.outputs.affected_projs}}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v4
with:
python-version: '3.9'
- id: test
run: |
python3 -m pip install pytest-html pytest-xdist ruamel.yaml -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
python3 -m pytest -v hack/test_konfig.py --junitxml ./hack/report/test.xml --html=./hack/report/test.html
- id: upload-test-report
if: always()
uses: actions/upload-artifact@v2
with:
name: test-report
path: |
hack/report/test.xml
hack/report/test.html