-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.sh
executable file
·102 lines (79 loc) · 3.65 KB
/
action.sh
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
#!/bin/bash
sleep 0.1 && echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo "$( basename "$0" )..." && echo
set -ex
########################################################################
#
# Generate dependencies-*.log file(s)
#
########################################################################
ls $REPO_PATH
########################################################################
# env vars
export PACKAGE_NAME=$(python3 $GITHUB_ACTION_PATH/utils/get_package_name.py .)
########################################################################
# grab local copy to avoid path mangling -- replace when https://github.com/WIPACrepo/wipac-dev-py-dependencies-action/issues/6
pip install requests semantic-version
temp_dir=$(mktemp -d) && cd $temp_dir && trap 'rm -rf $temp_dir' EXIT
wget https://raw.githubusercontent.com/WIPACrepo/wipac-dev-tools/main/wipac_dev_tools/semver_parser_tools.py -O $temp_dir/semver_parser_tools_local.py
# get python3 version (max) -- copied from https://github.com/WIPACrepo/wipac-dev-py-versions-action/blob/main/action.yml
export PACKAGE_MAX_PYTHON_VERSION=$(python -c '
import os, re
import semver_parser_tools_local as semver_parser_tools
repo_path = os.environ["REPO_PATH"]
semver_range = ""
if os.path.isfile(f"{repo_path}/pyproject.toml"):
# ex: requires-python = ">=3.8, <3.13"
pat = re.compile(r"requires-python = \"(?P<semver_range>[^\"]+)\"$")
with open(f"{repo_path}/pyproject.toml") as f:
for line in f:
if m := pat.match(line):
semver_range = m.group("semver_range")
if not semver_range:
raise Exception("could not find `requires-python` entry in pyproject.toml")
elif os.path.isfile(f"{repo_path}/setup.cfg"):
# ex: python_requires = >=3.8, <3.13
pat = re.compile(r"python_requires = (?P<semver_range>.+)$")
with open(f"{repo_path}/setup.cfg") as f:
for line in f:
if m := pat.match(line):
semver_range = m.group("semver_range")
if not semver_range:
raise Exception("could not find `python_requires` entry in setup.cfg")
else:
raise Exception("could not find pyproject.toml nor setup.cfg")
top_python = semver_parser_tools.get_latest_py3_release()
all_matches = semver_parser_tools.list_all_majmin_versions(
major=top_python[0],
semver_range=semver_range,
max_minor=top_python[1],
)
print(f"{max(all_matches)[0]}.{max(all_matches)[1]}")
')
echo $PACKAGE_MAX_PYTHON_VERSION
########################################################################
# Dockerfile / docker image logic
# detect if user supplied image(s)
IMAGES_TO_DEP=$( docker images | awk -v pat="$DOCKER_TAG_TO_DEP" '$2==pat' | awk -F ' ' '{print $1":"$2}' )
# compare counts of dockerfiles vs images, yes not perfect (considering build args) but moderately effective
if [ -z "$IMAGES_TO_DEP" ]; then
n_images=0
else
n_images=$( echo "$IMAGES_TO_DEP" | wc -l )
fi
n_dockerfiles=$( find $REPO_PATH -name "Dockerfile*" -printf '.' | wc -m ) # recursive
if (( n_dockerfiles > n_images )); then
echo "ERROR: $n_dockerfiles 'Dockerfile*' file(s) found but $n_images pre-built Docker image(s) with tag='$DOCKER_TAG_TO_DEP' were provided"
exit 1
fi
########################################################################
# generate
if [ ! -z "$IMAGES_TO_DEP" ]; then
# from Dockerfile(s)...
export IMAGES_TO_DEP
$GITHUB_ACTION_PATH/generate_dep_logs/gen-deps-from-user-docker-images.sh
else
# from python package...
$GITHUB_ACTION_PATH/generate_dep_logs/gen-deps-from-repo-python-pkg.sh
fi
sleep 0.1 && echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"