Skip to content

Commit 4173edd

Browse files
committed
add dev/ with helper scripts
1 parent 70295bc commit 4173edd

File tree

2 files changed

+153
-0
lines changed

2 files changed

+153
-0
lines changed

dev/test.sh

+137
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
#!/bin/bash
2+
#
3+
# Notes:
4+
#
5+
# --workflows required to avoid errors.
6+
# See: https://github.com/nektos/act/issues/1993
7+
#
8+
#
9+
#### SETUP ####################################################################
10+
set -o errtrace
11+
set -o nounset
12+
13+
# https://en.wikipedia.org/wiki/ANSI_escape_code
14+
E0="$(printf "\e[0m")" # reset
15+
E30="$(printf "\033[30m")" # black foreground
16+
E31="$(printf "\e[31m")" # red foreground
17+
E107="$(printf "\033[107m")" # bright white background
18+
19+
20+
error_exit() {
21+
# Echo error message and exit with error
22+
echo -e "${E31}ERROR:${E0} ${*}" 1>&2
23+
exit 1
24+
}
25+
26+
27+
header() {
28+
# Print 80 character wide black on white heading
29+
printf "${E30}${E107} %-71s$(date '+%T') ${E0}\n" "${@}"
30+
}
31+
32+
33+
run_act() {
34+
act --container-architecture linux/amd64 \
35+
--detect-event \
36+
--rm \
37+
--secret ADMIN_ASANA_TOKEN \
38+
--secret ADMIN_GITHUB_TOKEN \
39+
"${@}"
40+
}
41+
42+
43+
header 'Confirm prerequisites'
44+
# macOS
45+
if [[ $(uname -s) != 'Darwin' ]]
46+
then
47+
error_exit 'This script only supports macOS'
48+
else
49+
echo 'Operatings system is macOS'
50+
fi
51+
# act
52+
if ! command -v act >/dev/null
53+
then
54+
error_exit 'act must be installed (`act` not found in PATH)'
55+
else
56+
echo -n 'act is installed: '
57+
act --version
58+
fi
59+
# Docker
60+
if ! command -v docker >/dev/null
61+
then
62+
error_exit 'Docker must be installed (`docker` not found in PATH)'
63+
else
64+
echo -n 'Docker is installed: '
65+
docker --version
66+
fi
67+
# ADMIN_ASANA_TOKEN
68+
if [[ -z "${ADMIN_ASANA_TOKEN:-}" ]]
69+
then
70+
error_exit 'environment variable missing: ADMIN_ASANA_TOKEN'
71+
else
72+
echo 'Environment variable is set: ADMIN_ASANA_TOKEN'
73+
fi
74+
# ADMIN_GITHUB_TOKEN
75+
if [[ -z "${ADMIN_GITHUB_TOKEN:-}" ]]
76+
then
77+
error_exit 'environment variable missing: ADMIN_GITHUB_TOKEN'
78+
else
79+
echo 'Environment variable is set: ADMIN_GITHUB_TOKEN'
80+
fi
81+
echo
82+
83+
84+
header 'Ensuring docker is running'
85+
if [[ -S /var/run/docker.sock ]]
86+
then
87+
echo -n .
88+
for _ in {1..5}
89+
do
90+
echo -n .
91+
sleep 0.2
92+
done
93+
echo
94+
else
95+
open -a Docker
96+
while [[ ! -S /var/run/docker.sock ]]
97+
do
98+
echo -n .
99+
sleep 0.2
100+
done
101+
for _ in {1..40}
102+
do
103+
echo -n .
104+
sleep 0.2
105+
done
106+
echo
107+
fi
108+
echo
109+
110+
111+
header 'List workflows'
112+
run_act --list
113+
echo
114+
115+
116+
header 'Test: Push data to CC Open Source'
117+
run_act --workflows .github/workflows/push_data_to_ccos.yml \
118+
--job push_data
119+
echo
120+
121+
122+
header 'Test: Sync Community Teams with GitHub'
123+
run_act --workflows .github/workflows/sync_community_teams.yml \
124+
--job sync_community_teams
125+
echo
126+
127+
128+
header 'Test: Manage issues and pull requests in projects'
129+
run_act --workflows .github/workflows/manage_issues.yml \
130+
--job manage_issues_and_pull_requests
131+
echo
132+
133+
134+
header 'Test: Normalize Repos'
135+
run_act --workflows .github/workflows/normalize_repos.yml \
136+
--job normalize_repos
137+
echo

dev/tools.sh

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
#### SETUP ####################################################################
3+
set -o errtrace
4+
set -o nounset
5+
6+
printf "\e[1m\e[7m %-80s\e[0m\n" 'isort'
7+
pipenv run isort ${@:-.}
8+
echo
9+
10+
printf "\e[1m\e[7m %-80s\e[0m\n" 'black'
11+
pipenv run black ${@:-.}
12+
echo
13+
14+
printf "\e[1m\e[7m %-80s\e[0m\n" 'flake8'
15+
pipenv run flake8 ${@:-.}
16+
echo

0 commit comments

Comments
 (0)