@@ -9,60 +9,60 @@ PKG="meeDamian/github-release@2.0"
9
9
#
10
10
TOKEN=" $INPUT_TOKEN "
11
11
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
21
21
fi
22
22
23
23
# Try getting $tag from action input
24
24
tag=" $INPUT_TAG "
25
25
26
26
# [fallback] Try getting $tag from Github context (only works on git-tag push action)
27
27
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 }' ) "
29
29
fi
30
30
31
31
# If all ways of getting the $tag failed, exit with an error
32
32
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
45
45
fi
46
46
47
47
# Verify that gzip: option is set to any of the allowed values
48
48
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
58
58
fi
59
59
60
60
releases_url=" https://api.github.com/repos/$GITHUB_REPOSITORY /releases"
61
61
62
62
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 "
66
66
}
67
67
68
68
#
@@ -72,15 +72,15 @@ gh_release_api() {
72
72
release_id=" $( gh_release_api " tags/$tag " | jq -r ' .id | select(. != null)' ) "
73
73
74
74
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
84
84
fi
85
85
86
86
echo " ::group::Create Release"
@@ -90,8 +90,8 @@ TMP="$(mktemp -d)"
90
90
method=" POST"
91
91
full_url=" $releases_url "
92
92
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 "
95
95
fi
96
96
97
97
# If `draft` is not set, while `files` are provided, then
100
100
# 3. If all uploads succeed, publish the Release
101
101
draft=" $INPUT_DRAFT "
102
102
if [ -z " $INPUT_DRAFT " ] && [ -n " $INPUT_FILES " ]; then
103
- draft=true
103
+ draft=true
104
104
fi
105
105
106
106
# Creating the object in a PATCH-friendly way
107
107
# If POST: https://developer.github.com/v3/repos/releases/#create-a-release,
108
108
# If PATCH: https://developer.github.com/v3/repos/releases/#edit-a-release
109
109
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 " ) "
122
122
123
123
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
128
128
fi
129
129
130
130
@@ -139,8 +139,8 @@ echo "::endgroup::"
139
139
#
140
140
141
141
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
144
144
fi
145
145
146
146
echo " ::group::Upload Assets"
@@ -151,48 +151,48 @@ mkdir -p "$assets/"
151
151
152
152
# This loop splits files on space
153
153
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
168
168
169
169
# 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
196
196
done
197
197
198
198
@@ -205,66 +205,66 @@ current_assets=
205
205
206
206
# If override is allowed, make sure there's no asset name collisions with ones already uploaded
207
207
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' ) "
211
211
fi
212
212
213
213
214
214
upload_url=" $( echo " $releases_url " | sed -e ' s|api|uploads|' ) "
215
215
216
216
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
244
244
done
245
245
246
246
echo " ::endgroup::"
247
247
248
248
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
251
251
fi
252
252
253
253
echo " ::group::Complete Release"
254
254
255
255
# Publish Release
256
256
# docs ref: https://developer.github.com/v3/repos/releases/#edit-a-release
257
257
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 " ) "
262
262
263
263
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
268
268
fi
269
269
270
270
echo " ::endgroup::"
0 commit comments