Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1577 from advancedtelematic/ci/robust-rls
Browse files Browse the repository at this point in the history
Fix some edge cases in the release scripts
  • Loading branch information
lbonn committed Feb 28, 2020
2 parents 9f2cc5d + 69c07d8 commit 9239f06
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 34 deletions.
6 changes: 5 additions & 1 deletion scripts/publish_github_docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ fi
find . \( -regex './[^/]*' -and -type f -and -not -path ./.git \) -or \( -path './search/*' \) -exec git rm -r {} +
cp -ar "$DOX_DOCS/." .
git add .
gitcommit -m "Update docs to latest ($DESCRIBE)"
if git diff --cached --quiet; then
echo "Docs already updated to the latest version, skipping..."
else
gitcommit -m "Update docs to latest ($DESCRIBE)"
fi

if [ "$DRY_RUN" != 1 ]; then
git config credential.${GIT_REMOTE}.username "$GITHUB_API_USER"
Expand Down
85 changes: 52 additions & 33 deletions scripts/publish_github_rls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,25 @@
import os.path
import re
import sys
import time
import urllib.request


def urlopen_retry(req):
delay = 1
last_exc = Exception()
for k in range(5):
try:
return urllib.request.urlopen(req)
except urllib.error.HTTPError as e:
if e.code < 500:
raise
last_exc = e
time.sleep(delay)
delay *= 2
raise last_exc


def main():
if len(sys.argv) < 2:
print("usage: {} RLS_TAG [assets]".format(sys.argv[0]))
Expand All @@ -19,15 +35,19 @@ def main():
api_token = os.environ["GITHUB_API_TOKEN"]
files = sys.argv[2:]

req = urllib.request.Request("https://api.github.com/repos/advancedtelematic/aktualizr/releases/tags/{}".format(rls_tag), \
headers={
"Accept": "application/vnd.github.v3+json",
"Authorization": "token {}".format(api_token),
"Content-Type": "application/json"
}, method="GET"
)
req = urllib.request.Request(
"https://api.github.com/repos/advancedtelematic/aktualizr/releases/tags/{}".format(
rls_tag
),
headers={
"Accept": "application/vnd.github.v3+json",
"Authorization": "token {}".format(api_token),
"Content-Type": "application/json",
},
method="GET",
)
try:
with urllib.request.urlopen(req) as f:
with urlopen_retry(req) as f:
json.loads(f.read())
except urllib.error.HTTPError as e:
if e.code != 404:
Expand All @@ -37,21 +57,18 @@ def main():
return 0

# create release
c = {
"tag_name": rls_tag,
"name": rls_tag,
"body": "",
"draft": False
}
req = urllib.request.Request("https://api.github.com/repos/advancedtelematic/aktualizr/releases",
data=json.dumps(c).encode(),
headers={
"Accept": "application/vnd.github.v3+json",
"Authorization": "token {}".format(api_token),
"Content-Type": "application/json"
}, method="POST"
)
with urllib.request.urlopen(req) as f:
c = {"tag_name": rls_tag, "name": rls_tag, "body": "", "draft": False}
req = urllib.request.Request(
"https://api.github.com/repos/advancedtelematic/aktualizr/releases",
data=json.dumps(c).encode(),
headers={
"Accept": "application/vnd.github.v3+json",
"Authorization": "token {}".format(api_token),
"Content-Type": "application/json",
},
method="POST",
)
with urlopen_retry(req) as f:
resp = json.loads(f.read())

upload_url = re.sub("{.*}", "", resp["upload_url"])
Expand All @@ -60,16 +77,18 @@ def main():
bn = os.path.basename(fn)
url = upload_url + "?name={}".format(bn)
with open(fn, "rb") as f:
req = urllib.request.Request(url,
data=f,
headers={
"Accept": "application/vnd.github.v3+json",
"Authorization": "token {}".format(api_token),
"Content-Length": str(os.path.getsize(fn)),
"Content-Type": mimetypes.guess_type(bn)[0]
}, method="POST"
)
urllib.request.urlopen(req)
req = urllib.request.Request(
url,
data=f,
headers={
"Accept": "application/vnd.github.v3+json",
"Authorization": "token {}".format(api_token),
"Content-Length": str(os.path.getsize(fn)),
"Content-Type": mimetypes.guess_type(bn)[0],
},
method="POST",
)
urlopen_retry(req)

return 0

Expand Down

0 comments on commit 9239f06

Please sign in to comment.