ci: better structure (#13)

* struct ci; staged

* seems good

* ci try macos

* debug

* debug

* debug

* debug

* debug

* debug

* debug

* debug

* debug

* debug
This commit is contained in:
Dict Xiong 2022-08-28 20:51:44 +08:00 committed by GitHub
parent fa737d482f
commit 18dfca5f39
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 74 additions and 40 deletions

View File

@ -3,15 +3,14 @@ on:
push: ~ push: ~
workflow_dispatch: ~ workflow_dispatch: ~
jobs: jobs:
test: test-ubuntu:
name: test name: test on ubuntu
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: install dependencies - name: install dependencies
run: | run: |
sudo apt update sudo apt update
sudo apt install -y git python3 python3-pip zsh curl inetutils-ping sudo apt install -y git python3 python3-pip zsh curl inetutils-ping
sudo apt remove -y vim tmux
sudo pip3 install requests sudo pip3 install requests
- name: checkout repo - name: checkout repo
@ -21,45 +20,47 @@ jobs:
run: | run: |
rev=`git rev-parse HEAD` rev=`git rev-parse HEAD`
pwd pwd
export DFS_NO_COMPILE=1 DFS_NO_UPDATE=1
./install.sh ./install.sh
git checkout $rev test `git rev-parse HEAD` = "$rev"
- name: antigen build - name: antigen build
shell: /bin/zsh -ileo PIPE_FAIL {0} shell: /bin/zsh -ileo PIPE_FAIL {0}
run: | run: |
echo $SHELL echo $SHELL
antigen list antigen list
- name: check files
shell: /bin/zsh -ileo PIPE_FAIL {0}
run: |
l ~
l ~/.ssh
cat ~/.zshrc
- name: check scripts and alias - name: run tests
shell: /bin/zsh -ileo PIPE_FAIL {0} shell: /bin/zsh -ileo PIPE_FAIL {0}
run: source tools/test.zsh
test-macos:
name: test on macos
runs-on: macos-12
steps:
- name: install dependencies
run: | run: |
cd / brew update
dfs brew install git python3 zsh curl
dfs cd sudo pip3 install requests
- name: checkout repo
uses: actions/checkout@v3
- name: install dfs
run: |
rev=`git rev-parse HEAD`
pwd pwd
dfs version export DFS_NO_COMPILE=1 DFS_NO_UPDATE=1
dfs log 1 ./install.sh
l test `git rev-parse HEAD` = "$rev"
dogo
tools/common.sh get_os_type
tools/common.sh get_linux_dist
bash -x tools/common.sh post_log 1 2 3
- name: check scripts and alias (no ret check) - name: antigen build
shell: /bin/zsh -il {0}
run: |
p114 -c 4
return 0
- name: check update
shell: /bin/zsh -ileo PIPE_FAIL {0} shell: /bin/zsh -ileo PIPE_FAIL {0}
run: | run: |
dfs update echo $SHELL
dfs version antigen list
- name: run tests
shell: /bin/zsh -ileo PIPE_FAIL {0}
run: source tools/test.zsh

View File

@ -93,7 +93,9 @@ install_tmux_tpm(){
git clone https://gitee.com/dictxiong/tpm "$TMUX_TPM" git clone https://gitee.com/dictxiong/tpm "$TMUX_TPM"
if [[ -x $(command -v g++) && -x $(command -v cmake) && -x $(command -v make) ]]; then if [[ -x $(command -v g++) && -x $(command -v cmake) && -x $(command -v make) ]]; then
fmt_note "initializing tmux plugins ..." fmt_note "initializing tmux plugins ..."
~/.tmux/plugins/tpm/bin/install_plugins if [[ -z "$DFS_NO_COMPILE" ]]; then
~/.tmux/plugins/tpm/bin/install_plugins
fi
else else
fmt_warning "pls install g++,cmake,make and then init tmux plugins by <prefix + I> or ~/.tmux/plugins/tpm/bin/install_plugins" fmt_warning "pls install g++,cmake,make and then init tmux plugins by <prefix + I> or ~/.tmux/plugins/tpm/bin/install_plugins"
fi fi
@ -106,7 +108,9 @@ install_vim_vundle(){
fmt_note "installing vim vundle ..." fmt_note "installing vim vundle ..."
git clone https://gitee.com/dictxiong/Vundle.vim "$VIM_VUNDLE" git clone https://gitee.com/dictxiong/Vundle.vim "$VIM_VUNDLE"
fmt_note "initializing vim plugins ..." fmt_note "initializing vim plugins ..."
vim +PluginInstall +qall if [[ -z "$DFS_NO_COMPILE" ]]; then
vim +PluginInstall +qall
fi
fi fi
} }
@ -114,8 +118,10 @@ install_update(){
fmt_note "installing update.sh ..." fmt_note "installing update.sh ..."
cp "${DOTFILES}/.update.sh" "${DOTFILES}/update.sh" cp "${DOTFILES}/.update.sh" "${DOTFILES}/update.sh"
chmod +x "${DOTFILES}/update.sh" chmod +x "${DOTFILES}/update.sh"
fmt_note "running update.sh ..." if [[ -z "$DFS_NO_UPDATE" ]]; then
${DOTFILES}/update.sh fmt_note "running update.sh ..."
${DOTFILES}/update.sh
fi
} }
uninstall_update(){ uninstall_update(){

View File

@ -7,7 +7,7 @@ logging.basicConfig(level=logging.INFO, format="[%(filename)s:%(lineno)d][%(leve
try: try:
import requests import requests
except ImportError: except ImportError:
logging.fatal("Please install requests module") logging.critical("Please install requests module")
exit(1) exit(1)
@ -57,17 +57,17 @@ if __name__ == "__main__":
content=content.strip() content=content.strip()
if not content: if not content:
logging.error("empty log content") logging.error("empty log content")
exit(1) exit(0)
resp = post_log(url, hostname, uuid, content) resp = post_log(url, hostname, uuid, content)
if resp.status_code == 200: if resp.status_code == 200:
logging.info("200 ok") logging.info("200 ok")
exit(0) exit(0)
elif resp.status_code == 403: elif resp.status_code == 403:
logging.warning("403 forbidden") logging.error("403 forbidden")
logging.info("you may need to register your hostname and uuid") logging.info("you may need to register your hostname and uuid")
logging.info(f"hostname: {hostname}, uuid: {uuid}") logging.info(f"hostname: {hostname}, uuid: {uuid}")
exit(0) exit(0)
else: else:
logging.error("unknown error ") logging.critical("unknown error ")
logging.error(f"{resp.status_code}: {resp.text}") logging.error(f"{resp.status_code}: {resp.text}")
exit(1) exit(1)

27
tools/test.zsh Normal file
View File

@ -0,0 +1,27 @@
#!/bin/false "This script should be sourced in a shell, not executed directly"
set -ex
# check files
cd /
dfs cd
pwd
test -f .zshrc2
diff -q ./.ssh/authorized_keys2 ~/.ssh/authorized_keys2
grep -q ".zshrc2" ~/.zshrc
# check scripts and functions
dfs version
dfs log 1
l
dogo
tools/common.sh get_os_type
tools/common.sh get_linux_dist
# check alias
alias p114 > /dev/null
# check update
dfs update
dfs version
test `git rev-parse HEAD` = `curl -fsSL https://api.beardic.cn/get-var/dfs-commit-id`