-
Notifications
You must be signed in to change notification settings - Fork 51
/
entrypoint.sh
executable file
·154 lines (126 loc) · 4.29 KB
/
entrypoint.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
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
#!/bin/bash
set -eu
source /common.sh
# For backwards compatible also accept environment variable names, but parse all inputs in github
# action format
export RUSTTARGET="${INPUT_RUSTTARGET:-${RUSTTARGET:-}}"
EXTRA_FILES="${INPUT_EXTRA_FILES:-${EXTRA_FILES:-}}"
# SRC_DIR is handled in build.sh
ARCHIVE_TYPES="${INPUT_ARCHIVE_TYPES:-${ARCHIVE_TYPES:-}}"
ARCHIVE_NAME="${INPUT_ARCHIVE_NAME:-${ARCHIVE_NAME:-}}"
PRE_BUILD="${INPUT_PRE_BUILD:-${PRE_BUILD:-}}"
POST_BUILD="${INPUT_POST_BUILD:-${POST_BUILD:-}}"
export MINIFY="${INPUT_MINIFY:-${MINIFY:-}}"
export TOOLCHAIN_VERSION="${INPUT_TOOLCHAIN_VERSION:-${TOOLCHAIN_VERSION:-}}"
UPLOAD_MODE="${INPUT_UPLOAD_MODE:-${UPLOAD_MODE:-release}}"
RUSTFLAGS="${INPUT_RUSTFLAGS:-${RUSTFLAGS:-}}"
STATIC_LINK="${INPUT_STATIC_LINKING:-${STATIC_LINK:-}}"
if ! is_empty "$STATIC_LINK" && ! printf "%s" "$RUSTFLAGS" | grep -q "crt-static"; then
if is_true "$STATIC_LINK"; then
RUSTFLAGS="$RUSTFLAGS -C target-feature=+crt-static"
else
RUSTFLAGS="$RUSTFLAGS -C target-feature=-crt-static"
fi
fi
export RUSTFLAGS
EXTRA_COMMAND_FLAGS="${INPUT_EXTRA_COMMAND_FLAGS:-${EXTRA_COMMAND_FLAGS:-}}"
# Features (without default features)
FEATURES="${INPUT_FEATURES:-${FEATURES:-}}"
if ! is_empty "$FEATURES"; then
EXTRA_COMMAND_FLAGS="$EXTRA_COMMAND_FLAGS --no-default-features"
fi
# Additional enabled features
EXTRA_FEATURES="${INPUT_EXTRA_FEATURES:-${EXTRA_FEATURES:-}}"
FEATURES="$FEATURES$EXTRA_FEATURES"
if ! is_empty "$FEATURES"; then
EXTRA_COMMAND_FLAGS="$EXTRA_COMMAND_FLAGS --features $FEATURES"
fi
export EXTRA_COMMAND_FLAGS
if [ -z "${CMD_PATH+x}" ]; then
export CMD_PATH=""
fi
OUTPUT_DIR="/github/workspace/output"
mkdir -p "$OUTPUT_DIR"
# Link repo
PROJECT_ROOT="/rust/build/${GITHUB_REPOSITORY}"
mkdir -p "$PROJECT_ROOT"
rmdir "$PROJECT_ROOT"
ln -s "$GITHUB_WORKSPACE" "$PROJECT_ROOT"
cd "$PROJECT_ROOT"
# Run pre-build script
if [ -f "$PRE_BUILD" ]; then
"./$PRE_BUILD"
fi
# Build
if ! FILE_LIST=$(/build.sh "$OUTPUT_DIR"); then
error "Build failed"
exit 1
fi
# Run post-build script
if [ -f "$POST_BUILD" ]; then
"./$POST_BUILD"
fi
EVENT_DATA=$(cat "$GITHUB_EVENT_PATH")
echo "$EVENT_DATA" | jq .
UPLOAD_URL=$(echo "$EVENT_DATA" | jq -r .release.upload_url)
UPLOAD_URL=${UPLOAD_URL/\{?name,label\}/}
RELEASE_NAME=$(echo "$EVENT_DATA" | jq -r .release.tag_name)
PROJECT_NAME=$(basename "$GITHUB_REPOSITORY")
NAME="${ARCHIVE_NAME:-${PROJECT_NAME}_${RELEASE_NAME}_${RUSTTARGET}}"
ARCHIVE_TYPES="${ARCHIVE_TYPES:-"zip"}"
EXTRA_FILES="${EXTRA_FILES:-""}"
if [ -z "${EXTRA_FILES+x}" ]; then
warn "EXTRA_FILES not set"
else
for file in $(echo -n "${EXTRA_FILES}" | tr " " "\n"); do
cp --parents "$file" "$OUTPUT_DIR"
done
fi
cd "$OUTPUT_DIR"
if [ -n "${EXTRA_FILES+0}" ]; then
FILE_LIST="${FILE_LIST} ${EXTRA_FILES}"
fi
FILE_LIST=$(echo "${FILE_LIST}" | awk '{$1=$1};1')
info "Packing files: $FILE_LIST"
for ARCHIVE_TYPE in $ARCHIVE_TYPES; do
ARCHIVE="tmp.${ARCHIVE_TYPE}"
# shellcheck disable=SC2086
case $ARCHIVE_TYPE in
"zip")
zip -9r $ARCHIVE ${FILE_LIST}
;;
"tar"|"tar.gz"|"tar.bz2"|"tar.xz"|"tar.zst")
tar caf $ARCHIVE ${FILE_LIST}
;;
*)
error "The given archive type '${ARCHIVE_TYPE}' is not supported; please use a supported archive type."
continue
esac
FILE_NAME="${NAME}.${ARCHIVE/tmp./}"
printf "%s %s" "$(sha256sum "${ARCHIVE}" | cut -d ' ' -f 1)" "$FILE_NAME" > "${ARCHIVE}.sha256sum"
CHECKSUM_FILE_NAME="${FILE_NAME}.sha256sum"
mv "$ARCHIVE" "$FILE_NAME"
mv "${ARCHIVE}.sha256sum" "$CHECKSUM_FILE_NAME"
set_output "BUILT_ARCHIVE" "output/${FILE_NAME}"
set_output "BUILT_CHECKSUM" "output/${CHECKSUM_FILE_NAME}"
if [ "$UPLOAD_MODE" = "release" ]; then
if [ "$UPLOAD_URL" = "null" ]; then
warn "UPLOAD_MODE \"release\" was specified but no URL to upload to could be detected"
else
curl \
--fail-with-body -sS \
-X POST \
--data-binary @"${FILE_NAME}" \
-H 'Content-Type: application/octet-stream' \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
"${UPLOAD_URL}?name=${FILE_NAME}"
curl \
--fail-with-body -sS \
-X POST \
--data-binary @"$CHECKSUM_FILE_NAME" \
-H 'Content-Type: text/plain' \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
"${UPLOAD_URL}?name=${CHECKSUM_FILE_NAME}"
fi
fi
done