Skip to content

Commit d1bb7a8

Browse files
committed
spaces to tabs
1 parent dccb989 commit d1bb7a8

File tree

1 file changed

+144
-144
lines changed

1 file changed

+144
-144
lines changed

entrypoint.sh

+144-144
Original file line numberDiff line numberDiff line change
@@ -9,60 +9,60 @@ PKG="meeDamian/github-release@2.0"
99
#
1010
TOKEN="$INPUT_TOKEN"
1111
if [ -z "$TOKEN" ]; then
12-
>&2 echo "::error::missing: token (see log for details)"
13-
>&2 printf "\nERR: Invalid input: 'token' is required, and must be specified.\n"
14-
>&2 printf "\tNote: It's necessary to interact with Github's API.\n\n"
15-
>&2 printf "Try:\n"
16-
>&2 printf "\tuses: %s\n" "$PKG"
17-
>&2 printf "\twith:\n"
18-
>&2 printf "\t token: \${{ secrets.GITHUB_TOKEN }}\n"
19-
>&2 printf "\t ...\n\n"
20-
exit 1
12+
>&2 echo "::error::missing: token (see log for details)"
13+
>&2 printf "\nERR: Invalid input: 'token' is required, and must be specified.\n"
14+
>&2 printf "\tNote: It's necessary to interact with Github's API.\n\n"
15+
>&2 printf "Try:\n"
16+
>&2 printf "\tuses: %s\n" "$PKG"
17+
>&2 printf "\twith:\n"
18+
>&2 printf "\t token: \${{ secrets.GITHUB_TOKEN }}\n"
19+
>&2 printf "\t ...\n\n"
20+
exit 1
2121
fi
2222

2323
# Try getting $tag from action input
2424
tag="$INPUT_TAG"
2525

2626
# [fallback] Try getting $tag from Github context (only works on git-tag push action)
2727
if [ -z "$tag" ]; then
28-
tag="$(echo "$GITHUB_REF" | grep 'refs/tags/' | awk -F/ '{ print $NF }')"
28+
tag="$(echo "$GITHUB_REF" | grep 'refs/tags/' | awk -F/ '{ print $NF }')"
2929
fi
3030

3131
# If all ways of getting the $tag failed, exit with an error
3232
if [ -z "$tag" ]; then
33-
>&2 echo "::error::missing: tag (see log for details)"
34-
>&2 printf "\nERR: Invalid input: 'tag' is required, and must be specified.\n"
35-
>&2 printf "Try:\n"
36-
>&2 printf "\tuses: %s\n" "$PKG"
37-
>&2 printf "\twith:\n"
38-
>&2 printf "\t tag: v0.0.1\n"
39-
>&2 printf "\t ...\n\n"
40-
>&2 printf "Note: To use \$tag from env variable set before, use:\n"
41-
>&2 printf '\twith:\n'
42-
>&2 printf "\t tag: \${{ env.TAG }}\n"
43-
>&2 printf "\t ...\n\n"
44-
exit 1
33+
>&2 echo "::error::missing: tag (see log for details)"
34+
>&2 printf "\nERR: Invalid input: 'tag' is required, and must be specified.\n"
35+
>&2 printf "Try:\n"
36+
>&2 printf "\tuses: %s\n" "$PKG"
37+
>&2 printf "\twith:\n"
38+
>&2 printf "\t tag: v0.0.1\n"
39+
>&2 printf "\t ...\n\n"
40+
>&2 printf "Note: To use \$tag from env variable set before, use:\n"
41+
>&2 printf '\twith:\n'
42+
>&2 printf "\t tag: \${{ env.TAG }}\n"
43+
>&2 printf "\t ...\n\n"
44+
exit 1
4545
fi
4646

