ci(release): honor dry_run input and send JSON Content-Type
Some checks failed
ci / test (pull_request) Failing after 4m1s
Some checks failed
ci / test (pull_request) Failing after 4m1s
Forgejo dispatch passes string inputs; boolean dry_run stayed false and tried to mint v0.1.0. Strip PAT newlines so Authorization does not eat the next header (422 Empty Content-Type).
This commit is contained in:
parent
111b95c3ae
commit
58e10a0bc0
1 changed files with 12 additions and 12 deletions
|
|
@ -23,10 +23,10 @@ on:
|
||||||
required: false
|
required: false
|
||||||
type: string
|
type: string
|
||||||
dry_run:
|
dry_run:
|
||||||
description: Build and checksum without creating a tag or publishing
|
description: Build and checksum without creating a tag or publishing (true/false)
|
||||||
required: false
|
required: false
|
||||||
type: boolean
|
type: string
|
||||||
default: false
|
default: "false"
|
||||||
|
|
||||||
concurrency:
|
concurrency:
|
||||||
group: onionwire-release
|
group: onionwire-release
|
||||||
|
|
@ -59,22 +59,24 @@ jobs:
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
: "${FORGEJO_TOKEN:?FORGEJO_TOKEN secret is not set}"
|
: "${FORGEJO_TOKEN:?FORGEJO_TOKEN secret is not set}"
|
||||||
|
FORGEJO_TOKEN=$(printf '%s' "$FORGEJO_TOKEN" | tr -d '\r\n')
|
||||||
dry_run=false
|
dry_run=false
|
||||||
if [ "$EVENT_NAME" = "workflow_dispatch" ]; then
|
if [ "$EVENT_NAME" = "workflow_dispatch" ]; then
|
||||||
case "${INPUT_DRY_RUN:-false}" in
|
case "${INPUT_DRY_RUN:-false}" in
|
||||||
true|True|TRUE) dry_run=true ;;
|
true|True|TRUE|1|yes|YES) dry_run=true ;;
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
|
echo "event=$EVENT_NAME sha=$EVENT_SHA input_tag=${INPUT_TAG-} input_dry_run=${INPUT_DRY_RUN-} dry_run=$dry_run"
|
||||||
|
|
||||||
api_curl() {
|
api_curl() {
|
||||||
curl -sS --http1.1 --retry 5 --retry-all-errors --retry-delay 3 \
|
curl -sS --http1.1 --retry 5 --retry-all-errors --retry-delay 3 \
|
||||||
--connect-timeout 20 --max-time 60 "$@"
|
--connect-timeout 20 --max-time 60 \
|
||||||
|
-H "Authorization: Bearer $FORGEJO_TOKEN" "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
input_tag="${INPUT_TAG:-}"
|
input_tag="${INPUT_TAG:-}"
|
||||||
if [ -n "$input_tag" ]; then
|
if [ -n "$input_tag" ]; then
|
||||||
code=$(api_curl -o /tmp/tag.json -w '%{http_code}' \
|
code=$(api_curl -o /tmp/tag.json -w '%{http_code}' \
|
||||||
-H "Authorization: Bearer $FORGEJO_TOKEN" \
|
|
||||||
"$REPO_API/tags/$input_tag")
|
"$REPO_API/tags/$input_tag")
|
||||||
if [ "$code" != "200" ]; then
|
if [ "$code" != "200" ]; then
|
||||||
echo "dispatch tag $input_tag not found (HTTP $code)" >&2
|
echo "dispatch tag $input_tag not found (HTTP $code)" >&2
|
||||||
|
|
@ -86,8 +88,7 @@ jobs:
|
||||||
created=false
|
created=false
|
||||||
echo "re-publish existing tag $tag at $sha (dry_run=$dry_run)"
|
echo "re-publish existing tag $tag at $sha (dry_run=$dry_run)"
|
||||||
else
|
else
|
||||||
api_curl -H "Authorization: Bearer $FORGEJO_TOKEN" \
|
api_curl "$REPO_API/tags?limit=50" -o /tmp/tags.json
|
||||||
"$REPO_API/tags?limit=50" -o /tmp/tags.json
|
|
||||||
tag=$(python3 -c "import json,re; tags=json.load(open('/tmp/tags.json')); assert isinstance(tags, list), tags; semver=[]; [semver.append((int(m[1]), int(m[2]), int(m[3]))) for t in tags for m in [re.fullmatch(r'v([0-9]+)\.([0-9]+)\.([0-9]+)', t.get('name') or '')] if m]; print('v0.1.0' if not semver else 'v%d.%d.%d' % (max(semver)[0], max(semver)[1], max(semver)[2] + 1))")
|
tag=$(python3 -c "import json,re; tags=json.load(open('/tmp/tags.json')); assert isinstance(tags, list), tags; semver=[]; [semver.append((int(m[1]), int(m[2]), int(m[3]))) for t in tags for m in [re.fullmatch(r'v([0-9]+)\.([0-9]+)\.([0-9]+)', t.get('name') or '')] if m]; print('v0.1.0' if not semver else 'v%d.%d.%d' % (max(semver)[0], max(semver)[1], max(semver)[2] + 1))")
|
||||||
sha="$EVENT_SHA"
|
sha="$EVENT_SHA"
|
||||||
created=false
|
created=false
|
||||||
|
|
@ -95,7 +96,6 @@ jobs:
|
||||||
echo "dry_run: would use $tag on $sha (no tag created)"
|
echo "dry_run: would use $tag on $sha (no tag created)"
|
||||||
else
|
else
|
||||||
code=$(api_curl -o /tmp/tag.json -w '%{http_code}' \
|
code=$(api_curl -o /tmp/tag.json -w '%{http_code}' \
|
||||||
-H "Authorization: Bearer $FORGEJO_TOKEN" \
|
|
||||||
"$REPO_API/tags/$tag")
|
"$REPO_API/tags/$tag")
|
||||||
if [ "$code" = "200" ]; then
|
if [ "$code" = "200" ]; then
|
||||||
existing=$(python3 -c "import json; print(json.load(open('/tmp/tag.json'))['commit']['sha'])")
|
existing=$(python3 -c "import json; print(json.load(open('/tmp/tag.json'))['commit']['sha'])")
|
||||||
|
|
@ -107,10 +107,10 @@ jobs:
|
||||||
elif [ "$code" = "404" ]; then
|
elif [ "$code" = "404" ]; then
|
||||||
python3 -c "import json,sys; json.dump({'tag_name':sys.argv[1],'target':sys.argv[2],'message':'OnionWire '+sys.argv[1]}, sys.stdout)" \
|
python3 -c "import json,sys; json.dump({'tag_name':sys.argv[1],'target':sys.argv[2],'message':'OnionWire '+sys.argv[1]}, sys.stdout)" \
|
||||||
"$tag" "$sha" > /tmp/tag-create.json
|
"$tag" "$sha" > /tmp/tag-create.json
|
||||||
|
echo "tag-create payload $(wc -c < /tmp/tag-create.json) bytes"
|
||||||
create_code=$(api_curl -o /tmp/tag-created.json -w '%{http_code}' \
|
create_code=$(api_curl -o /tmp/tag-created.json -w '%{http_code}' \
|
||||||
-X POST -H "Authorization: Bearer $FORGEJO_TOKEN" \
|
-X POST -H "Content-Type: application/json" \
|
||||||
-H "Content-Type: application/json" \
|
--data-binary @/tmp/tag-create.json \
|
||||||
--data @/tmp/tag-create.json \
|
|
||||||
"$REPO_API/tags")
|
"$REPO_API/tags")
|
||||||
if [ "$create_code" = "201" ]; then
|
if [ "$create_code" = "201" ]; then
|
||||||
created=true
|
created=true
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue