Skip to content

Commit

Permalink
chore: initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
junminahn committed Jun 10, 2024
0 parents commit 9002b4b
Show file tree
Hide file tree
Showing 13 changed files with 238 additions and 0 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Build

on:
pull_request:
paths-ignore:
- '**.md'
push:
paths-ignore:
- '**.md'

jobs:
plugin-test:
runs-on: ubuntu-22.04
steps:
- uses: hmarr/debug-action@f7318c783045ac39ed9bb497e22ce835fdafbfe6
- uses: actions/checkout@b80ff79f1755d06ba70441c368a6fe801f5f3a62

- name: Install asdf
uses: asdf-vm/actions/setup@6278efebb38ae025cc91dd008910f549e775a8c8

- name: Move database-tools plugin to asdf plugins dir
run: |
mkdir -p ${ASDF_DIR}/plugins
cp -r . ${ASDF_DIR}/plugins/database-tools
- name: Run database-tools plugin tests
run: |
echo "Trying to list all versions of database-tools"
asdf list all database-tools
echo "Trying to install database-tools 0.8.1"
asdf install database-tools 0.8.1
asdf list database-tools | grep 0.8.1
- uses: asdf-vm/actions/plugin-test@6278efebb38ae025cc91dd008910f549e775a8c8
with:
command: database-tools --version
29 changes: 29 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Check code/commit conventions

on: push

jobs:
pre-commit:
runs-on: ubuntu-22.04
steps:
- uses: hmarr/debug-action@f7318c783045ac39ed9bb497e22ce835fdafbfe6
- uses: actions/checkout@b80ff79f1755d06ba70441c368a6fe801f5f3a62

- name: Install asdf tools
uses: egose/actions/asdf-tools@6be83b27672d3e09a451e7aeb195781604a124da

- name: Install python tools
run: |
pip install -r requirements.txt
asdf reshim
- name: Rerun Pre-Commit Hooks on CI
run: pre-commit run --color=always --show-diff-on-failure --all-files

commitlint:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@b80ff79f1755d06ba70441c368a6fe801f5f3a62
with:
fetch-depth: 0
- uses: wagoid/commitlint-github-action@7f0a61df502599e1f1f50880aaa7ec1e2c0592f2
Empty file added .gitignore
Empty file.
30 changes: 30 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-added-large-files
- id: check-case-conflict
- id: check-executables-have-shebangs
files: \.bash
- id: check-json
- id: check-vcs-permalinks
- id: check-yaml
- id: check-ast
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.13.0
hooks:
- id: pretty-format-yaml
args: [--autofix, --indent, '2']
# see https://github.com/gruntwork-io/pre-commit/releases
- repo: https://github.com/gruntwork-io/pre-commit
rev: v0.1.23
hooks:
- id: shellcheck
- repo: local
hooks:
- id: check-sh
name: check bash scripts' formats
entry: ./scripts/shfmt.bash
language: script
3 changes: 3 additions & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
python 3.12.1
shellcheck 0.9.0
shfmt 3.6.0
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) Junmin Ahn

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# asdf-database-tools

[Database Tools](https://github.com/egose/database-tools) binary plugin for [asdf](https://github.com/asdf-vm/asdf)

## Install

### Plugin

```sh
asdf plugin add database-tools
# or
asdf plugin add database-tools https://github.com/egose/asdf-database-tools.git
```

### database-tools

```sh
# List all versions of a package
asdf list all database-tools

# Install a specific version of a package
asdf install database-tools <version>

# Install the latest stable version
asdf install database-tools latest

# Set the package global version
asdf global database-tools <version>

# Check the version
database-tools --version
```

Please check [asdf](https://github.com/asdf-vm/asdf) for more details.

# License

See [LICENSE](LICENSE) ©[Junmin Ahn](https://github.com/junminahn/)
43 changes: 43 additions & 0 deletions bin/install
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env bash
set -eo pipefail

: "${ASDF_INSTALL_VERSION:?"Missing ASDF_INSTALL_VERSION"}"
: "${ASDF_INSTALL_PATH:?"Missing ASDF_INSTALL_PATH"}"

install_tool() {
local version=$1
local install_path=$2
local bin_install_path="${install_path}/bin"
local binary_name="database-tools"
local platform=""
local arch=""
local tempdir=""
local tempfile=""
local filename=""
local download_url=""

[ "Linux" = "$(uname)" ] && platform="linux" || platform="osx"
[ "x86_64" = "$(uname -m)" ] && arch="x86_64" || arch="i686"
echo "platform: $platform, arch: $arch"

[ "linux" = "${platform}" ] && tempdir=$(mktemp -d asdf-database-tools.XXXX) || tempdir=$(mktemp -dt asdf-database-tools.XXXX)

filename="v${version}/dist.tar.gz"
tempfile="${tempdir}/${filename}"
download_url="https://github.com/egose/database-tools/releases/download/${filename}"

echo "download_url $download_url"
echo "ASDF_INSTALL_PATH $ASDF_INSTALL_PATH"

curl -L "${download_url}" -o "${tempfile}"
tar zxf "${tempfile}" -C "$install_path" --strip-components=1 || exit 1

echo "Creating bin install directory"
mkdir -p "$bin_install_path"
cp "${install_path}/${binary_name}" "${bin_install_path}/${binary_name}"
chmod +x "${bin_install_path}/${binary_name}"

rm -rf "${tempdir}"
}

install_tool "$ASDF_INSTALL_VERSION" "$ASDF_INSTALL_PATH"
27 changes: 27 additions & 0 deletions bin/list-all
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash
set -eo pipefail

github_coordinates="egose/database-tools"
releases_path="https://api.github.com/repos/${github_coordinates}/releases"

cmd="curl -s"
if [ -n "$GITHUB_API_TOKEN" ]; then
cmd="$cmd -H 'Authorization: token $GITHUB_API_TOKEN'"
fi
cmd="$cmd $releases_path"

sort_versions() {
sed 'h; s/[+-]/./g; s/.p\([[:digit:]]\)/.z\1/; s/$/.z/; G; s/\n/ /' |
LC_ALL=C sort -V | cut -d ' ' -f 2
}

versions=$(
eval "$cmd" |
tee |
grep -o '"tag_name": *"[^"]*"' |
sed -E 's/"tag_name": *"v?([^"]*)"/\1/' |
sort_versions |
xargs
)

echo "$versions"
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pre-commit==3.1.1
gitlint==0.15.1
3 changes: 3 additions & 0 deletions scripts/shellcheck.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

exec shellcheck -s bash -x bin/*
3 changes: 3 additions & 0 deletions scripts/shfmt-diff.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

exec shfmt --diff --indent 2 .
3 changes: 3 additions & 0 deletions scripts/shfmt.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

exec shfmt --write --indent 2 .

0 comments on commit 9002b4b

Please sign in to comment.