-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdxos.zsh
executable file
·143 lines (116 loc) · 2.7 KB
/
dxos.zsh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#
# Git
#
alias gs='git-branch-select -l'
alias gb='git branch -vv'
#
# pnpm nx run-many --target=build
# pnpm -w nx build <target> --watch
#
alias pi="pnpm install"
alias pw="pnpm watch"
alias px="pnpm -w nx"
alias nx="pnpm -w nx"
# Run target in local directory (e.g., `p build`).
function p () {
TARGET=$1
shift 1
px $TARGET "${PWD##*/}" "$@"
}
# Build
function pb () {
px build "${PWD##*/}" "$@"
}
# Test
function pt () {
px test "${PWD##*/}" "$@"
}
# Break NX cache (e.g., `pc test`).
function pc () {
TARGET=$1
shift 1
px $TARGET "${PWD##*/}" "$@" "${RANDOM}"
}
# Run everything (e.g., `pa build`).
function pa () {
TARGET=$1
shift 1
ROOT=$(git rev-parse --show-toplevel)
if [ "$ROOT" = "$PWD" ]; then
px run-many --target=$TARGET "$@"
else;
pushd $ROOT
nx run-many --target=$TARGET "$@"
popd
fi;
}
# Build, test and lint everything.
function pre () {
if [ "$1" = "-c" ]; then
git clean -xdf
fi;
# export CI=true
# ROOT=$(git rev-parse --show-toplevel)
px reset
CI=true pi
CI=true pa build
CI=true pa test
CI=true pa lint
}
#
# CI monitoring the PR associated with the current branch.
# Set CIRCLECI_TOKEN
#
# Local development:
# - change .zplug/init.sh
#
# ```bash
# zplug dxos/zsh/dxos.zsh, from:local
# exec zsh
# ```
#
# To remove:
# `rm -rf /opt/homebrew/opt/zplug/repos/dxos`
#
CIRCLECI_ORG="dxos"
CIRCLECI_REPO="dxos"
CLEAR="\033[0J"
function ci () {
function ci_status () {
PROJECT_SLUG="gh/$CIRCLECI_ORG/$CIRCLECI_REPO"
# Get project.
PROJECT_ID=$(curl -s -H "Circle-Token: $CIRCLECI_TOKEN" \
"https://circleci.com/api/v2/project/${PROJECT_SLUG}/pipeline?branch=$(git branch --show-current)" | \
jq -r '.items.[0].id')
echo -e "Pipeline: $PROJECT_ID"
# Get workflow.
URL="https://circleci.com/api/v2/pipeline/${PROJECT_ID}/workflow"
RESPONSE=$(curl -s -H "Circle-Token: $CIRCLECI_TOKEN" $URL)
echo -e "$RESPONSE" | jq
STATUS=$(echo -e "$RESPONSE" | jq -r '.items.[0].status')
if [ "$STATUS" = "failed" ]; then
WORKFLOW_ID=$(echo -e "$RESPONSE" | jq -r '.items.[0].id')
# Get failed job.
JOB_NUMBER=$(curl -s -H "Circle-Token: $CIRCLECI_TOKEN" \
"https://circleci.com/api/v2/workflow/${WORKFLOW_ID}/job" |
jq -r '.items | map(select(.status=="failed")) | .[0].job_number')
URL=$(curl -s -H "Circle-Token: $CIRCLECI_TOKEN" \
"https://circleci.com/api/v2/project/${PROJECT_SLUG}/job/${JOB_NUMBER}" | jq -r ".web_url")
fi
}
while true; do
tput sc
ci_status
tput rc
case "$STATUS" in
"running")
;;
*)
echo "${CLEAR}Result $STATUS"
echo "$URL"
break
;;
esac
sleep 10
done
}