4747
# Verify that gzip: option is set to any of the allowed values
4848
if [ "$INPUT_GZIP" != "true" ] && [ "$INPUT_GZIP" != "false" ] && [ "$INPUT_GZIP" != "folders" ]; then
49-
>&2 echo "::error::invalid: gzip (see log for details)"
50-
>&2 printf "\nERR: Invalid input: 'gzip' can only be not set, or one of: true, false, folders\n"
51-
>&2 printf "\tNote: It defines what to do with assets before uploading them.\n\n"
52-
>&2 printf "Try:\n"
53-
>&2 printf "\tuses: %s\n" "$PKG"
54-
>&2 printf "\twith:\n"
55-
>&2 printf "\t gzip: true\n"
56-
>&2 printf "\t ...\n\n"
57-
exit 1
49+
>&2 echo "::error::invalid: gzip (see log for details)"
50+
>&2 printf "\nERR: Invalid input: 'gzip' can only be not set, or one of: true, false, folders\n"
51+
>&2 printf "\tNote: It defines what to do with assets before uploading them.\n\n"
52+
>&2 printf "Try:\n"
53+
>&2 printf "\tuses: %s\n" "$PKG"
54+
>&2 printf "\twith:\n"
55+
>&2 printf "\t gzip: true\n"
56+
>&2 printf "\t ...\n\n"
57+
exit 1
5858
fi
5959

6060
releases_url="https://api.github.com/repos/$GITHUB_REPOSITORY/releases"
6161

6262
gh_release_api() {
63-
url="$1"
64-
method="${2:-GET}"
65-
curl -sS -H "Authorization: token $TOKEN" -X "$method" "$releases_url/$url"
63+
url="$1"
64+
method="${2:-GET}"
65+
curl -sS -H "Authorization: token $TOKEN" -X "$method" "$releases_url/$url"
6666
}
6767

6868
#
@@ -72,15 +72,15 @@ gh_release_api() {
7272
release_id="$(gh_release_api "tags/$tag" | jq -r '.id | select(. != null)')"
7373

7474
if [ -n "$release_id" ] && [ "$INPUT_ALLOW_OVERRIDE" != "true" ]; then
75-
>&2 echo "::error::missing: allow_override (see log for details)"
76-
>&2 printf "\nERR: Release for tag='%s' already exists, and overriding is not allowed.\n" "$tag"
77-
>&2 printf "\tNote: Either use different 'tag:' name, or set 'allow_override:'\n\n"
78-
>&2 printf "Try:\n"
79-
>&2 printf "\tuses: %s\n" "$PKG"
80-
>&2 printf "\twith:\n"
81-
>&2 printf "\t ...\n"
82-
>&2 printf "\t allow_override: true\n\n"
83-
exit 1
75+
>&2 echo "::error::missing: allow_override (see log for details)"
76+
>&2 printf "\nERR: Release for tag='%s' already exists, and overriding is not allowed.\n" "$tag"
77+
>&2 printf "\tNote: Either use different 'tag:' name, or set 'allow_override:'\n\n"
78+
>&2 printf "Try:\n"
79+
>&2 printf "\tuses: %s\n" "$PKG"
80+
>&2 printf "\twith:\n"
81+
>&2 printf "\t ...\n"
82+
>&2 printf "\t allow_override: true\n\n"
83+
exit 1
8484
fi
8585

8686
echo "::group::Create Release"
@@ -90,8 +90,8 @@ TMP="$(mktemp -d)"
9090
method="POST"
9191
full_url="$releases_url"
9292
if [ -n "$release_id" ]; then
93-
method="PATCH"
94-
full_url="$full_url/$release_id"
93+
method="PATCH"
94+
full_url="$full_url/$release_id"
9595
fi
9696

9797
# If `draft` is not set, while `files` are provided, then
@@ -100,31 +100,31 @@ fi
100100
# 3. If all uploads succeed, publish the Release
101101
draft="$INPUT_DRAFT"
102102
if [ -z "$INPUT_DRAFT" ] && [ -n "$INPUT_FILES" ]; then
103-
draft=true
103+
draft=true
104104
fi
105105

106106
# Creating the object in a PATCH-friendly way
107107
# If POST: https://developer.github.com/v3/repos/releases/#create-a-release,
108108
# If PATCH: https://developer.github.com/v3/repos/releases/#edit-a-release
109109
status_code="$(jq -nc \
110-
--arg tag_name "$tag" \
111-
--arg name "$INPUT_NAME" \
112-
--arg body "$(printf '%s' "$INPUT_BODY" | sed 's|\\|\\\\|g')" \
113-
--arg target_commitish "$INPUT_COMMITISH" \
114-
--argjson draft "${draft:-null}" \
115-
--argjson prerelease "${INPUT_PRERELEASE:-null}" \
116-
'{$tag_name, $name, $body, $target_commitish, $draft, $prerelease} | del(.[] | select(. == null or . == ""))' | \
117-
curl -sS -X "$method" -d @- \
118-
--write-out "%{http_code}" -o "$TMP/$method.json" \
119-
-H "Authorization: token $TOKEN" \
120-
-H "Content-Type: application/json" \
121-
"$full_url")"
110+
--arg tag_name "$tag" \
111+
--arg name "$INPUT_NAME" \
112+
--arg body "$(printf '%s' "$INPUT_BODY" | sed 's|\\|\\\\|g')" \
113+
--arg target_commitish "$INPUT_COMMITISH" \
114+
--argjson draft "${draft:-null}" \
115+
--argjson prerelease "${INPUT_PRERELEASE:-null}" \
116+
'{$tag_name, $name, $body, $target_commitish, $draft, $prerelease} | del(.[] | select(. == null or . == ""))' | \
117+
curl -sS -X "$method" -d @- \
118+
--write-out "%{http_code}" -o "$TMP/$method.json" \
119+
-H "Authorization: token $TOKEN" \
120+
-H "Content-Type: application/json" \
121+
"$full_url")"
122122

123123
if [ "$status_code" != "200" ] && [ "$status_code" != "201" ]; then
124-
>&2 echo "::error::failed to create release (see log for details)"
125-
>&2 printf "\n\tERR: %s to Github release has failed\n" "$method"
126-
>&2 jq . < "$TMP/$method.json"
127-
exit 1
124+
>&2 echo "::error::failed to create release (see log for details)"
125+
>&2 printf "\n\tERR: %s to Github release has failed\n" "$method"
126+
>&2 jq . < "$TMP/$method.json"
127+
exit 1
128128
fi
129129

130130

@@ -139,8 +139,8 @@ echo "::endgroup::"
139139
#
140140

141141
if [ -z "$INPUT_FILES" ]; then
142-
>&2 echo "No assets to upload. All done."
143-
exit 0
142+
>&2 echo "No assets to upload. All done."
143+
exit 0
144144
fi
145145

146146
echo "::group::Upload Assets"
@@ -151,48 +151,48 @@ mkdir -p "$assets/"
151151

152152
# This loop splits files on space
153153
for entry in $INPUT_FILES; do
154-
# Well, that needs explaining… If delimiter given in `-d` does not occur in string, `cut` always returns
155-
# the original string, no matter what the field `-f` specifies.
156-
#
157-
# Prepend `:` to `$entry` to ensure match happens, because `-f` in `cut` is only respected when it does, and that way:
158-
# * `-f 2` always contains the name of the asset
159-
# * `-f 3` is either the custom name of the asset, or
160-
# is empty, and needs to be set to value of `-f 2`
161-
asset_name="$(echo ":$entry" | cut -d: -f2)"
162-
asset_path="$(echo ":$entry" | cut -d: -f3)"
163-
164-
if [ -z "$asset_path" ]; then
165-
asset_name="$(basename "$entry")"
166-
asset_path="$entry"
167-
fi
154+
# Well, that needs explaining… If delimiter given in `-d` does not occur in string, `cut` always returns
155+
# the original string, no matter what the field `-f` specifies.
156+
#
157+
# Prepend `:` to `$entry` to ensure match happens, because `-f` in `cut` is only respected when it does, and that way:
158+
# * `-f 2` always contains the name of the asset
159+
# * `-f 3` is either the custom name of the asset, or
160+
# is empty, and needs to be set to value of `-f 2`
161+
asset_name="$(echo ":$entry" | cut -d: -f2)"
162+
asset_path="$(echo ":$entry" | cut -d: -f3)"
163+
164+
if [ -z "$asset_path" ]; then
165+
asset_name="$(basename "$entry")"
166+
asset_path="$entry"
167+
fi
168168

