Skip to content

Commit

Permalink
feat: rewrite & simplify plugin (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
jthegedus committed Jul 17, 2022
1 parent aa92510 commit 279a264
Show file tree
Hide file tree
Showing 33 changed files with 560 additions and 1,232 deletions.
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: 2
updates:
# Maintain dependencies for GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
24 changes: 0 additions & 24 deletions .github/workflows/build.yaml

This file was deleted.

25 changes: 15 additions & 10 deletions .github/workflows/lint.yaml → .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,25 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: asdf_install
uses: actions/checkout@v3

- name: Install asdf dependencies
uses: asdf-vm/actions/install@v1
- name: Shellcheck
run: shellcheck -x bin/* -P lib/
- name: Run ShellCheck
run: scripts/shellcheck.bash

shfmt:
shellfmt:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: asdf_install
uses: actions/checkout@v3

- name: Install asdf dependencies
uses: asdf-vm/actions/install@v1
- name: Shell Format - List files to check

- name: List file to shfmt
run: shfmt -f .
- name: Shell Format - Validate
run: shfmt -d .

- name: Run shfmt
run: scripts/shfmt.bash

Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ on:
- main

jobs:
release-please:
release:
runs-on: ubuntu-latest
steps:
- uses: GoogleCloudPlatform/release-please-action@v2
- uses: GoogleCloudPlatform/release-please-action@v3
name: Create Release
with:
release-type: simple
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Lint PR
name: Enforce Conventional Commit Style

on:
pull_request_target:
Expand All @@ -8,10 +8,10 @@ on:
- synchronize

jobs:
main:
semantic-pr:
runs-on: ubuntu-latest
steps:
- uses: amannn/action-semantic-pull-request@v3.4.0
- uses: amannn/action-semantic-pull-request@v4.5.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
Expand Down
40 changes: 40 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Test

on:
push:
branches:
- main
pull_request:

jobs:
asdf_plugin_test:
strategy:
matrix:
os:
- ubuntu-latest
- macos-latest
runs-on: ${{ matrix.os }}
steps:
- name: asdf plugin test
uses: asdf-vm/actions/plugin-test@v1
with:
command: firebase --help
github_token: ${{ github.token }}
bats:
strategy:
matrix:
os:
- ubuntu-latest
- macos-latest
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install asdf dependencies
uses: asdf-vm/actions/install@v1
- name: Run tests
run: bats test
env:
GITHUB_API_TOKEN: ${{ github.token }}
1 change: 0 additions & 1 deletion .husky/.gitignore

This file was deleted.

4 changes: 0 additions & 4 deletions .husky/commit-msg

This file was deleted.

20 changes: 0 additions & 20 deletions .husky/pre-commit

This file was deleted.

8 changes: 6 additions & 2 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
nodejs 16.15.1
# Markdown Formatting
deno 1.23.1
# Shell Script Testing Framework
bats 1.7.0
# Shell Script Linter
shellcheck 0.8.0
# Shell Script Formatter
shfmt 3.5.1
pnpm 7.2.1
27 changes: 18 additions & 9 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,22 @@

## Setup

1. `git clone https://github.com/jthegedus/asdf-firebase.git`
2. `asdf install`
3. `npm i`
1. `git clone https://github.com/jthegedus/asdf-v.git`
1. ```
asdf plugin add deno https://github.com/asdf-community/asdf-deno.git
asdf plugin add bats https://github.com/timgluz/asdf-bats.git
asdf plugin add shellcheck https://github.com/luizm/asdf-shellcheck.git
asdf plugin add shfmt https://github.com/luizm/asdf-shfmt.git
```
1. `asdf install`

## Structure

- `bin/*`: asdf plugin functions
- `lib/dependencies.txt`: list of dependencies required for this plugin to execute and install the tool as well as the tool's dependencies.
- `lib/helpers.bash`: helper functions that are asdf-firebase specific
- `lib/utils.bash`: utility functions that are asdf-plugin agnostic
- `lib/dependencies.txt`: list of dependencies required for this plugin to
execute and install the tool as well as the tool's dependencies.
- `lib/envs.bash`: environment variables for install, use and testing of the
plugin

## Testing Locally

Expand All @@ -20,14 +26,17 @@
```shell
asdf plugin remove firebase
asdf plugin add firebase .
asdf install firebase 7.15.1
asdf install firebase 11.2.2
```

### asdf plugin tests
### asdf tests

Two types of testing are used. Bats tests under the `test/` dir and asdf
specific integration tests with `asdf plugin test`.

```shell
asdf plugin test <plugin-name> <plugin-url> [--asdf-tool-version <version>] [--asdf-plugin-gitref <git-ref>] [test-command*]
asdf plugin test firebase https://github.com/jthegedus/asdf-firebase.git firebase --version
asdf plugin test v https://github.com/jthegedus/asdf-v.git v --version
```

Tests are automatically run in GitHub Actions on push and PR.
66 changes: 45 additions & 21 deletions bin/download
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,50 @@ set -euo pipefail
current_script_path="${BASH_SOURCE[0]}"
plugin_dir="$(dirname "$(dirname "$current_script_path")")"

# shellcheck source=../lib/utils.bash
source "${plugin_dir}/lib/utils.bash"

function download() {
local filename="firebase"
local url
url="$(get_github_repo)/releases/download/v${ASDF_INSTALL_VERSION}/firebase-tools-$(get_os_name)"

log_info "⏬ downloading ${filename} ${ASDF_INSTALL_VERSION} from ${url}"
status_code=$(curl -X GET \
--write-out "%{http_code}" \
--progress-bar \
-Lo "${ASDF_DOWNLOAD_PATH}/${filename}" \
"${url}")

if [[ ${status_code} -eq 404 ]]; then
rm -rf "${ASDF_DOWNLOAD_PATH}"
log_failure_and_exit "An error occurred. firebase-tools may not have been found for version ${ASDF_INSTALL_VERSION}. Full versions are required, not just major version numbers."
fi
log_success "downloaded!"
# shellcheck source=../lib/envs.bash
. "${plugin_dir}/lib/envs.bash"

function fail() {
printf "* ERROR: asdf-%s %s\\n" "$TOOL_NAME" "$*"
exit 1
}

download
# ref installs not supported
if [ "$ASDF_INSTALL_TYPE" != "version" ]; then
fail "supports release installs only. See \"asdf list all $TOOL_NAME\" for a list of supported versions."
fi

if [ "$ASDF_INSTALL_TYPE" == "version" ]; then
# validate version(non-ref) is in list-all versions
results="$(asdf list all $TOOL_NAME)"
if ! grep -q "^$ASDF_INSTALL_VERSION$" <<<"$results"; then
fail "version \"$ASDF_INSTALL_VERSION\" not supported. \"asdf list all $TOOL_NAME\" will list available versions."
fi
fi

os_name="default"
case $(uname -s) in
Linux*)
os_name="linux"
;;
Darwin*)
os_name="macos"
;;
*)
fail "Script only supports macOS and Ubuntu"
;;
esac
url="${GH_REPO}/releases/download/v${ASDF_INSTALL_VERSION}/firebase-tools-${os_name}"

printf "* Downloading %s@%s from %s\\n" "$TOOL_NAME" "$ASDF_INSTALL_VERSION" "$url"
status_code=$(curl -X GET \
--write-out "%{http_code}" \
--progress-bar \
-Lo "${ASDF_DOWNLOAD_PATH}/${TOOL_NAME}" \
"${url}")

if [[ ${status_code} -eq 404 ]]; then
rm -rf "${ASDF_DOWNLOAD_PATH}"
fail "An error occurred. firebase-tools may not have been found for version ${ASDF_INSTALL_VERSION}. Full versions are required, not just major version numbers."
fi
printf "%s\\n" "* Downloaded to ${ASDF_DOWNLOAD_PATH}/${TOOL_NAME}"
13 changes: 13 additions & 0 deletions bin/help.deps
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

set -euo pipefail

current_script_path=${BASH_SOURCE[0]}
plugin_dir=$(dirname "$(dirname "$current_script_path")")

# shellcheck source=../lib/envs.bash
. "${plugin_dir}/lib/envs.bash"

printf "%s\\n\\n" "Dependencies:"
cat "$plugin_dir/lib/dependencies.txt"
printf "\\n"
12 changes: 12 additions & 0 deletions bin/help.links
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

set -euo pipefail

current_script_path=${BASH_SOURCE[0]}
plugin_dir=$(dirname "$(dirname "$current_script_path")")

# shellcheck source=../lib/envs.bash
. "${plugin_dir}/lib/envs.bash"

printf "%s\\t%s\\n" "Git Repository:" "$GH_REPO"
printf "%s\\t%s\\n" "Documentation:" "$DOCS_SITE"
11 changes: 11 additions & 0 deletions bin/help.overview
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

set -euo pipefail

current_script_path=${BASH_SOURCE[0]}
plugin_dir=$(dirname "$(dirname "$current_script_path")")

# shellcheck source=../lib/envs.bash
. "${plugin_dir}/lib/envs.bash"

printf "%s\\n\\n" "Manage $TOOL_NAME versions per project. The minimum supported $TOOL_NAME version is $MIN_SUPPORTED_VERSION"
Loading

0 comments on commit 279a264

Please sign in to comment.