Skip to content

Commit 5eb9be2

Browse files
committed
feat: use cookiecutter template
1 parent 2cfb104 commit 5eb9be2

File tree

6 files changed

+179
-51
lines changed

6 files changed

+179
-51
lines changed

.github/workflows/aio.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: AllInOne
2+
3+
on:
4+
push:
5+
paths-ignore:
6+
- '**.md'
7+
pull_request:
8+
paths-ignore:
9+
- '**.md'
10+
schedule:
11+
- cron: 0 0 * * 5
12+
13+
jobs:
14+
plugin_test:
15+
strategy:
16+
matrix:
17+
os:
18+
- macos-latest
19+
- ubuntu-latest
20+
runs-on: ${{ matrix.os }}
21+
steps:
22+
- name: asdf_plugin_test
23+
uses: asdf-vm/actions/plugin-test@v1
24+
with:
25+
command: terraform-docs --version
26+
27+
lint:
28+
runs-on: ubuntu-latest
29+
steps:
30+
- name: Checkout code
31+
uses: actions/checkout@v2
32+
- name: Run the sh-checker
33+
uses: luizm/action-sh-checker@v0.1.8
34+
env:
35+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36+
#SHELLCHECK_OPTS: -e SC1004 # Optional: exclude some shellcheck warnings.
37+
SHFMT_OPTS: -i 2 # Optional: pass arguments to shfmt.
38+
with:
39+
sh_checker_comment: true

.travis.yml

Lines changed: 0 additions & 15 deletions
This file was deleted.

README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
# asdf-terraform-docs
22