169169
# this loop, expands possible globs
170-
for file in $asset_path; do
171-
# Error out on the only illegal combination: compression disabled AND folder provided
172-
if [ "$INPUT_GZIP" = "false" ] && [ -d "$file" ]; then
173-
>&2 echo "::error::invalid: gzip and files combination (see log for details)"
174-
>&2 printf "\nERR: Invalid configuration: 'gzip' cannot be set to 'false' while there are 'folders/' provided.\n"
175-
>&2 printf "\tNote: Either set 'gzip: folders', or remove directories from the 'files:' list.\n\n"
176-
>&2 printf "Try:\n"
177-
>&2 printf "\tuses: %s\n" "$PKG"
178-
>&2 printf "\twith:\n"
179-
>&2 printf "\t ...\n"
180-
>&2 printf "\t gzip: folders\n"
181-
>&2 printf "\t files: >\n"
182-
>&2 printf "\t README.md\n"
183-
>&2 printf "\t my-artifacts/\n"
184-
exit 1
185-
fi
186-
187-
# Just copy files, if compression not enabled for all
188-
if [ "$INPUT_GZIP" != "true" ] && [ -f "$file" ]; then
189-
cp "$file" "$assets/$asset_name"
190-
continue
191-
fi
192-
193-
# In any other case compress
194-
tar -czf "$assets/$asset_name.tgz" "$file"
195-
done
170+
for file in $asset_path; do
171+
# Error out on the only illegal combination: compression disabled AND folder provided
172+
if [ "$INPUT_GZIP" = "false" ] && [ -d "$file" ]; then
173+
>&2 echo "::error::invalid: gzip and files combination (see log for details)"
174+
>&2 printf "\nERR: Invalid configuration: 'gzip' cannot be set to 'false' while there are 'folders/' provided.\n"
175+
>&2 printf "\tNote: Either set 'gzip: folders', or remove directories from the 'files:' list.\n\n"
176+
>&2 printf "Try:\n"
177+
>&2 printf "\tuses: %s\n" "$PKG"
178+
>&2 printf "\twith:\n"
179+
>&2 printf "\t ...\n"
180+
>&2 printf "\t gzip: folders\n"
181+
>&2 printf "\t files: >\n"
182+
>&2 printf "\t README.md\n"
183+
>&2 printf "\t my-artifacts/\n"
184+
exit 1
185+
fi
186+
187+
# Just copy files, if compression not enabled for all
188+
if [ "$INPUT_GZIP" != "true" ] && [ -f "$file" ]; then
189+
cp "$file" "$assets/$asset_name"
190+
continue
191+
fi
192+
193+
# In any other case compress
194+
tar -czf "$assets/$asset_name.tgz" "$file"
195+
done
196196
done
197197

198198

@@ -205,66 +205,66 @@ current_assets=
205205

206206
# If override is allowed, make sure there's no asset name collisions with ones already uploaded
207207
if [ "$INPUT_ALLOW_OVERRIDE" = "true" ]; then
208-
# Get list of all assets as a JSON map of: name->id
209-
# docs ref: https://developer.github.com/v3/repos/releases/#list-assets-for-a-release
210-
current_assets="$(gh_release_api "$release_id/assets" | jq -r 'map({ (.name): .id }) | add')"
208+
# Get list of all assets as a JSON map of: name->id
209+
# docs ref: https://developer.github.com/v3/repos/releases/#list-assets-for-a-release
210+
current_assets="$(gh_release_api "$release_id/assets" | jq -r 'map({ (.name): .id }) | add')"
211211
fi
212212

213213

214214
upload_url="$(echo "$releases_url" | sed -e 's|api|uploads|')"
215215

