-
Notifications
You must be signed in to change notification settings - Fork 1
/
fetch_ci_vars_lists
executable file
·161 lines (140 loc) · 4.71 KB
/
fetch_ci_vars_lists
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/usr/bin/env bash
# SPDX-FileCopyrightText: 2021 Robin Vobruba <[email protected]>
#
# SPDX-License-Identifier: Unlicense
# Exit immediately on each error and unset variable;
# see: https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/
set -Eeuo pipefail
#set -Eeu
script_dir=$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")
function filter_tabular_html() {
VARS_LIST_HTML_FILE="$1"
COL_NUM_VAR_NAME="$2"
COL_NUM_DESC="$3"
cat "$VARS_LIST_HTML_FILE" \
| awk -e '
BEGIN {
in_row = 0
col_num = -99
COL_NUM_VAR_NAME = '"$COL_NUM_VAR_NAME"'
COL_NUM_DESC = '"$COL_NUM_DESC"'
}
/^<tr[^>]*>$/ {
in_row = 1
col_num = 0
}
/^<\/tr>$/ {
in_row = 0
col_num = -99
}
/^<td[^>]*>/ {
if (col_num == COL_NUM_VAR_NAME) {
var_name = $0
gsub("^<td[^>]*>", "", var_name)
gsub("</td>$", "", var_name)
gsub("^<code[^>]*>", "", var_name)
gsub("</code>$", "", var_name)
}
if (col_num == COL_NUM_DESC) {
description = $0
gsub("^<td[^>]*>", "", description)
gsub("</td>$", "", description)
printf("%s=\"%s\"\n" , var_name, description)
}
col_num = col_num + 1
}
' | sort
}
function filter_list_html() {
VARS_LIST_HTML_FILE="$1"
cat "$VARS_LIST_HTML_FILE" \
| awk -e '
BEGIN {
var_name_set = 0
desc_set = 0
}
{
if (var_name_set && !desc_set) {
# We actually want the space inserted between them here!
desc = desc " " $0
if (match($0, "<li>")) {
open_li_s = open_li_s + 1
}
if (match($0, "</li>")) {
open_li_s = open_li_s - 1
}
if (open_li_s == 0) {
desc_set = 1
}
}
if (desc_set) {
printf("%s=\"%s\"\n" , var_name, desc)
var_name_set = 0
desc_set = 0
}
}
/^<li><code class="highlighter-rouge">.*<\/code>:/ {
var_name = $0
gsub("^<li[^>]*>", "", var_name)
gsub("</li>$", "", var_name)
gsub("^<code[^>]*>", "", var_name)
gsub("</code>.*", "", var_name)
var_name_set = 1
if (match($0, "</li>$")) {
desc = $0
gsub(".*</code>: ", "", desc)
gsub("</li>$", "", desc)
desc_set = 1
} else {
desc = ""
open_li_s = 1
}
}
' | sort
}
function cleanup_html_files() {
tidy -wrap 4096 --show-warnings false \
-modify \
"$@" \
2> /dev/null || true
}
VARS_LIST_HTML_GITLAB_URL="https://docs.gitlab.com/ee/ci/variables/predefined_variables.html"
VARS_LIST_HTML_GITHUB_URL="https://docs.github.com/en/actions/reference/environment-variables"
VARS_LIST_HTML_BITBUCKET_URL="https://support.atlassian.com/bitbucket-cloud/docs/variables-and-secrets/"
VARS_LIST_HTML_JENKINS_URL="https://jenkins-x.io/docs/resources/guides/using-jx/pipelines/envvars/"
VARS_LIST_HTML_TRAVISCI_URL="https://docs-staging.travis-ci.com/user/environment-variables/#default-environment-variables"
# NOTE CirceCI does not use environment variables. We suggest to manually transfer config values from there into environment variables.
# NOTE TeamCity uses (almost) no environment variables. We suggest to manually transfer config values from there into environment variables.
VARS_LIST_HTML_GITLAB_FILE="target/ci_vers_gitlab.html"
VARS_LIST_HTML_GITHUB_FILE="target/ci_vers_github.html"
VARS_LIST_HTML_BITBUCKET_FILE="target/ci_vers_bitbucket.html"
VARS_LIST_HTML_JENKINS_FILE="target/ci_vers_jenkins.html"
VARS_LIST_HTML_TRAVISCI_FILE="target/ci_vers_travisci.html"
GITLAB_FILE="target/gitlab.sh.env"
GITHUB_FILE="target/github.sh.env"
BITBUCKET_FILE="target/bitbucket.sh.env"
JENKINS_FILE="target/jenkins.sh.env"
TRAVISCI_FILE="target/travisci.sh.env"
download=false
if $download
then
wget "$VARS_LIST_HTML_GITLAB_URL" -O "$VARS_LIST_HTML_GITLAB_FILE"
wget "$VARS_LIST_HTML_GITHUB_URL" -O "$VARS_LIST_HTML_GITHUB_FILE"
wget "$VARS_LIST_HTML_BITBUCKET_URL" -O "$VARS_LIST_HTML_BITBUCKET_FILE"
wget "$VARS_LIST_HTML_JENKINS_URL" -O "$VARS_LIST_HTML_JENKINS_FILE"
wget "$VARS_LIST_HTML_TRAVISCI_URL" -O "$VARS_LIST_HTML_TRAVISCI_FILE"
fi
# Cleanup the downloaded HTML
cleanup_html_files \
"$VARS_LIST_HTML_GITLAB_FILE" \
"$VARS_LIST_HTML_GITHUB_FILE" \
"$VARS_LIST_HTML_BITBUCKET_FILE" \
"$VARS_LIST_HTML_JENKINS_FILE" \
"$VARS_LIST_HTML_TRAVISCI_FILE"
sed -i -e 's|<p[^>]*>||g' -e 's|</p>||g' "$VARS_LIST_HTML_BITBUCKET_FILE"
cleanup_html_files "$VARS_LIST_HTML_BITBUCKET_FILE"
filter_tabular_html "$VARS_LIST_HTML_GITLAB_FILE" 0 3 > "$GITLAB_FILE"
filter_tabular_html "$VARS_LIST_HTML_GITHUB_FILE" 0 1 > "$GITHUB_FILE"
filter_tabular_html "$VARS_LIST_HTML_BITBUCKET_FILE" 0 1 > "$BITBUCKET_FILE"
filter_tabular_html "$VARS_LIST_HTML_JENKINS_FILE" 0 1 > "$JENKINS_FILE"
filter_list_html "$VARS_LIST_HTML_TRAVISCI_FILE" > "$TRAVISCI_FILE"