Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build(action): support github actions #9

Merged
merged 1 commit into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@ builds:
goos:
- linux
- darwin
- freebsd
goarch:
- amd64
- arm64

archives:
- format: zip
name_template: "{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}"
- format: tar.gz
format_overrides:
- goos: darwin
format: zip
name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
files:
- README.md
- LICENSE
Expand Down
10 changes: 10 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: zgsync
description: setup zgsync
runs:
using: "composite"
steps:
- name: setup zgsync
shell: bash
run: |
cd "${GITHUB_WORKSPACE}" || exit 1
/bin/bash -c "$(curl -fsfL https://raw.githubusercontent.com/tukaelu/zgsync/master/install.sh)
115 changes: 115 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#!/usr/bin/env bash

set -Eeuo pipefail

BINDIR="${BINDIR:-/usr/local/bin}"

REPO_OWNER="tukaelu"
PROG_NAME="zgsync"

if ! \curl --version >/dev/null 2>&1; then
echo "curl command is required to install ${PROG_NAME}" 2>&1
echo "Please install curl and try again." 2>&1
exit 1
fi

get_goos() {
os=$(uname -s)
case $os in
"Linux")
echo "linux"
;;
"Darwin")
echo "darwin"
;;
"FreeBSD")
echo "freebsd"
;;
*)
echo "unsupported OS: ${os}"
exit 1
;;
esac
}

get_goarch() {
arch=$(uname -m)
case $arch in
"amd64" | "x86_64")
echo "amd64"
;;
"arm64" | "aarch64")
echo "arm64"
;;
*)
echo "unsupported arch: ${arch}"
exit 1
;;
esac
}

get_latest_version() {
version=$(
curl -fsSL https://api.github.com/repos/${REPO_OWNER}/${PROG_NAME}/releases/latest |
grep tag_name |
cut -d: -f2-3 |
sed -e 's/["v, ]//g'
)
echo "${version}"
}

get_ext() {
case $goos in
"linux" | "freebsd")
echo ".tar.gz"
;;
"darwin")
echo ".zip"
;;
*)
echo "unsupported OS: ${os}"
exit 1
;;
esac
}

do_extract() {
local path=$1
local fname=$2
local ext=$3
case ${ext} in
".tar.gz")
tar -C "${path}" -xzf "${path}/${fname}"
;;
".zip")
unzip -d "${path}" "${path}/${fname}"
;;
*)
echo "unsupported ext: ${ext}"
exit 1
;;
esac
}

goos=$(get_goos)
goarch=$(get_goarch)
ext=$(get_ext)
latest_version=$(get_latest_version)

fname="${PROG_NAME}_${latest_version}_${goos}_${goarch}${ext}"
release_url="https://github.com/${REPO_OWNER}/${PROG_NAME}/releases/download/v${latest_version}/${fname}"

tmpdir=$(mktemp -d)

echo "Downloading ${fname} from ${release_url} ... "
curl -fSL -o "${tmpdir}/${fname}" "${release_url}"
echo "done."

echo -n "Extracting ... "
do_extract "${tmpdir}" "${fname}" "${ext}"
echo "done."

echo -n "Installing ... "
mv "${tmpdir}/${PROG_NAME}" "${BINDIR}/${PROG_NAME}"
chmod +x "${BINDIR}/${PROG_NAME}"
echo "done."