Skip to content

Commit

Permalink
[skip ci] Implement URL shorter
Browse files Browse the repository at this point in the history
  • Loading branch information
greymd committed Jun 7, 2020
1 parent 4d751f5 commit 4e7f1f4
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 4 deletions.
39 changes: 39 additions & 0 deletions .github/gitio_shorter.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash
set -eu

is_registerable() {
local _code="$1"
local _res_code
_res_code="$(curl --retry 3 -s -o /dev/null -w "%{http_code}" "https://git.io/${_code}")"
if [[ "$_res_code" == 302 ]];then
echo "code ${_code} is NOT registerable" >&2
return 1
else
echo "code ${_code} is registerable" >&2
return 0
fi
}

shorten() {
local _url="$1"
local _code="$2"
local _res_code
_res_code="$(curl --retry 3 -s -o /dev/null -w "%{http_code}" -F "url=${_url}" -F "code=${_code}" "https://git.io")"
if [[ "$_res_code" == 201 ]];then
echo "Succeed to register ${_code}, yay" >&2
return 0
else
echo "Failed to register ${_code} .." >&2
return 1
fi
}

main() {
local _url="$1"
local _code="$2"
is_registerable "$_code" \
&& shorten "$_url" "$_code" \
&& echo "https://git.io/$_code"
}

main ${1+"$@"}
16 changes: 12 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,21 +135,29 @@ jobs:
name: rpm.x86_64
- shell: bash
run: |
_url="https://github.com/greymd/teip/releases/download/v${{ steps.vars.outputs.ver }}/$(head -n 1 rpm.x86_64/digest.txt)"
_shorter=./.github/gitio_shorter.sh
_ver=${{ steps.vars.outputs.ver }}
_url="https://github.com/greymd/teip/releases/download/v${_ver}/$(head -n 1 rpm.x86_64/digest.txt)"
_sha=$(tail -n 1 rpm.x86_64/digest.txt)
sed -i "/rpm_x86_64_start/,/rpm_x86_64_end/s|https://.*rpm|$_url|g" ./README.md
_short_url=$($_shorter "${_url}" "teip-${_ver}.x86_64.rpm" || $_shorter "${_url}" "teip-${_ver}-${_sha:1:5}.x86_64.rpm" || echo "${_url}")
sed -i "/rpm_x86_64_start/,/rpm_x86_64_end/s|https://.*rpm|$_short_url|g" ./README.md
sed -i "/rpm_x86_64_sha256/s/SHA256:.*/SHA256: $_sha/" ./README.md
cat ./README.md
- name: Apply artifacts deb
uses: actions/download-artifact@v1
with:
name: deb.x86_64
- shell: bash
run: |
_url="https://github.com/greymd/teip/releases/download/v${{ steps.vars.outputs.ver }}/$(head -n 1 deb.x86_64/digest.txt)"
_shorter=./.github/gitio_shorter.sh
_ver=${{ steps.vars.outputs.ver }}
_url="https://github.com/greymd/teip/releases/download/v${_ver}/$(head -n 1 deb.x86_64/digest.txt)"
_sha=$(tail -n 1 deb.x86_64/digest.txt)
sed -i "/deb_x86_64_start/,/deb_x86_64_end/s|https://.*deb|$_url|g" ./README.md
_short_url=$($_shorter "${_url}" "teip-${_ver}.x86_64.deb" || $_shorter "${_url}" "teip-${_ver}-${_sha:1:5}.x86_64.deb" || echo "${_url}")
sed -i "/deb_x86_64_start/,/deb_x86_64_end/s|https://.*deb|$_short_url|g" ./README.md
sed -i "/deb_x86_64_sha256/s/SHA256:.*/SHA256: $_sha/" ./README.md
cat ./README.md
- name: Release README
if: "! contains (steps.vars.outputs.ver, 'beta')"
Expand Down

0 comments on commit 4e7f1f4

Please sign in to comment.