Skip to content

Commit 0a85f80

Browse files
authored
Merge pull request kcl-lang#1 from kcl-lang/refactor-kpm-form
refactor: use kpm to package and run.
2 parents 4b9bdba + 677ba21 commit 0a85f80

File tree

631 files changed

+785
-37989
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

631 files changed

+785
-37989
lines changed

.devcontainer.json

Lines changed: 0 additions & 47 deletions
This file was deleted.

.github/workflows/main.yml

Lines changed: 15 additions & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -1,169 +1,26 @@
1+
name: test
12
on:
23
pull_request:
34
branches:
4-
- main
5+
- main
56
push:
67
branches:
7-
- main
8-
8+
- main
99
jobs:
10-
diff:
11-
runs-on: ubuntu-latest
12-
steps:
13-
- uses: actions/checkout@v2
14-
with:
15-
fetch-depth: 0
16-
- id: diff
17-
uses: technote-space/get-diff-action@v6
18-
outputs:
19-
CHANGED_FILE: ${{ steps.diff.outputs.diff }}
20-
deps:
21-
needs: diff
10+
test:
2211
runs-on: ubuntu-latest
23-
container:
24-
image: kusionstack/kusion:latest
25-
env:
26-
changePaths: ${{needs.diff.outputs.CHANGED_FILE}}
2712
steps:
28-
- uses: actions/checkout@v2
29-
with:
30-
fetch-depth: 0
31-
- id: deps
32-
shell: bash
33-
run: |
34-
echo "changed paths from git diff action: ${changePaths}"
35-
echo "remove single quotes from changed paths"
36-
changePaths=${changePaths//\'/}
37-
echo "removed paths: ${changePaths}"
13+
- uses: actions/checkout@v3
14+
- name: kcl Installation
15+
run: wget -q https://kcl-lang.io/script/install.sh -O - | /bin/bash
3816

39-
affected_stacks=""
40-
affected_projs=""
41-
deps_stack_exit_code=0
42-
deps_proj_exit_code=0
43-
44-
# 1. check if the changed paths empty
45-
if [ -z "${changePaths}" ]; then
46-
# got empty change paths:
47-
echo "got empty changed paths, not deps will be tested"
48-
else
49-
# 2. parse and get affected stacks and projects
50-
51-
# 2.1 convert change paths to --focus option
52-
change_paths_array=$(echo "$changePaths" | tr '\n' ' ')
53-
focus_files=$(printf -- "--focus %s " $change_paths_array)
54-
55-
# 2.2 execute deps command
56-
57-
# affected stacks
58-
deps_cmd_stack="kusion deps --direct down --only stack $focus_files"
59-
echo "get affected stacks: running cmd: $deps_cmd_stack"
60-
affected_stacks=$($deps_cmd_stack)
61-
deps_stack_exit_code=$?
62-
63-
# affected projects
64-
deps_cmd_proj="kusion deps --direct down $focus_files"
65-
echo "get affected projects: running cmd: $deps_cmd_proj"
66-
affected_projs=$($deps_cmd_proj)
67-
deps_proj_exit_code=$?
68-
fi
17+
- uses: actions/setup-go@v1
18+
with:
19+
go-version: "1.19"
6920

70-
# 3. set output
71-
echo "affected stacks: $affected_stacks"
72-
echo "affected projects: $affected_projs"
73-
# escape the newline symbol in the results:
74-
affected_stacks="${affected_stacks//$'\n'/'%0A'}"
75-
affected_projs="${affected_projs//$'\n'/'%0A'}"
76-
echo "::set-output name=affected_stacks::$affected_stacks"
77-
echo "::set-output name=affected_projs::$affected_projs"
21+
- name: kpm Installation
22+
run: go install kcl-lang.io/kpm@latest
7823

79-
# 4. If deps cli failed, exit with the actual exit code
80-
[ $deps_stack_exit_code -eq 0 ] && echo "deps command --only stack was successful" || exit "deps command --only stack failed"
81-
[ $deps_proj_exit_code -eq 0 ] && echo "deps command --only project was successful" || exit "deps command --only project failed"
82-
- name: get output result
83-
run: |
84-
echo "affected stacks: ${{ steps.deps.outputs.affected_stacks }}"
85-
echo "affected projects: ${{ steps.deps.outputs.affected_projs }}"
86-
outputs:
87-
affected_stacks: ${{ steps.deps.outputs.affected_stacks }}
88-
affected_projs: ${{ steps.deps.outputs.affected_projs }}
89-
lint:
90-
needs: deps
91-
runs-on: ubuntu-latest
92-
container:
93-
image: kusionstack/kusion:latest
94-
env:
95-
CHANGED_FILE: ${{needs.diff.outputs.CHANGED_FILE}}
96-
AFFECTED_STACKS: ${{needs.deps.outputs.affected_stacks}}
97-
AFFECTED_PROJECTS: ${{needs.deps.outputs.affected_projs}}
98-
steps:
99-
- uses: actions/checkout@v2
100-
- uses: actions/setup-python@v4
101-
with:
102-
python-version: '3.9'
103-
- id: install-pytest-html
104-
run: |
105-
python3 -m pip install pytest-html pytest-xdist ruamel.yaml -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
106-
# 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
107-
apt -y install wget
108-
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 ./
109-
- id: lint-check
110-
run: |
111-
export PATH=$PATH:$(pwd)/kclvm/bin
112-
python3 -m pytest -v -n 5 hack/lint_check.py --junitxml ./hack/report/lint.xml --html=./hack/report/lint.html
113-
- id: upload-lint-report
114-
if: always()
115-
uses: actions/upload-artifact@v2
116-
with:
117-
name: lint-report
118-
path: |
119-
hack/report/lint.xml
120-
hack/report/lint.html
121-
structure-check:
122-
needs: deps
123-
runs-on: ubuntu-latest
124-
container:
125-
image: kusionstack/kusion:latest
126-
env:
127-
CHANGED_FILE: ${{needs.diff.outputs.CHANGED_FILE}}
128-
AFFECTED_STACKS: ${{needs.deps.outputs.affected_stacks}}
129-
AFFECTED_PROJECTS: ${{needs.deps.outputs.affected_projs}}
130-
steps:
131-
- uses: actions/checkout@v2
132-
- id: install-pytest-html
133-
run: python3 -m pip install pytest-html pyyaml -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
134-
- id: structure-check
135-
run: python3 -m pytest -v hack/verify-project-structure.py --junitxml ./hack/report/structure-check.xml --html=./hack/report/structure-check.html
136-
- id: upload-structure-check-report
137-
if: always()
138-
uses: actions/upload-artifact@v2
139-
with:
140-
name: structure-check-report
141-
path: |
142-
hack/report/structure-check.xml
143-
hack/report/structure-check.html
144-
test:
145-
needs: deps
146-
runs-on: ubuntu-latest
147-
container:
148-
image: kusionstack/kusion:latest
149-
env:
150-
CHANGED_FILE: ${{needs.diff.outputs.CHANGED_FILE}}
151-
AFFECTED_STACKS: ${{needs.deps.outputs.affected_stacks}}
152-
AFFECTED_PROJECTS: ${{needs.deps.outputs.affected_projs}}
153-
steps:
154-
- uses: actions/checkout@v2
155-
- uses: actions/setup-python@v4
156-
with:
157-
python-version: '3.9'
158-
- id: test
159-
run: |
160-
python3 -m pip install pytest-html pytest-xdist ruamel.yaml -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
161-
python3 -m pytest -v hack/test_konfig.py --junitxml ./hack/report/test.xml --html=./hack/report/test.html
162-
- id: upload-test-report
163-
if: always()
164-
uses: actions/upload-artifact@v2
165-
with:
166-
name: test-report
167-
path: |
168-
hack/report/test.xml
169-
hack/report/test.html
24+
- name: Example tests
25+
shell: bash -ieo pipefail {0}
26+
run: PATH=$PATH:$HOME/go/bin ./scripts/test.sh

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ report/
2020

2121
kusion_state.json
2222

23-
changed_list.txt
23+
changed_list.txt

Makefile

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,2 @@
1-
PWD=$(shell pwd)
2-
PROJECT_NAME=Konfig
3-
KCL_IMAGE=kcllang/kcl
4-
5-
parallel-compile=python3 hack/compile-rocket.py
6-
7-
help: ## 这里是帮助文档 :)
8-
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' Makefile | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
9-
10-
docker-sh: ## 在 kusion docker 容器中执行 shell
11-
docker run --rm -v $(PWD):/${PROJECT_NAME} -w /${PROJECT_NAME} -it -u root ${KCL_IMAGE}
12-
13-
check-all: ## 校验所有 Project
14-
@${parallel-compile} all
15-
16-
check-%: ## 检验指定目录下的 Project
17-
@${parallel-compile} $*
18-
19-
# Build and run tests.
20-
#
21-
# Args:
22-
# WHAT: Project directory names to test.
23-
#
24-
# Example:
25-
# make check WHAT=cafeextcontroller
26-
# make check WHAT="cafeextcontroller infraform"
27-
# make check WHAT=samples
28-
check: ## 校验指定目录下的 Project,比如 make check WHAT=nginx-example 或者 make check WHAT="http-echo nginx-example"
29-
@${parallel-compile} $(WHAT)
30-
31-
clean-all: ## 清理缓存
32-
@echo "cleaning kcl cache..."
33-
@rm -rf ./.kclvm
34-
@echo "cleaning test cache..."
35-
@find . -name .pytest_cache | xargs rm -rf
36-
@echo "clean finished."
37-
38-
install-hooks: ## 安装 git hooks,目前主要有 pre-commit hook(提交时自动编译)
39-
@rm -rf .git/hooks/pre-commit
40-
@cd .git/hooks && ln -s ../../hooks/pre-commit pre-commit
41-
@echo 'Successfully install pre-commit hooks!'
42-
43-
uninstall-hooks: ## 卸载 git hooks
44-
@rm -rf .git/hooks/pre-commit
45-
@echo 'Successfully uninstall pre-commit hooks!'
1+
test:
2+
./scripts/test.sh

README-zh.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ Konfig 是 KCL 配置中基础设施配置的单一存储库。Konfig 提供给
3737
└── kcl.mod # 大库配置文件,通常用来标识大库根目录位置以及大库所需依赖
3838
```
3939

40+
## 前置条件
41+
42+
安装 [kpm](https://kcl-lang.io/docs/user_docs/guides/package-management/installation)
43+
4044
## 快速开始
4145

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

0 commit comments

Comments
 (0)