216216
for asset in "$assets"/*; do
217-
file_name="$(basename "$asset")"
218-
219-
# If a list of previously uploaded assets is available, and contains
220-
# item with the same name as currently uploaded, delete it first.
221-
if [ -n "$current_assets" ]; then
222-
asset_id="$(echo "$current_assets" | jq ".\"$file_name\"")"
223-
if [ -n "$asset_id" ]; then
224-
# docs ref: https://developer.github.com/v3/repos/releases/#delete-a-release-asset
225-
gh_release_api "assets/$asset_id" DELETE
226-
fi
227-
fi
228-
229-
# docs ref: https://developer.github.com/v3/repos/releases/#upload-a-release-asset
230-
status_code="$(curl -sS -X POST \
231-
--write-out "%{http_code}" -o "$TMP/$file_name.json" \
232-
-H "Authorization: token $TOKEN" \
233-
-H "Content-Length: $(stat -c %s "$asset")" \
234-
-H "Content-Type: $(file -b --mime-type "$asset")" \
235-
--upload-file "$asset" \
236-
"$upload_url/$release_id/assets?name=$file_name")"
237-
238-
if [ "$status_code" -ne "201" ]; then
239-
>&2 echo "::error::failed to upload asset: $file_name (see log for details)"
240-
>&2 printf "\n\tERR: Failed asset upload: %s\n" "$file_name"
241-
>&2 jq . < "$TMP/$file_name.json"
242-
exit 1
243-
fi
217+
file_name="$(basename "$asset")"
218+
219+
# If a list of previously uploaded assets is available, and contains
220+
# item with the same name as currently uploaded, delete it first.
221+
if [ -n "$current_assets" ]; then
222+
asset_id="$(echo "$current_assets" | jq ".\"$file_name\"")"
223+
if [ -n "$asset_id" ]; then
224+
# docs ref: https://developer.github.com/v3/repos/releases/#delete-a-release-asset
225+
gh_release_api "assets/$asset_id" DELETE
226+
fi
227+
fi
228+
229+
# docs ref: https://developer.github.com/v3/repos/releases/#upload-a-release-asset
230+
status_code="$(curl -sS -X POST \
231+
--write-out "%{http_code}" -o "$TMP/$file_name.json" \
232+
-H "Authorization: token $TOKEN" \
233+
-H "Content-Length: $(stat -c %s "$asset")" \
234+
-H "Content-Type: $(file -b --mime-type "$asset")" \
235+
--upload-file "$asset" \
236+
"$upload_url/$release_id/assets?name=$file_name")"
237+
238+
if [ "$status_code" -ne "201" ]; then
239+
>&2 echo "::error::failed to upload asset: $file_name (see log for details)"
240+
>&2 printf "\n\tERR: Failed asset upload: %s\n" "$file_name"
241+
>&2 jq . < "$TMP/$file_name.json"
242+
exit 1
243+
fi
244244
done
245245

246246
echo "::endgroup::"
247247

248248
if [ -n "$INPUT_DRAFT" ]; then
249-
>&2 echo "Draft status already correct. All done."
250-
exit 0
249+
>&2 echo "Draft status already correct. All done."
250+
exit 0
251251
fi
252252

253253
echo "::group::Complete Release"
254254

255255
# Publish Release
256256
# docs ref: https://developer.github.com/v3/repos/releases/#edit-a-release
257257
status_code="$(curl -sS -X PATCH -d '{"draft": false}' \
258-
--write-out "%{http_code}" -o "$TMP/publish.json" \
259-
-H "Authorization: token $TOKEN" \
260-
-H "Content-Type: application/json" \
261-
"$releases_url/$release_id")"
258+
--write-out "%{http_code}" -o "$TMP/publish.json" \
259+
-H "Authorization: token $TOKEN" \
260+
-H "Content-Type: application/json" \
261+
"$releases_url/$release_id")"
262262

263263
if [ "$status_code" != "200" ]; then
264-
>&2 echo "::error::failed to complete release (see log for details)"
265-
>&2 printf "\n\tERR: Final publishing of the ready Github Release has failed\n"
266-
>&2 jq . < "$TMP/publish.json"
267-
exit 1
264+
>&2 echo "::error::failed to complete release (see log for details)"
265+
>&2 printf "\n\tERR: Final publishing of the ready Github Release has failed\n"
266+
>&2 jq . < "$TMP/publish.json"
267+
exit 1
268268
fi
269269

270270
echo "::endgroup::"

0 commit comments

Comments
 (0)