Skip to content

Commit

Permalink
Update repository
Browse files Browse the repository at this point in the history
  • Loading branch information
piotmag769 committed Oct 23, 2023
1 parent 492389a commit 968e89f
Show file tree
Hide file tree
Showing 8 changed files with 212 additions and 49 deletions.
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
nodejs 18.14.0
shellcheck 0.9.0
shfmt 3.6.0
71 changes: 42 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,56 +1,69 @@
<div align="center">

# asdf-starknet-foundry [![Build](https://github.com/akhercha/asdf-starknet-foundry/actions/workflows/build.yml/badge.svg)](https://github.com/akhercha/asdf-starknet-foundry/actions/workflows/build.yml) [![Lint](https://github.com/akhercha/asdf-starknet-foundry/actions/workflows/lint.yml/badge.svg)](https://github.com/akhercha/asdf-starknet-foundry/actions/workflows/lint.yml)
# asdf-starknet-foundry [![Build](https://github.com/foundry-rs/asdf-starknet-foundry/actions/workflows/build.yml/badge.svg)](https://github.com/foundry-rs/asdf-starknet-foundry/actions/workflows/build.yml) [![Lint](https://github.com/foundry-rs/asdf-starknet-foundry/actions/workflows/lint.yml/badge.svg)](https://github.com/foundry-rs/asdf-starknet-foundry/actions/workflows/lint.yml)

