-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-release.sh
More file actions
executable file
·136 lines (108 loc) · 4.2 KB
/
build-release.sh
File metadata and controls
executable file
·136 lines (108 loc) · 4.2 KB
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
#!/usr/bin/env bash
set -euo pipefail
# Build Release assets for all PHP docsets.
# Generate partial site files.
ROOT="$(cd "$(dirname "$0")" && pwd)"
source "$ROOT/lib/common.sh"
OUTPUT_DIR="release"
OUTPUT="$ROOT/$OUTPUT_DIR"
SITE="$ROOT/_site"
RELEASE_BODY_FILE="$OUTPUT/body.md"
RELEASE_ASSETS_FILE="$OUTPUT/assets.txt"
# Store docset versions table rows for release body
DOCSET_VERSIONS_ROWS=""
build_release() {
local lang=$(normalize_lang_code "$1")
local docset_name="PHP_${lang}"
local docset_filename="${docset_name}.docset"
local docset="$OUTPUT/$docset_filename"
local docset_archive="${docset_name}.tgz"
local docset_archive_path="$OUTPUT/$docset_archive"
local docset_archive_url="https://github.com/ElfSundae/dash-php/releases/download/docsets/${docset_archive}"
local lang_en_name=$(get_lang_en_name "$lang")
local feed_filename="PHP_-_${lang_en_name// /_}.xml"
local feed_url="https://elfsundae.github.io/dash-php/feeds/${feed_filename}"
local install_url="https://elfsundae.github.io/dash-php/feed/?lang=${lang}"
echo "===== Build Release Assets for $docset_filename ====="
if ! "$ROOT/generate.sh" "$lang" --output "$OUTPUT"; then
msg_main "Try to download existing docset: ${docset_archive_url}..."
if ! curl -fsL -o "$docset_archive_path" "$docset_archive_url"; then
msg_error "Failed to download existing docset: $docset_archive"
return 0
fi
msg_main "Unarchiving ${docset_archive}..."
tar -xf "$docset_archive_path" -C "$OUTPUT" || {
msg_error "Failed to unarchive $docset_archive"
return 0
}
fi
if [[ ! -f "$docset_archive_path" ]]; then
msg_main "Archiving ${docset_filename}..."
(
cd "$OUTPUT"
tar --exclude='.DS_Store' --exclude='optimizedIndex.dsidx' -czf "$docset_archive" "$docset_filename"
) || {
msg_error "Failed to archive $docset_filename"
reutrn 0
}
msg_sub "Archived $docset_filename to $docset_archive"
fi
local docset_bundle_name
docset_bundle_name=$(get_docset_bundle_name "$docset")
if [[ -z "$docset_bundle_name" ]]; then
msg_error "Failed to obtain docset bundle name."
return 0
fi
msg_main "$docset_filename bundle name: $docset_bundle_name"
local docset_build_date
docset_build_date=$(get_docset_build_date "$docset")
if [[ -z "$docset_build_date" ]]; then
msg_error "Failed to obtain docset build date."
return 0
fi
msg_main "$docset_filename build date: $docset_build_date"
msg_main "Obtaining the docset version..."
local version
version=$(get_docset_version "$docset")
if [[ -z "$version" ]]; then
msg_error "Failed to obtain the docset version."
return 0
fi
msg_sub "$docset_filename version: $version"
tee "${OUTPUT}/${feed_filename}" <<EOF
<entry>
<version>${version}</version>
<buildDate>${docset_build_date}</buildDate>
<url>${docset_archive_url}</url>
</entry>
EOF
echo "$OUTPUT_DIR/${docset_archive}" >> "$RELEASE_ASSETS_FILE"
# echo "$OUTPUT_DIR/${feed_filename}" >> "$RELEASE_ASSETS_FILE"
DOCSET_VERSIONS_ROWS+="| ${docset_bundle_name} | \
${docset_build_date} | \`${version}\` | <${feed_url}> | \
📚 [Add to Dash](${install_url} \"Add ${docset_bundle_name} docset feed to Dash\") | \
"$'\n'
msg_main "Generating site files..."
mkdir -p "$SITE/feeds"
cp "${OUTPUT}/${feed_filename}" "$SITE/feeds/"
mkdir -p "$SITE/badges"
badge "$docset_build_date" "$version" blue grey > "$SITE/badges/${docset_name}.svg"
}
require_command curl md5sum tar badge
rm -rf "$OUTPUT"
mkdir -p "$OUTPUT"
rm -rf "$SITE"
mkdir -p "$SITE"
for lang in "${LANG_CODES[@]}"; do
build_release "$lang"
done
if [[ ! -s "$RELEASE_ASSETS_FILE" ]]; then
msg_error "Failed to build any docset release assets."
exit 10
fi
cat <<EOF > "$RELEASE_BODY_FILE"
This release provides automatically updated Dash docsets for the [PHP Manual](https://www.php.net/manual), available in multiple languages.
| Docset | Build Date | Version | Feed URL | Install |
|--------|------------|---------|----------|---------|
$DOCSET_VERSIONS_ROWS
EOF