Skip to content

Commit

Permalink
Merge pull request #1 from kcl-lang/refactor-kpm-form
Browse files Browse the repository at this point in the history
refactor: use kpm to package and run.
  • Loading branch information
Peefy authored Oct 8, 2023
2 parents 4b9bdba + 677ba21 commit 0a85f80
Show file tree
Hide file tree
Showing 631 changed files with 785 additions and 37,989 deletions.
47 changes: 0 additions & 47 deletions .devcontainer.json

This file was deleted.

173 changes: 15 additions & 158 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,169 +1,26 @@
name: test
on:
pull_request:
branches:
- main
- main
push:
branches:
- main

- 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
test:
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}"
- uses: actions/checkout@v3
- name: kcl Installation
run: wget -q https://kcl-lang.io/script/install.sh -O - | /bin/bash

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
- uses: actions/setup-go@v1
with:
go-version: "1.19"

# 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"
- name: kpm Installation
run: go install kcl-lang.io/kpm@latest

# 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
- name: Example tests
shell: bash -ieo pipefail {0}
run: PATH=$PATH:$HOME/go/bin ./scripts/test.sh
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ report/

kusion_state.json

changed_list.txt
changed_list.txt
47 changes: 2 additions & 45 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,45 +1,2 @@
PWD=$(shell pwd)
PROJECT_NAME=Konfig
KCL_IMAGE=kcllang/kcl

parallel-compile=python3 hack/compile-rocket.py

help: ## 这里是帮助文档 :)
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' Makefile | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

docker-sh: ## 在 kusion docker 容器中执行 shell
docker run --rm -v $(PWD):/${PROJECT_NAME} -w /${PROJECT_NAME} -it -u root ${KCL_IMAGE}

check-all: ## 校验所有 Project
@${parallel-compile} all

check-%: ## 检验指定目录下的 Project
@${parallel-compile} $*

# Build and run tests.
#
# Args:
# WHAT: Project directory names to test.
#
# Example:
# make check WHAT=cafeextcontroller
# make check WHAT="cafeextcontroller infraform"
# make check WHAT=samples
check: ## 校验指定目录下的 Project,比如 make check WHAT=nginx-example 或者 make check WHAT="http-echo nginx-example"
@${parallel-compile} $(WHAT)

clean-all: ## 清理缓存
@echo "cleaning kcl cache..."
@rm -rf ./.kclvm
@echo "cleaning test cache..."
@find . -name .pytest_cache | xargs rm -rf
@echo "clean finished."

install-hooks: ## 安装 git hooks,目前主要有 pre-commit hook(提交时自动编译)
@rm -rf .git/hooks/pre-commit
@cd .git/hooks && ln -s ../../hooks/pre-commit pre-commit
@echo 'Successfully install pre-commit hooks!'

uninstall-hooks: ## 卸载 git hooks
@rm -rf .git/hooks/pre-commit
@echo 'Successfully uninstall pre-commit hooks!'
test:
./scripts/test.sh
4 changes: 4 additions & 0 deletions README-zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ Konfig 是 KCL 配置中基础设施配置的单一存储库。Konfig 提供给
└── kcl.mod # 大库配置文件,通常用来标识大库根目录位置以及大库所需依赖
```

## 前置条件

安装 [kpm](https://kcl-lang.io/docs/user_docs/guides/package-management/installation)

## 快速开始

参考[这里](https://kcl-lang.io/docs/user_docs/guides/working-with-konfig/guide)
Expand Down
Loading

0 comments on commit 0a85f80

Please sign in to comment.