Skip to content

Commit

Permalink
chore: unify lint/fix scripts (#1549)
Browse files Browse the repository at this point in the history
  • Loading branch information
jthegedus committed May 31, 2023
1 parent 097f773 commit d8ce353
Show file tree
Hide file tree
Showing 9 changed files with 297 additions and 199 deletions.
61 changes: 13 additions & 48 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,61 +6,26 @@ on:
- master
pull_request:

jobs:
shellcheck:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Install asdf dependencies
uses: asdf-vm/actions/install@v2

- name: Run ShellCheck
run: scripts/shellcheck.bash

shellfmt:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
env:
PYTHON_MIN_VERSION: "3.7.13"

- name: Install Fish (for fish_indent)
run: |
sudo add-apt-repository -y ppa:fish-shell/nightly-master
sudo apt-get update
sudo apt-get -y install fish
- name: Install asdf dependencies
uses: asdf-vm/actions/install@v2

- name: List file to shfmt
run: shfmt -f .

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

checkstyle-py:
jobs:
asdf:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Install Python
uses: actions/setup-python@v4
- uses: actions/checkout@v3
- uses: asdf-vm/actions/install@v2
- uses: actions/setup-python@v4
with:
python-version: "3.7.13"
python-version: ${{ env.PYTHON_MIN_VERSION }}
- run: scripts/install_dependencies.bash
- run: scripts/lint.bash --check

- name: Run checkstyle.py
run: scripts/checkstyle.py

actionlint:
actions:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- uses: actions/checkout@v3
- name: Check workflow files
uses: docker://rhysd/actionlint:1.6.23
uses: docker://rhysd/actionlint:1.6.24
with:
args: -color
86 changes: 12 additions & 74 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@ on:
- master
pull_request:

env:
ELVISH_VERSION: v0.19.2
FISH_VERSION: 3.6.1
NUSHELL_VERSION: 0.78.0
POWERSHELL_VERSION: 7.3.3

jobs:
detect-changes:
runs-on: ubuntu-latest
Expand All @@ -22,30 +16,26 @@ jobs:
documentation: ${{ steps.filter.outputs.documentation }}
cli: ${{ steps.filter.outputs.cli }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: dorny/paths-filter@v2
id: filter
with:
filters: |
documentation:
- '.github/workflows/**'
- 'docs/**'
- '.tool-versions'
cli:
- '.github/workflows/**'
- 'bin/**'
- 'lib/**'
- 'scripts/**'
- 'test/**'
- '.tool-versions'
- 'asdf.elv'
- 'asdf.fish'
- 'asdf.nu'
- 'asdf.sh'
- 'asdf.*'
- 'defaults'
- 'help.txt'
ubuntu:
needs: detect-changes
Expand All @@ -54,46 +44,11 @@ jobs:
if: ${{ needs.detect-changes.outputs.cli == 'true' }}
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Install test dependencies
run: |
curl -fsSLo- https://packages.microsoft.com/keys/microsoft.asc | sudo tee >/dev/null /etc/apt/trusted.gpg.d/microsoft.asc
sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-debian-bullseye-prod bullseye main" > /etc/apt/sources.list.d/microsoft.list'
sudo add-apt-repository -y ppa:fish-shell/release-3
sudo apt-get update
sudo apt-get -y install curl parallel \
fish="${{ env.FISH_VERSION }}-1~jammy" \
powershell="${{ env.POWERSHELL_VERSION }}-1.deb"
# Create $HOME/bin
mkdir -p "$HOME/bin"
# Download elvish binary and add to path
curl https://dl.elv.sh/linux-amd64/elvish-${{ env.ELVISH_VERSION }}.tar.gz -o elvish-${{ env.ELVISH_VERSION }}.tar.gz
tar xzf elvish-${{ env.ELVISH_VERSION }}.tar.gz
rm elvish-${{ env.ELVISH_VERSION }}.tar.gz
mv elvish-${{ env.ELVISH_VERSION }} "$HOME/bin/elvish"
# Download nushell binary and add to path
curl -L https://github.com/nushell/nushell/releases/download/${{ env.NUSHELL_VERSION }}/nu-${{ env.NUSHELL_VERSION }}-x86_64-unknown-linux-gnu.tar.gz -o nu-${{ env.NUSHELL_VERSION }}-x86_64-unknown-linux-gnu.tar.gz
tar xzf nu-${{ env.NUSHELL_VERSION }}-x86_64-unknown-linux-gnu.tar.gz
rm nu-${{ env.NUSHELL_VERSION }}-x86_64-unknown-linux-gnu.tar.gz
mv nu-${{ env.NUSHELL_VERSION }}-x86_64-unknown-linux-gnu/* "$HOME/bin"
# Add $HOME/bin to path
echo "$HOME/bin" >>"$GITHUB_PATH"
- name: Install bats
run: |
git clone --depth 1 --branch "v$(grep -Eo "^\\s*bats\\s*.*$" ".tool-versions" | cut -d ' ' -f2-)" https://github.com/bats-core/bats-core.git "$HOME/bats-core"
echo "$HOME/bats-core/bin" >>"$GITHUB_PATH"
- name: Run tests
run: scripts/test.bash
- run: scripts/install_dependencies.bash
- run: scripts/test.bash
env:
GITHUB_API_TOKEN: ${{ github.token }}

Expand All @@ -104,26 +59,11 @@ jobs:
if: ${{ needs.detect-changes.outputs.cli == 'true' }}
runs-on: macos-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Install test dependencies
run: |
brew install coreutils parallel \
elvish \
fish \
nushell \
powershell
- name: Install bats
run: |
git clone --depth 1 --branch "v$(grep -Eo "^\\s*bats\\s*.*$" ".tool-versions" | cut -d ' ' -f2-)" https://github.com/bats-core/bats-core.git "$HOME/bats-core"
echo "$HOME/bats-core/bin" >>"$GITHUB_PATH"
- name: Run tests
run: scripts/test.bash
- run: scripts/install_dependencies.bash
- run: scripts/test.bash
env:
GITHUB_API_TOKEN: ${{ github.token }}

Expand All @@ -141,13 +81,11 @@ jobs:
fetch-depth: 0

# only run steps past here if changes to docs/** directory
- name: Setup Node.js
uses: actions/setup-node@v3
- uses: actions/setup-node@v3
with:
node-version: "18"

- name: Cache dependencies
uses: actions/cache@v3
- uses: actions/cache@v3
id: npm-cache
with:
path: |
Expand Down
11 changes: 6 additions & 5 deletions docs/contribute/core.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,15 @@ If you want to try out your changes without making change to your installed `asd
It is best to format, lint and test your code locally before you commit or push to the remote. Use the following scripts/commands:

```shell:no-line-numbers
# Shellcheck
./scripts/shellcheck.bash
# Lint
./scripts/lint.bash --check
# Format
./scripts/shfmt.bash
# Fix & Format
./scripts/lint.bash --fix
# Test: all tests
bats test/
./scripts/test.bash
# Test: for specific command
bats test/list_commands.bash
```
Expand Down
24 changes: 0 additions & 24 deletions scripts/format.bash

This file was deleted.

77 changes: 77 additions & 0 deletions scripts/install_dependencies.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/usr/bin/env bash

set -euo pipefail
IFS=$'\n\t'

### Used env vars set by default in GitHub Actions
# docs: https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables
# GITHUB_ACTIONS
# RUNNER_OS

if [ -z "$GITHUB_ACTIONS" ]; then
printf "%s\n" "GITHUB_ACTIONS is not set. This script is only intended to be run in GitHub Actions. Exiting."
exit 1
fi

if [ -z "$RUNNER_OS" ]; then
printf "%s\n" "RUNNER_OS is not set. This script is only intended to be run in GitHub Actions. Exiting."
exit 1
fi

### Set environment variables for tracking versions
# Elvish
elvish_semver="v0.19.2"
# Fish
fish_semver="3.6.1"
fish_apt_semver="${fish_semver}-1~jammy"
# Nushell
nushell_semver="0.78.0"
# Powershell
powershell_semver="7.3.3"
powershell_apt_semver="${powershell_semver}-1.deb"

### Install dependencies on Linux
if [ "$RUNNER_OS" = "Linux" ]; then
printf "%s\n" "Installing dependencies on Linux"

curl -fsSLo- https://packages.microsoft.com/keys/microsoft.asc | sudo tee /etc/apt/trusted.gpg.d/microsoft.asc >/dev/null
sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-debian-bullseye-prod bullseye main" > /etc/apt/sources.list.d/microsoft.list'
sudo add-apt-repository -y ppa:fish-shell/release-3
sudo apt-get update
sudo apt-get -y install curl parallel \
fish="${fish_apt_semver}" \
powershell="${powershell_apt_semver}"

# Create $HOME/bin
mkdir -p "$HOME/bin"

# Download elvish binary and add to path
curl https://dl.elv.sh/linux-amd64/elvish-${elvish_semver}.tar.gz -o elvish-${elvish_semver}.tar.gz
tar xzf elvish-${elvish_semver}.tar.gz
rm elvish-${elvish_semver}.tar.gz
mv elvish-${elvish_semver} "$HOME/bin/elvish"

# Download nushell binary and add to path
curl -L https://github.com/nushell/nushell/releases/download/${nushell_semver}/nu-${nushell_semver}-x86_64-unknown-linux-gnu.tar.gz -o nu-${nushell_semver}-x86_64-unknown-linux-gnu.tar.gz
tar xzf nu-${nushell_semver}-x86_64-unknown-linux-gnu.tar.gz
rm nu-${nushell_semver}-x86_64-unknown-linux-gnu.tar.gz
mv nu-${nushell_semver}-x86_64-unknown-linux-gnu/* "$HOME/bin"

# Add $HOME/bin to path (add Elvish & Nushell to path)
echo "$HOME/bin" >>"$GITHUB_PATH"
fi

### Install dependencies on macOS
if [ "$RUNNER_OS" = "macOS" ]; then
printf "%s\n" "Installing dependencies on macOS"
brew install coreutils parallel \
elvish \
fish \
nushell \
powershell
fi

### Install bats-core
printf "%s\n" "Installing bats-core"
git clone --depth 1 --branch "v$(grep -Eo "^\\s*bats\\s*.*$" ".tool-versions" | cut -d ' ' -f2-)" https://github.com/bats-core/bats-core.git "$HOME/bats-core"
echo "$HOME/bats-core/bin" >>"$GITHUB_PATH"

0 comments on commit d8ce353

Please sign in to comment.