[starknet-foundry](https://foundry-rs.github.io/starknet-foundry/) plugin for the [asdf version manager](https://asdf-vm.com).
[Starknet Foundry] plugin for the [asdf] version manager created by [akhercha](https://github.com/akhercha).

</div>

# Contents
## Install

- [Dependencies](#dependencies)
- [Install](#install)
- [Contributing](#contributing)
- [License](#license)
This plugin needs `bash`, `curl`, `tar` and other generic POSIX utilities.
Everything should be included by default on your system.

# Dependencies
```shell
asdf plugin add starknet-foundry
```

**TODO: adapt this section**
or

- `bash`, `curl`, `tar`: generic POSIX utilities.
- `SOME_ENV_VAR`: set this environment variable in your shell config to load the correct version of tool x.
```shell
asdf plugin add starknet-foundry https://github.com/foundry-rs/asdf-starknet-foundry.git
```

# Install
## Use

Plugin:
Show all installable versions:

```shell
asdf plugin add starknet-foundry
# or
asdf plugin add starknet-foundry https://github.com/akhercha/asdf-starknet-foundry.git
asdf list-all starknet-foundry
```

starknet-foundry:
Install latest version:

```shell
# Show all installable versions
asdf list-all starknet-foundry

# Install specific version
asdf install starknet-foundry latest
```

Install specific version:

```shell
asdf install starknet-foundry 0.8.2
```

Set a version globally (in your `~/.tool-versions` file):

# Set a version globally (on your ~/.tool-versions file)
```shell
asdf global starknet-foundry latest
```

Set a version locally:

# Now starknet-foundry commands are available
snforge --version <TOOL CHECK><TOOL CHECK> sncast --version
```shell
asdf local starknet-foundry latest
```

Check [asdf](https://github.com/asdf-vm/asdf) readme for more instructions on how to
install & manage versions.
Now snforge and sncast commands are available:

```shell
snforge --version
```

# Contributing
```shell
sncast --version
```

Contributions of any kind welcome! See the [contributing guide](contributing.md).
Check [asdf](https://github.com/asdf-vm/asdf) readme for more instructions on how to install & manage versions.

[Thanks goes to these contributors](https://github.com/akhercha/asdf-starknet-foundry/graphs/contributors)!
[asdf]: https://asdf-vm.com
[Starknet Foundry]: https://foundry-rs.github.io/starknet-foundry
12 changes: 0 additions & 12 deletions contributing.md

This file was deleted.

2 changes: 2 additions & 0 deletions plugin_test
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
repository = https://github.com/foundry-rs/asdf-starknet-foundry.git

19 changes: 17 additions & 2 deletions scripts/format.bash
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
#!/usr/bin/env bash

shfmt --language-dialect bash --write \
./**/*
set -euo pipefail

printf "* %s\n\n" "Formatting shell scripts..."

# format Shell scripts in scripts/ directory.
shfmt --language-dialect bash --find \
./scripts/*
shfmt --language-dialect bash --indent 2 --write \
./scripts/*

printf "\n* %s\n\n" "Formatting markdown..."

# format Markdown files.
npx -y prettier --write \
./**/*.md

printf "\n* %s\n" "Formatting complete!"
22 changes: 16 additions & 6 deletions scripts/lint.bash
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
#!/usr/bin/env bash

shellcheck --shell=bash --external-sources \
bin/* --source-path=template/lib/ \
lib/* \
scripts/*
set -euo pipefail

shfmt --language-dialect bash --diff \
./**/*
# check format Markdown files.
npx -y prettier --check \
./**/*.md

printf "* %s\n" "Linting shell scripts..."

# check format Shell scripts in scripts/ directory.
shfmt --language-dialect bash --indent 2 --diff \
./scripts/*

# lint for errors in Shell scripts in scripts/ directory.
shellcheck --shell bash --external-sources \
./scripts/*

printf "* %s\n" "All matched using shellcheck & shfmt!"
134 changes: 134 additions & 0 deletions scripts/test_plugin.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
#!/usr/bin/env bash

# See: ./scripts/test_plugin.bash --help

function fail() {
echo "FAIL: $*" >&2
exit 1
}

# Extract the link to a svg badge from a line of README.
function badge_svg() {
grep -o '(http[^)]*svg[^)]*)' | sed -e 's/(//;s/)//'
}

function check_plugins_from_diff() {
local BASE_REF="$1" # Base commit of main branch.
local HEAD_REF="$2" # Latest commit of PR

local DIFF_CHANGES
DIFF_CHANGES="$(git diff --name-only "${BASE_REF}" "${HEAD_REF}")"

# Assert that the PR diff only includes a change to README and file(s) under plugins/ directory
{
test 1 -lt "$(echo "$DIFF_CHANGES" | wc --lines | xargs)" &&
echo "$DIFF_CHANGES" | grep README.md >/dev/null &&
echo "$DIFF_CHANGES" | grep plugins/ >/dev/null
} || fail "Expected git diff ${REF_RANGE} to only include changes for a single plugin"

local PLUGIN_FILES
PLUGIN_FILES="$(git diff --name-only "${BASE_REF}" "${HEAD_REF}" -- plugins/)"
for PLUGIN_FILE in $PLUGIN_FILES; do
echo "Checking $PLUGIN_FILE"
check_plugin_from_file "$PLUGIN_FILE"
done
}

function check_plugin_from_file() {
local PLUGIN_FILE="$1"

# Assert that we have a file at plugins/PLUGIN_NAME
test -f "$PLUGIN_FILE" ||
fail "Expected a plugin file at $PLUGIN_FILE"

# Assert that PLUGIN_FILE file ends with new line.
test 'X' == "$(tail --bytes=1 "$PLUGIN_FILE" | tr '\n' 'X')" ||
fail "Expected $PLUGIN_FILE to end with a new line."

# Assert that PLUGIN_FILE has repository key and points to a git repo.
local PLUGIN_REPO
PLUGIN_REPO="$(sed -e 's/repository = //' "$PLUGIN_FILE")"
test -n "$PLUGIN_REPO" ||
fail "File $PLUGIN_FILE does not specify a repository url"

# Assert the plugin repo is reachable.
git ls-remote --quiet "$PLUGIN_REPO" HEAD >/dev/null ||
fail "Repo is unreachable: $PLUGIN_REPO"

local PLUGIN_REPO_NO_GIT
PLUGIN_REPO_NO_GIT="$(echo "$PLUGIN_REPO" | sed -e 's/\.git$//' | tr '/' '\n' | tail --lines 1)"

local README_LINE
README_LINE="$(git grep -h --ignore-case -C0 "${PLUGIN_REPO_NO_GIT}" -- README.md | head --lines 1)"

# Assert that a new line for plugin was added at README
test -n "$README_LINE" ||
fail "Expected a line at README.md with a link to ${PLUGIN_REPO_NO_GIT}"

BADGE_COLUMN="$(echo "${README_LINE}" | cut -d '|' -f4)"
BADGE_URL="$(echo "${BADGE_COLUMN}" | badge_svg)"

# Assert that the badge has "pass" text in it, indicating the plugin is healthy
curl -qsL "${BADGE_URL}" | grep -o -i 'pass' >/dev/null ||
fail "Expected plugin CI badge SVG to be passing but it was not: $BADGE_URL"

echo "OK $PLUGIN_FILE"
}

function check_all_plugins() {
local fails=0
local total=0
local out
for file in plugins/*; do

total=$((total + 1))
out="$($0 --file "$file" 2>&1)"
result=$?

if test "${result}" == 0 && test ! "${CI}"; then
# show successes locally, not in CI
printf "* Checking %s %s\n" "$file" "[PASSED]"
elif test "${result}" != 0; then
# show failures locally and in CI
fails=$((fails + 1))
printf "* Checking %s %s\n" "$file" "[FAILED]"
printf "*\t%s\n" "$out"
fi
done

printf "\n"
printf "%s %s\n" "Plugins available:" "${total}"
printf "%s %s\n" "Plugin build checks passed:" "$((total - fails))"
printf "%s %s\n" "Plugin build checks failed:" "${fails}"
exit ${fails}
}

if test "--all" == "$*"; then
printf "%s\n" "Testing all registered plugins"
check_all_plugins

elif test "--diff" == "$1"; then
printf "%s %s..%s" "Testing plugin introduced at git diff" "$2" "$3"
check_plugins_from_diff "$2" "$3"

elif test "--file" == "$1"; then
check_plugin_from_file "$2"
else
cat <<-EOF
Test that a plugin at PLUGIN_FILE follows basic sanity checks:
* A plugins/<plugin> file contains the repository url.
* A new line is added on README.md with a link mentioning the plugin.
* The new plugin has CI badge and it's passing.
Usage:
> $0 --file plugins/PLUGIN_FILE
Test only plugin at file.
> $0 --all
Test all plugins registered under plugins/
> $0 --diff BASE_REF HEAD_REF
Test a single plugin introduced in git diff BASE_REF..HEAD_REF
EOF
fi
Empty file removed version.txt
Empty file.

0 comments on commit 968e89f

Please sign in to comment.