Skip to content

Commit

Permalink
release workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
sarumaj committed Nov 23, 2022
1 parent d7ed878 commit d27784a
Show file tree
Hide file tree
Showing 5 changed files with 503 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ dmypy.json
.pyre/

# buildozer
.buildozer/**/platform/build*/**
.buildozer

*.profile
*.dat
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ debug:
release:
buildozer -v android release

publish: release debug
publish: release
$(shell ./publish.sh)

adb-run-debug: debug
Expand Down
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-


__version__ = "1.0.1"
__version__ = "1.0.2b"


def main():
Expand Down
70 changes: 70 additions & 0 deletions publish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/usr/bin/env bash

GH_REPO_USER=sarumaj
GH_REPO=MyCampusMobile
GH_USER=sarumaj
GH_TOKEN=$(git config --global --list | grep url | sed -E 's|.*:(.*)@.*|\1|g')
GH_TARGET=main
ASSETS_PATH=bin
VERSION=$(cat main.py | grep '__version__ = ' | sed -rE 's|.*"([0-9]+\.[0-9]+\.[0-9]+\w?)".*|\1|g')

if [[ ! -z $(git tag --list $VERSION) ]]
then
git add -u
git commit -m "$VERSION release" --no-verify
git tag "v${VERSION}"
git push --follow-tags
git push origin "v${VERSION}"
fi

rel_id=$(
curl \
--silent --user "$GH_USER:$GH_TOKEN" \
-X GET https://api.github.com/repos/${GH_REPO_USER}/${GH_REPO}/releases/tags/v${VERSION} \
| jq -r '.id'
)
echo Found release ${rel_id}

if [[ $rel_id -eq null ]]
then
echo Creating release
response=$(
curl \
--silent --user "$GH_USER:$GH_TOKEN" \
-X POST https://api.github.com/repos/${GH_REPO_USER}/${GH_REPO}/releases \
--data '{
"tag_name": "v'$VERSION'",
"target_commitish": "'$GH_TARGET'",
"name": "v'$VERSION'",
"body": "version release: '$VERSION'",
"draft": false,
"prerelease": false
}')
rel_id=$( jq -r '.id' <<<$response)
else
echo Updating release ${release_id}
response=$(
curl \
--silent --user "$GH_USER:$GH_TOKEN" \
-X PATCH https://api.github.com/repos/${GH_REPO_USER}/${GH_REPO}/releases/$rel_id \
--data '{
"tag_name": "v'$VERSION'",
"target_commitish": "'$GH_TARGET'",
"name": "v'$VERSION'",
"body": "version release: '$VERSION'",
"draft": false,
"prerelease": false
}')
fi
echo Result: ${response}


for i in $ASSETS_PATH/* ; do
file_name=$(basename $i)
echo uploading ${file_name}
curl \
--user "$GH_USER:$GH_TOKEN" \
-X POST https://uploads.github.com/repos/${GH_REPO_USER}/${GH_REPO}/releases/${rel_id}/assets?name=${file_name} \
--header 'Content-Type: application/octet-stream' \
--upload-file "./${ASSETS_PATH}/${file_name}" 2>&1 >/dev/null
done
Loading

0 comments on commit d27784a

Please sign in to comment.