Skip to content

Commit ee783ac

Browse files
committed
ci: add deploy config
1 parent 58a549b commit ee783ac

File tree

3 files changed

+145
-0
lines changed

3 files changed

+145
-0
lines changed

.github/release-body.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
## 📝 Source code
2+
3+
Streamlink's git repository and issue tracker can be found at [streamlink/streamlink](https://github.com/streamlink/streamlink).
4+
Before continuing, please read the [changelog of this release](https://streamlink.github.io/changelog.html).
5+
6+
## 📦 Installer contents
7+
8+
- an embedded Python environment
9+
- Streamlink and its dependencies
10+
- FFmpeg, for muxing streams
11+
12+
Users of Windows 7 need to choose the installers based on Python 3.8.
13+
For more information, please see Streamlink's [install docs](https://streamlink.github.io/install.html#windows-binaries).
14+
15+
## ⚙️ How to use
16+
17+
See the detailed [CLI guide](https://streamlink.github.io/cli.html) on Streamlink's website.
18+
19+
## ❤️ Support
20+
21+
If you think that Streamlink is useful and if you want to keep the project alive, then please consider supporting its maintainers by sending a small and optionally recurring tip via the [available options](https://streamlink.github.io/donate.html).
22+
Your support is very much appreciated, thank you!

.github/workflows/main.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,20 @@ jobs:
3939
with:
4040
name: ${{ steps.vars.outputs.installer_name }}
4141
path: dist/*.exe
42+
43+
deploy:
44+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
45+
needs:
46+
- build
47+
runs-on: ubuntu-latest
48+
permissions:
49+
contents: write
50+
steps:
51+
- uses: actions/checkout@v3
52+
- run: mkdir dist
53+
- uses: actions/download-artifact@v3
54+
with:
55+
path: ./dist
56+
- run: ./deploy.sh ./dist/**/*.exe
57+
env:
58+
RELEASES_API_KEY: ${{ secrets.GITHUB_TOKEN }}

deploy.sh

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
#!/usr/bin/env bash
2+
set -eo pipefail
3+
4+
[[ "${CI}" ]] && [[ "${GITHUB_REPOSITORY}" ]] && [[ "${GITHUB_REF}" =~ ^refs/tags/ ]] && [[ "${RELEASES_API_KEY}" ]] || exit 1
5+
6+
ROOT=$(git rev-parse --show-toplevel 2>/dev/null || dirname "$(readlink -f "${0}")")
7+
FILES=("${@}")
8+
9+
declare -A DEPS=(
10+
[curl]=curl
11+
[jq]=jq
12+
)
13+
14+
# ----
15+
16+
SELF=$(basename "$(readlink -f "${0}")")
17+
log() {
18+
echo "[${SELF}] $@"
19+
}
20+
err() {
21+
log >&2 "$@"
22+
exit 1
23+
}
24+
25+
for dep in "${!DEPS[@]}"; do
26+
command -v "${dep}" 2>&1 >/dev/null || err "Missing dependency: ${DEPS["${dep}"]}"
27+
done
28+
29+
[[ $# == 0 ]] && err "Missing file(s)"
30+
31+
# ----
32+
33+
TAG="${GITHUB_REF/#refs\/tags\//}"
34+
CURL_OPTIONS=(
35+
-H "Accept: application/vnd.github.v3+json"
36+
-H "User-Agent: ${GITHUB_REPOSITORY}"
37+
-H "Authorization: token ${RELEASES_API_KEY}"
38+
)
39+
GH_API="https://api.github.com/repos/${GITHUB_REPOSITORY}"
40+
GH_UPLOAD="https://uploads.github.com/repos/${GITHUB_REPOSITORY}"
41+
BODY="${ROOT}/.github/release-body.md"
42+
43+
44+
get_release_id() {
45+
curl -fsSL \
46+
-X GET \
47+
"${CURL_OPTIONS[@]}" \
48+
"${GH_API}/releases/tags/${TAG}" \
49+
| jq -re ".id"
50+
}
51+
52+
create_release() {
53+
local data="$(jq -cnR \
54+
--arg tag_name "${TAG}" \
55+
--arg name "${GITHUB_REPOSITORY} ${TAG}" \
56+
--arg body "$(cat "${BODY}")" \
57+
'{
58+
"tag_name": $tag_name,
59+
"name": $name,
60+
"body": $body
61+
}'
62+
)"
63+
curl -fsSL \
64+
-X POST \
65+
"${CURL_OPTIONS[@]}" \
66+
-d "${data}" \
67+
"${GH_API}/releases" \
68+
| jq -re ".id"
69+
}
70+
71+
upload_assets() {
72+
local release_id="${1}"
73+
for path in "${FILES[@]}"; do
74+
local file=$(basename "${path}")
75+
log "Uploading ${file}"
76+
sha256sum "${path}"
77+
curl -fsSL \
78+
-X POST \
79+
"${CURL_OPTIONS[@]}" \
80+
-H "Content-Type: application/octet-stream" \
81+
--data-binary "@${path}" \
82+
"${GH_UPLOAD}/releases/${release_id}/assets?name=${file}" \
83+
>/dev/null
84+
done
85+
}
86+
87+
deploy() {
88+
log "Getting release ID for tag ${TAG}"
89+
local release_id=$(get_release_id 2>/dev/null || true)
90+
91+
if [[ -z "${release_id}" ]]; then
92+
log "Creating new release for tag ${TAG}"
93+
local release_id=$(create_release)
94+
fi
95+
96+
if [[ -z "${release_id}" ]]; then
97+
err "Missing release ID"
98+
fi
99+
100+
log "Uploading assets to release ${release_id}"
101+
upload_assets "${release_id}"
102+
103+
log "Done"
104+
}
105+
106+
deploy

0 commit comments

Comments
 (0)