3-
[![Build Status](https://travis-ci.org/looztra/asdf-terraform-docs.svg?branch=master)](https://travis-ci.org/looztra/asdf-terraform-docs)
3+
![AllInOne](https://github.com/looztra/asdf-terraform-docs/workflows/AllInOne/badge.svg)
4+
[![GitHub license](https://img.shields.io/github/license/looztra/asdf-terraform-docs?style=plastic)](https://github.com/looztra/asdf-terraform-docs/blob/master/LICENSE)
45

5-
[terraform-docs](https://github.com/segmentio/terraform-docs/) plugin for the [asdf](https://github.com/asdf-vm/asdf) version manager.
6+
## Build History
7+
8+
[![Build history](https://buildstats.info/github/chart/looztra/asdf-terraform-docs?branch=master)](https://github.com/looztra/asdf-terraform-docs/actions)
9+
10+
## terraform-docs
11+
12+
<https://github.com/terraform-docs/terraform-docs>
613

714
## Install
815

@@ -13,3 +20,7 @@ asdf plugin-add terraform-docs https://github.com/looztra/asdf-terraform-docs
1320
## Use
1421

1522
Check out the [asdf](https://github.com/asdf-vm/asdf) readme for instructions on how to install and manage versions of terraform-docs.
23+
24+
## Source code
25+
26+
This source code has been generated with : `cookiecutter --overwrite-if-exists --directory plugins/terraform-docs --no-input https://github.com/looztra/cookiecutter-asdf-plugin`

bin/install

Lines changed: 124 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,70 +3,173 @@
33
set -e
44
set -o pipefail
55

6+
# https://github.com/terraform-docs/terraform-docs/releases/download/v0.6.0/terraform-docs-v0.6.0-linux-amd64
7+
# https://github.com/terraform-docs/terraform-docs/releases/download/v0.6.0/terraform-docs-v0.6.0-darwin-amd64
8+
9+
readonly NO_BINARY_ALTNAME=@@UNDEFINED@@
10+
readonly g_github_coordinates=terraform-docs/terraform-docs
11+
readonly g_binary_name=terraform-docs
12+
readonly g_binary_altname="$NO_BINARY_ALTNAME"
13+
#
14+
# __VERSION__/__VERSION_SHORT__/__BINARY_NAME__/__PLATFORM__
15+
#
16+
readonly g_filename_template=__BINARY_NAME__-__VERSION__-__PLATFORM__
17+
#
18+
# __GITHUB_COORDINATES__/__VERSION__/__VERSION_SHORT__/__FILENAME__
19+
#
20+
readonly g_download_url_template=https://github.com/__GITHUB_COORDINATES__/releases/download/__VERSION__/__FILENAME__
21+
#
22+
# __ARCHIVE_DIR__/__BINARY_NAME__/__VERSION__/__VERSION_SHORT__/__PLATFORM__
23+
#
24+
readonly g_binary_path_in_archive_template=__ARCHIVE_DIR__/__BINARY_NAME__-__VERSION__-__PLATFORM__
25+
readonly g_downloaded_file_is_not_an_archive=true
26+
readonly g_platform_pattern=uname_l_dash_amd64 # one of uname_c_x86_64|uname_l_dash_amd64|uname_l_underscore_amd64|custom
27+
28+
# Borrowed to someone, but I don't remember who it was, sorry :(
29+
# Print message $2 with log-level $1 to STDERR, colorized if terminal
30+
# log DEBUG "DOCKER_HOST ${DOCKER_HOST}"
31+
function log() {
32+
local level=${1?}
33+
shift
34+
local code
35+
local line
36+
code=''
37+
line="[$(date '+%F %T')] $level: $*"
38+
if [ -t 2 ]; then
39+
case "$level" in
40+
INFO) code=36 ;;
41+
DEBUG) code=35 ;;
42+
WARN) code=33 ;;
43+
ERROR) code=31 ;;
44+
*) code=37 ;;
45+
esac
46+
echo -e "\e[${code}m${line} \e[94m(${FUNCNAME[1]})\e[0m"
47+
else
48+
echo "$line"
49+
fi >&2
50+
}
51+
652
install_tool() {
7-
#local install_type=$1
53+
local install_type=$1
854
local version=$2
955
local install_path=$3
1056
local tmp_download_dir=$4
1157
local binary_name=$5
58+
local binary_alt_name=$6
59+
local downloaded_file_is_not_an_archive=$7
1260

1361
local platform
1462
local bin_install_path="$install_path/bin"
15-
local binary_path="$bin_install_path/${binary_name}"
63+
local full_path_to_binary="$bin_install_path/${binary_name}"
64+
local full_path_to_alt_binary
65+
if [[ -n "$binary_alt_name" || "$binary_alt_name" == "$NO_BINARY_ALTNAME" ]]; then
66+
full_path_to_alt_binary="$bin_install_path/${binary_alt_name}"
67+
fi
1668
local download_url
17-
local download_path
69+
local download_target_file
70+
local download_sub_path_dir
71+
72+
if [[ "$install_type" != "version" ]]; then
73+
log ERROR "Install of type [$install_type] not supported"
74+
fi
1875

1976
platform=$(get_platform)
2077
download_url=$(get_download_url "$version" "$platform" "$binary_name")
21-
download_path="$tmp_download_dir/"$(get_filename "$version" "$platform" "$binary_name")
78+
download_sub_path_dir=$tmp_download_dir/sub
79+
mkdir -p "$download_sub_path_dir"
80+
download_target_file="$download_sub_path_dir/"$(get_filename "$version" "$platform" "$binary_name")
2281

23-
echo "Downloading [${binary_name}] from ${download_url} to ${download_path}"
24-
curl -Lo "$download_path" "$download_url"
82+
log INFO "Downloading [${binary_name}] from ${download_url} to ${download_target_file}"
83+
curl --location --output "$download_target_file" "$download_url"
2584

26-
echo "Creating bin directory"
85+
log INFO "Creating bin directory [${bin_install_path}]"
2786
mkdir -p "${bin_install_path}"
2887

29-
echo "Cleaning previous binaries"
30-
rm -f "$binary_path" 2>/dev/null || true
88+
log INFO "Cleaning previous binaries if any"
89+
rm -f "$full_path_to_binary" 2>/dev/null || true
90+
if [[ -n "$binary_alt_name" ]]; then
91+
rm -f "$full_path_to_alt_binary" 2>/dev/null || true
92+
fi
93+
if [[ "$downloaded_file_is_not_an_archive" != "true" ]]; then
94+
log INFO "Extracting archive"
95+
tar xpf "$download_target_file" -C "$tmp_download_dir"
96+
else
97+
log INFO "Preparing downloaded file"
98+
cp "$download_target_file" "$tmp_download_dir"
99+
fi
100+
log INFO "Copying binaries"
101+
cp "$(get_binary_path_in_archive "${tmp_download_dir}" "${binary_name}" "${version}" "${platform}")" "${full_path_to_binary}"
102+
chmod +x "${full_path_to_binary}"
103+
if [[ -n "$binary_alt_name" ]]; then
104+
cp "${full_path_to_binary}" "${full_path_to_alt_binary}"
105+
chmod +x "${full_path_to_alt_binary}"
106+
fi
107+
}
31108

32-
echo "Copying binary"
33-
cp "$(get_binary_path_in_archive "${tmp_download_dir}" "${binary_name}" "${version}" "${platform}")" "${binary_path}"
34-
chmod +x "${binary_path}"
109+
get_version_short() {
110+
local version=$1
111+
echo "$version" | tr -d "v"
35112
}
36113

37114
get_binary_path_in_archive() {
38115
local archive_dir=$1
39116
local binary_name=$2
40117
local version=$3
41118
local platform=$4
119+
local version_short
120+
version_short=$(get_version_short "$version")
42121

43-
echo "${archive_dir}/${binary_name}-${version}-${platform}"
122+
echo $g_binary_path_in_archive_template |
123+
sed "s|__ARCHIVE_DIR__|${archive_dir}|g;s|__BINARY_NAME__|${binary_name}|g;s|__VERSION__|${version}|g;s|__VERSION_SHORT__|${version_short}|g;s|__PLATFORM__|${platform}|g;"
44124
}
45125

46126
get_platform() {
127+
get_platform_${g_platform_pattern}
128+
}
129+
130+
get_platform_custom() {
131+
echo "NOT USED"
132+
}
133+
134+
get_platform_uname_c_x86_64() {
135+
echo "$(uname)_x86_64"
136+
}
137+
138+
get_platform_uname_l_dash_amd64() {
47139
echo "$(uname | tr '[:upper:]' '[:lower:]')-amd64"
48140
}
49141

142+
get_platform_uname_l_underscore_amd64() {
143+
echo "$(uname | tr '[:upper:]' '[:lower:]')_amd64"
144+
}
145+
50146
get_filename() {
51-
#local version="$1"
147+
local version="$1"
52148
local platform="$2"
53149
local binary_name="$3"
150+
local version_short
151+
version_short=$(get_version_short "$version")
152+
# log DEBUG "version=${version}, version_short=${version_short}, binary_name=${binary_name}, platform=${platform}"
54153

55-
echo "${binary_name}-${version}-${platform}"
154+
echo "$g_filename_template" |
155+
sed "s/__VERSION__/${version}/g;s/__VERSION_SHORT__/${version_short}/g;s/__BINARY_NAME__/${binary_name}/g;s/__PLATFORM__/${platform}/g"
56156
}
57157

58-
# https://github.com/terraform-docs/terraform-docs/releases/download/v0.6.0/terraform-docs-v0.6.0-linux-amd64
59-
60158
get_download_url() {
61159
local version="$1"
62160
local platform="$2"
63161
local binary_name="$3"
64162
local filename
65163
filename="$(get_filename "$version" "$platform" "$binary_name")"
164+
local version_short
165+
version_short=$(get_version_short "$version")
166+
# log DEBUG "version=${version}, binary_name=${binary_name}, platform=${platform}, filename=${filename}"
167+
168+
echo "$g_download_url_template" |
169+
sed "s|__GITHUB_COORDINATES__|${g_github_coordinates}|g;s|__VERSION__|${version}|g;s|__VERSION_SHORT__|${version_short}|g;s|__FILENAME__|${filename}|g;"
66170

67-
echo "https://github.com/terraform-docs/terraform-docs/releases/download/${version}/${filename}"
68171
}
69172

70-
tmp_download_dir="$(mktemp -d -t 'asdf_XXXXXXXX')"
71-
trap 'rm -rf "${tmp_download_dir}"' EXIT
72-
install_tool "$ASDF_INSTALL_TYPE" "$ASDF_INSTALL_VERSION" "$ASDF_INSTALL_PATH" "$tmp_download_dir" terraform-docs
173+
readonly _tmp_download_dir="$(mktemp -d -t 'asdf_XXXXXXXX')"
174+
trap 'rm -rf "${_tmp_download_dir}"' EXIT
175+
install_tool "$ASDF_INSTALL_TYPE" "$ASDF_INSTALL_VERSION" "$ASDF_INSTALL_PATH" "$_tmp_download_dir" "$g_binary_name" "$g_binary_altname" "$g_downloaded_file_is_not_an_archive"

bin/list-all

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

3-
github_coordinates=terraform-docs/terraform-docs
4-
releases_path="https://api.github.com/repos/${github_coordinates}/releases"
5-
cmd="curl -sL"
3+
readonly github_coordinates=terraform-docs/terraform-docs
4+
readonly releases_path="https://api.github.com/repos/${github_coordinates}/releases"
5+
cmd="curl -Ls"
66
if [ -n "$GITHUB_API_TOKEN" ]; then
77
cmd="$cmd -H 'Authorization: token $GITHUB_API_TOKEN'"
88
fi

shellcheck-on-linux-only.sh

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)