Skip to content

Commit ae61b42

Browse files
committed
Upload github assets
1 parent dcf858a commit ae61b42

File tree

3 files changed

+94
-2
lines changed

3 files changed

+94
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ scripts/build-config-custom.js
99
scripts/build-config-*.js
1010
kitchen-sink/vue/js/app.js
1111
kitchen-sink/react/js/app.js
12+
.github-access-token

scripts/release-asset.sh

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Author: Stefan Buck
4+
# License: MIT
5+
# https://gist.github.com/stefanbuck/ce788fee19ab6eb0b4447a85fc99f447
6+
#
7+
#
8+
# This script accepts the following parameters:
9+
#
10+
# * tag
11+
# * filename
12+
# * github_api_token
13+
#
14+
# Script to upload a release asset using the GitHub API v3.
15+
#
16+
# Example:
17+
#
18+
# upload-github-release-asset.sh github_api_token=TOKEN owner=stefanbuck repo=playground tag=v0.1.0 filename=./build.zip
19+
#
20+
21+
# Check dependencies.
22+
set -e
23+
xargs=$(which gxargs || which xargs)
24+
25+
# Validate settings.
26+
[ "$TRACE" ] && set -x
27+
28+
CONFIG=$@
29+
30+
for line in $CONFIG; do
31+
eval "$line"
32+
done
33+
34+
# Define variables.
35+
GH_API="https://api.github.com"
36+
GH_REPO="$GH_API/repos/framework7io/framework7"
37+
GH_TAGS="$GH_REPO/releases/tags/$tag"
38+
AUTH="Authorization: token $github_api_token"
39+
WGET_ARGS="--content-disposition --auth-no-challenge --no-cookie"
40+
CURL_ARGS="-LJO#"
41+
42+
if [[ "$tag" == 'LATEST' ]]; then
43+
GH_TAGS="$GH_REPO/releases/latest"
44+
fi
45+
46+
# Validate token.
47+
curl -o /dev/null -sH "$AUTH" $GH_REPO || { echo "Error: Invalid repo, token or network issue!"; exit 1; }
48+
49+
# Read asset tags.
50+
response=$(curl -sH "$AUTH" $GH_TAGS)
51+
52+
# Get ID of the asset based on given filename.
53+
eval $(echo "$response" | grep -m 1 "id.:" | grep -w id | tr : = | tr -cd '[[:alnum:]]=')
54+
[ "$id" ] || { echo "Error: Failed to get release id for tag: $tag"; echo "$response" | awk 'length($0)<100' >&2; exit 1; }
55+
56+
# Upload asset
57+
echo "Uploading asset... "
58+
59+
# Construct url
60+
GH_ASSET="https://uploads.github.com/repos/framework7io/framework7/releases/$id/assets?name=$(basename $filename)"
61+
62+
curl "$GITHUB_OAUTH_BASIC" --data-binary @"$filename" -H "Authorization: token $github_api_token" -H "Content-Type: application/octet-stream" $GH_ASSET

scripts/release.sh

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,40 @@ if [[ $REPLY =~ ^[Yy]$ ]]; then
6262

6363
# commit
6464
git add -A
65-
git add -f \
66-
packages/**/*.*
65+
git add -f packages/**/*.*
6766
git commit -m "$VERSION Release"
6867

6968
# publish
7069
git push origin refs/tags/v"$VERSION"
7170
git push
71+
72+
# Create assets
73+
(
74+
(
75+
cd packages/core
76+
tar -zcvf ../framework7.tar.gz ./*
77+
zip -r ../framework7.zip ./*
78+
)
79+
(
80+
cd packages/react
81+
tar -zcvf ../framework7-react.tar.gz ./*
82+
zip -r ../framework7-react.zip ./*
83+
)
84+
(
85+
cd packages/vue
86+
tar -zcvf ../framework7-vue.tar.gz ./*
87+
zip -r ../framework7-vue.zip ./*
88+
)
89+
)
90+
91+
# Read TOKEN
92+
token=$(<./.github-access-token)
93+
94+
# Upload assets
95+
source "scripts/release-asset.sh" github_api_token=$token tag=v$VERSION filename=../packages/framework7.tar.gz
96+
source "scripts/release-asset.sh" github_api_token=$token tag=v$VERSION filename=../packages/framework7.zip
97+
source "scripts/release-asset.sh" github_api_token=$token tag=v$VERSION filename=../packages/framework7-react.tar.gz
98+
source "scripts/release-asset.sh" github_api_token=$token tag=v$VERSION filename=../packages/framework7-react.zip
99+
source "scripts/release-asset.sh" github_api_token=$token tag=v$VERSION filename=../packages/framework7-vue.tar.gz
100+
source "scripts/release-asset.sh" github_api_token=$token tag=v$VERSION filename=../packages/framework7-vue.zip
72101
fi

0 commit comments

Comments
 (0)