Skip to content

Commit ffcdbf5

Browse files
committed
ci: update ci config
1 parent 5c0621c commit ffcdbf5

File tree

5 files changed

+147
-83
lines changed

5 files changed

+147
-83
lines changed

.github/workflows/ci.yml

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,40 @@
11
---
22
name: CI
33

4+
permissions: {}
5+
46
on:
57
push:
8+
branches:
9+
- '**'
610
paths-ignore:
711
- "**.md"
812
pull_request:
13+
branches:
14+
- '**'
915
paths-ignore:
1016
- "**.md"
1117
schedule:
12-
- cron: '0 6 * * 1' # Every monday 6 AM
18+
- cron: '0 4 1 * *'
19+
# Run workflow manually
20+
workflow_dispatch:
1321

1422
jobs:
1523
test:
1624
strategy:
1725
fail-fast: false
1826
matrix:
1927
os:
20-
- ubuntu-20.04
21-
- macos-11
28+
- ubuntu-latest
29+
- ubuntu-24.04-arm
30+
- macos-latest
31+
- macos-26-intel
2232

2333
runs-on: ${{ matrix.os }}
2434

2535
steps:
26-
- name: Checkout
27-
uses: actions/checkout@v2
28-
29-
- name: Install asdf plugin tester
30-
uses: asdf-vm/actions/plugin-test@v1
36+
- name: Test plugin
37+
uses: asdf-vm/actions/plugin-test@v3
3138
with:
3239
command: squarectl --version
3340
env:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![CI](https://github.com/jbox-web/asdf-squarectl/workflows/CI/badge.svg)](https://github.com/jbox-web/asdf-squarectl/actions)
44

5-
A plugin for the [asdf version manager](https://asdf-vm.com/) to install [Stacker](https://github.com/jbox-web/squarectl)
5+
A plugin for the [asdf version manager](https://asdf-vm.com/) to install [squarectl](https://github.com/jbox-web/squarectl)
66

77
## Install
88

bin/install

Lines changed: 13 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,22 @@
11
#!/usr/bin/env bash
22

3-
set -e
3+
# See: https://kvz.io/bash-best-practices.html
4+
set -o errexit
5+
set -o nounset
46
set -o pipefail
57

6-
github_coordinates="jbox-web/squarectl"
7-
tool_name="squarectl"
8+
current_script_path=${BASH_SOURCE[0]}
9+
plugin_dir=$(dirname "$(dirname "${current_script_path}")")
810

9-
install_tool() {
10-
local version=${2}
11-
local install_path=${3}
12-
local tmp_download_dir=${4}
13-
local binary_name=${5}
11+
# shellcheck source=./lib/utils.sh
12+
source "${plugin_dir}/lib/utils.sh"
1413

15-
local bin_install_path="${install_path}/bin"
16-
local binary_path="${bin_install_path}/${binary_name}"
17-
local platform
18-
local download_url
19-
local download_path
14+
########
15+
# MAIN #
16+
########
2017

21-
platform=$(get_platform)
22-
download_url=$(get_download_url "${version}" "${platform}" "${binary_name}")
23-
download_path="${tmp_download_dir}/"$(get_filename "${version}" "${platform}" "${binary_name}")
18+
TMP_DOWNLOAD_DIR="$(mktemp -d -t \"asdf_${TOOL_NAME}_XXXXXXXX\")"
2419

25-
echo "Downloading [${binary_name}] from ${download_url} to ${download_path}"
26-
curl -Lo "${download_path}" "${download_url}"
20+
trap 'rm -rf "${TMP_DOWNLOAD_DIR}"' EXIT
2721

28-
echo "Creating bin directory"
29-
mkdir -p "${bin_install_path}"
30-
31-
echo "Cleaning previous binaries"
32-
rm -f "${binary_path}" 2>/dev/null || true
33-
34-
echo "Copying binary"
35-
cp "${download_path}" "${binary_path}"
36-
chmod +x "${binary_path}"
37-
}
38-
39-
get_platform() {
40-
if [[ "$(uname)" == "Linux" ]]; then
41-
echo "linux-amd64"
42-
else
43-
echo "darwin-amd64"
44-
fi
45-
}
46-
47-
get_filename() {
48-
local version="${1}"
49-
local platform="${2}"
50-
local binary_name="${3}"
51-
52-
echo "${binary_name}-${platform}"
53-
}
54-
55-
get_download_url() {
56-
local version="${1}"
57-
local platform="${2}"
58-
local binary_name="${3}"
59-
local filename
60-
filename="$(get_filename "${version}" "${platform}" "${binary_name}")"
61-
62-
echo "https://github.com/${github_coordinates}/releases/download/v${version}/${filename}"
63-
}
64-
65-
tmp_download_dir="$(mktemp -d -t 'asdf_XXXXXXXX')"
66-
trap 'rm -rf "${tmp_download_dir}"' EXIT
67-
install_tool "${ASDF_INSTALL_TYPE}" "${ASDF_INSTALL_VERSION}" "${ASDF_INSTALL_PATH}" "${tmp_download_dir}" "${tool_name}"
22+
install_tool "${ASDF_INSTALL_TYPE}" "${ASDF_INSTALL_VERSION}" "${ASDF_INSTALL_PATH}" "${TMP_DOWNLOAD_DIR}" "${TOOL_NAME}"

bin/list-all

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,18 @@
11
#!/usr/bin/env bash
22

3-
set -e
3+
# See: https://kvz.io/bash-best-practices.html
4+
set -o errexit
5+
set -o nounset
46
set -o pipefail
57

6-
github_coordinates="jbox-web/squarectl"
7-
releases_path="https://api.github.com/repos/${github_coordinates}/releases"
8+
current_script_path=${BASH_SOURCE[0]}
9+
plugin_dir=$(dirname "$(dirname "${current_script_path}")")
810

9-
cmd="curl -s"
10-
if [ -n "$GITHUB_API_TOKEN" ]; then
11-
cmd="$cmd -H 'Authorization: token $GITHUB_API_TOKEN'"
12-
fi
13-
cmd="$cmd $releases_path"
11+
# shellcheck source=./lib/utils.sh
12+
source "${plugin_dir}/lib/utils.sh"
1413

15-
# stolen from https://github.com/rbenv/ruby-build/pull/631/files#diff-fdcfb8a18714b33b07529b7d02b54f1dR942
16-
function sort_versions() {
17-
sed 'h; s/[+-]/./g; s/.p\([[:digit:]]\)/.z\1/; s/$/.z/; G; s/\n/ /' | \
18-
LC_ALL=C sort -t. -k 1,1 -k 2,2n -k 3,3n -k 4,4n -k 5,5n | awk '{print $2}'
19-
}
14+
########
15+
# MAIN #
16+
########
2017

21-
# Fetch all tag names, and get only second column. Then remove all unnecesary characters.
22-
versions=$(eval $cmd | grep -oE "tag_name\": *\".{1,15}\"," | sed 's/tag_name\": *\"v//;s/\",//' | sort_versions)
23-
echo "$versions"
18+
list_all_versions

lib/utils.sh

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
TOOL_NAME="squarectl"
2+
GITHUB_COORDINATES="jbox-web/${TOOL_NAME}"
3+
4+
function install_tool() {
5+
local version=${2}
6+
local install_path=${3}
7+
local tmp_download_dir=${4}
8+
local binary_name=${5}
9+
10+
local bin_install_path="${install_path}/bin"
11+
local binary_path="${bin_install_path}/${binary_name}"
12+
13+
local platform
14+
local architecture
15+
local download_url
16+
local download_path
17+
18+
platform="$(get_platform)"
19+
architecture="$(get_architecture)"
20+
filename=$(get_filename "${version}" "${platform}" "${architecture}" "${binary_name}")
21+
download_url=$(get_download_url "${version}" "${platform}" "${architecture}" "${binary_name}")
22+
download_path="${tmp_download_dir}/${filename}"
23+
24+
echo "Downloading [${binary_name}] (from ${download_url} to ${download_path})"
25+
curl -Lo "${download_path}" "${download_url}"
26+
27+
echo "Creating bin directory (${bin_install_path})"
28+
mkdir -p "${bin_install_path}"
29+
30+
echo "Cleaning previous binaries (${binary_path})"
31+
rm -f "${binary_path}" 2>/dev/null || true
32+
33+
echo "Copying binary"
34+
cp "${download_path}" "${binary_path}"
35+
chmod +x "${binary_path}"
36+
}
37+
38+
function get_filename() {
39+
local version="${1}"
40+
local platform="${2}"
41+
local architecture="${3}"
42+
local binary_name="${4}"
43+
44+
echo "${binary_name}-${platform}-${architecture}"
45+
}
46+
47+
function get_download_url() {
48+
local version="${1}"
49+
local platform="${2}"
50+
local architecture="${3}"
51+
local binary_name="${4}"
52+
53+
local filename
54+
filename="$(get_filename "${version}" "${platform}" "${architecture}" "${binary_name}")"
55+
56+
echo "https://github.com/${GITHUB_COORDINATES}/releases/download/v${version}/${filename}"
57+
}
58+
59+
function get_platform() {
60+
local platform
61+
62+
case "${OSTYPE}" in
63+
darwin*) platform="darwin" ;;
64+
linux*) platform="linux" ;;
65+
*) fail "Unsupported platform" ;;
66+
esac
67+
68+
echo "${platform}"
69+
}
70+
71+
function get_architecture() {
72+
local architecture
73+
architecture="$(uname -m)"
74+
75+
case "${architecture}" in
76+
x86_64) architecture="amd64" ;;
77+
aarch64) architecture="arm64" ;;
78+
arm64) architecture="arm64" ;;
79+
*) fail "Unsupported architecture" ;;
80+
esac
81+
82+
echo "${architecture}"
83+
}
84+
85+
# stolen from https://github.com/rbenv/ruby-build/pull/631/files#diff-fdcfb8a18714b33b07529b7d02b54f1dR942
86+
function sort_versions() {
87+
sed 'h; s/[+-]/./g; s/.p\([[:digit:]]\)/.z\1/; s/$/.z/; G; s/\n/ /' | \
88+
LC_ALL=C sort -t. -k 1,1 -k 2,2n -k 3,3n -k 4,4n -k 5,5n | awk '{print $2}'
89+
}
90+
91+
function list_all_versions() {
92+
local releases_path
93+
releases_path="https://api.github.com/repos/${GITHUB_COORDINATES}/releases"
94+
95+
local cmd
96+
cmd="curl -s"
97+
98+
if [ -n "${GITHUB_API_TOKEN:-}" ]; then
99+
cmd="${cmd} -H 'Authorization: token ${GITHUB_API_TOKEN}'"
100+
fi
101+
102+
cmd="${cmd} ${releases_path}"
103+
104+
# Fetch all tag names, and get only second column. Then remove all unnecesary characters.
105+
versions=$(eval ${cmd} | grep -oE "tag_name\": *\".{1,15}\"," | sed 's/tag_name\": *\"v//;s/\",//' | sort_versions)
106+
echo "${versions}"
107+
}

0 commit comments

Comments
 (0)