Skip to content

Commit d8ce353

Browse files
authored
chore: unify lint/fix scripts (asdf-vm#1549)
1 parent 097f773 commit d8ce353

File tree

9 files changed

+297
-199
lines changed

9 files changed

+297
-199
lines changed

.github/workflows/lint.yml

Lines changed: 13 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -6,61 +6,26 @@ on:
66
- master
77
pull_request:
88

9-
jobs:
10-
shellcheck:
11-
runs-on: ubuntu-latest
12-
steps:
13-
- name: Checkout code
14-
uses: actions/checkout@v3
15-
16-
- name: Install asdf dependencies
17-
uses: asdf-vm/actions/install@v2
18-
19-
- name: Run ShellCheck
20-
run: scripts/shellcheck.bash
21-
22-
shellfmt:
23-
runs-on: ubuntu-latest
24-
steps:
25-
- name: Checkout code
26-
uses: actions/checkout@v3
9+
env:
10+
PYTHON_MIN_VERSION: "3.7.13"
2711

28-
- name: Install Fish (for fish_indent)
29-
run: |
30-
sudo add-apt-repository -y ppa:fish-shell/nightly-master
31-
sudo apt-get update
32-
sudo apt-get -y install fish
33-
34-
- name: Install asdf dependencies
35-
uses: asdf-vm/actions/install@v2
36-
37-
- name: List file to shfmt
38-
run: shfmt -f .
39-
40-
- name: Run shfmt
41-
run: scripts/shfmt.bash
42-
43-
checkstyle-py:
12+
jobs:
13+
asdf:
4414
runs-on: ubuntu-latest
4515
steps:
46-
- name: Checkout code
47-
uses: actions/checkout@v3
48-
49-
- name: Install Python
50-
uses: actions/setup-python@v4
16+
- uses: actions/checkout@v3
17+
- uses: asdf-vm/actions/install@v2
18+
- uses: actions/setup-python@v4
5119
with:
52-
python-version: "3.7.13"
20+
python-version: ${{ env.PYTHON_MIN_VERSION }}
21+
- run: scripts/install_dependencies.bash
22+
- run: scripts/lint.bash --check
5323

54-
- name: Run checkstyle.py
55-
run: scripts/checkstyle.py
56-
57-
actionlint:
24+
actions:
5825
runs-on: ubuntu-latest
5926
steps:
60-
- name: Checkout code
61-
uses: actions/checkout@v3
62-
27+
- uses: actions/checkout@v3
6328
- name: Check workflow files
64-
uses: docker://rhysd/actionlint:1.6.23
29+
uses: docker://rhysd/actionlint:1.6.24
6530
with:
6631
args: -color

.github/workflows/tests.yml

Lines changed: 12 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@ on:
66
- master
77
pull_request:
88

9-
env:
10-
ELVISH_VERSION: v0.19.2
11-
FISH_VERSION: 3.6.1
12-
NUSHELL_VERSION: 0.78.0
13-
POWERSHELL_VERSION: 7.3.3
14-
159
jobs:
1610
detect-changes:
1711
runs-on: ubuntu-latest
@@ -22,30 +16,26 @@ jobs:
2216
documentation: ${{ steps.filter.outputs.documentation }}
2317
cli: ${{ steps.filter.outputs.cli }}
2418
steps:
25-
- name: Checkout code
26-
uses: actions/checkout@v3
19+
- uses: actions/checkout@v3
2720
with:
2821
fetch-depth: 0
29-
3022
- uses: dorny/paths-filter@v2
3123
id: filter
3224
with:
3325
filters: |
3426
documentation:
3527
- '.github/workflows/**'
3628
- 'docs/**'
37-
- '.tool-versions'
3829
cli:
3930
- '.github/workflows/**'
4031
- 'bin/**'
4132
- 'lib/**'
4233
- 'scripts/**'
4334
- 'test/**'
4435
- '.tool-versions'
45-
- 'asdf.elv'
46-
- 'asdf.fish'
47-
- 'asdf.nu'
48-
- 'asdf.sh'
36+
- 'asdf.*'
37+
- 'defaults'
38+
- 'help.txt'
4939
5040
ubuntu:
5141
needs: detect-changes
@@ -54,46 +44,11 @@ jobs:
5444
if: ${{ needs.detect-changes.outputs.cli == 'true' }}
5545
runs-on: ubuntu-latest
5646
steps:
57-
- name: Checkout code
58-
uses: actions/checkout@v3
47+
- uses: actions/checkout@v3
5948
with:
6049
fetch-depth: 0
61-
62-
- name: Install test dependencies
63-
run: |
64-
curl -fsSLo- https://packages.microsoft.com/keys/microsoft.asc | sudo tee >/dev/null /etc/apt/trusted.gpg.d/microsoft.asc
65-
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'
66-
sudo add-apt-repository -y ppa:fish-shell/release-3
67-
sudo apt-get update
68-
sudo apt-get -y install curl parallel \
69-
fish="${{ env.FISH_VERSION }}-1~jammy" \
70-
powershell="${{ env.POWERSHELL_VERSION }}-1.deb"
71-
72-
# Create $HOME/bin
73-
mkdir -p "$HOME/bin"
74-
75-
# Download elvish binary and add to path
76-
curl https://dl.elv.sh/linux-amd64/elvish-${{ env.ELVISH_VERSION }}.tar.gz -o elvish-${{ env.ELVISH_VERSION }}.tar.gz
77-
tar xzf elvish-${{ env.ELVISH_VERSION }}.tar.gz
78-
rm elvish-${{ env.ELVISH_VERSION }}.tar.gz
79-
mv elvish-${{ env.ELVISH_VERSION }} "$HOME/bin/elvish"
80-
81-
# Download nushell binary and add to path
82-
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
83-
tar xzf nu-${{ env.NUSHELL_VERSION }}-x86_64-unknown-linux-gnu.tar.gz
84-
rm nu-${{ env.NUSHELL_VERSION }}-x86_64-unknown-linux-gnu.tar.gz
85-
mv nu-${{ env.NUSHELL_VERSION }}-x86_64-unknown-linux-gnu/* "$HOME/bin"
86-
87-
# Add $HOME/bin to path
88-
echo "$HOME/bin" >>"$GITHUB_PATH"
89-
90-
- name: Install bats
91-
run: |
92-
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"
93-
echo "$HOME/bats-core/bin" >>"$GITHUB_PATH"
94-
95-
- name: Run tests
96-
run: scripts/test.bash
50+
- run: scripts/install_dependencies.bash
51+
- run: scripts/test.bash
9752
env:
9853
GITHUB_API_TOKEN: ${{ github.token }}
9954

@@ -104,26 +59,11 @@ jobs:
10459
if: ${{ needs.detect-changes.outputs.cli == 'true' }}
10560
runs-on: macos-latest
10661
steps:
107-
- name: Checkout code
108-
uses: actions/checkout@v3
62+
- uses: actions/checkout@v3
10963
with:
11064
fetch-depth: 0
111-
112-
- name: Install test dependencies
113-
run: |
114-
brew install coreutils parallel \
115-
elvish \
116-
fish \
117-
nushell \
118-
powershell
119-
120-
- name: Install bats
121-
run: |
122-
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"
123-
echo "$HOME/bats-core/bin" >>"$GITHUB_PATH"
124-
125-
- name: Run tests
126-
run: scripts/test.bash
65+
- run: scripts/install_dependencies.bash
66+
- run: scripts/test.bash
12767
env:
12868
GITHUB_API_TOKEN: ${{ github.token }}
12969

@@ -141,13 +81,11 @@ jobs:
14181
fetch-depth: 0
14282

14383
# only run steps past here if changes to docs/** directory
144-
- name: Setup Node.js
145-
uses: actions/setup-node@v3
84+
- uses: actions/setup-node@v3
14685
with:
14786
node-version: "18"
14887

149-
- name: Cache dependencies
150-
uses: actions/cache@v3
88+
- uses: actions/cache@v3
15189
id: npm-cache
15290
with:
15391
path: |

docs/contribute/core.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,15 @@ If you want to try out your changes without making change to your installed `asd
4040
It is best to format, lint and test your code locally before you commit or push to the remote. Use the following scripts/commands:
4141

4242
```shell:no-line-numbers
43-
# Shellcheck
44-
./scripts/shellcheck.bash
43+
# Lint
44+
./scripts/lint.bash --check
4545
46-
# Format
47-
./scripts/shfmt.bash
46+
# Fix & Format
47+
./scripts/lint.bash --fix
4848
4949
# Test: all tests
50-
bats test/
50+
./scripts/test.bash
51+
5152
# Test: for specific command
5253
bats test/list_commands.bash
5354
```

scripts/format.bash

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

scripts/install_dependencies.bash

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
IFS=$'\n\t'
5+
6+
### Used env vars set by default in GitHub Actions
7+
# docs: https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables
8+
# GITHUB_ACTIONS
9+
# RUNNER_OS
10+
11+
if [ -z "$GITHUB_ACTIONS" ]; then
12+
printf "%s\n" "GITHUB_ACTIONS is not set. This script is only intended to be run in GitHub Actions. Exiting."
13+
exit 1
14+
fi
15+
16+
if [ -z "$RUNNER_OS" ]; then
17+
printf "%s\n" "RUNNER_OS is not set. This script is only intended to be run in GitHub Actions. Exiting."
18+
exit 1
19+
fi
20+
21+
### Set environment variables for tracking versions
22+
# Elvish
23+
elvish_semver="v0.19.2"
24+
# Fish
25+
fish_semver="3.6.1"
26+
fish_apt_semver="${fish_semver}-1~jammy"
27+
# Nushell
28+
nushell_semver="0.78.0"
29+
# Powershell
30+
powershell_semver="7.3.3"
31+
powershell_apt_semver="${powershell_semver}-1.deb"
32+
33+
### Install dependencies on Linux
34+
if [ "$RUNNER_OS" = "Linux" ]; then
35+
printf "%s\n" "Installing dependencies on Linux"
36+
37+
curl -fsSLo- https://packages.microsoft.com/keys/microsoft.asc | sudo tee /etc/apt/trusted.gpg.d/microsoft.asc >/dev/null
38+
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'
39+
sudo add-apt-repository -y ppa:fish-shell/release-3
40+
sudo apt-get update
41+
sudo apt-get -y install curl parallel \
42+
fish="${fish_apt_semver}" \
43+
powershell="${powershell_apt_semver}"
44+
45+
# Create $HOME/bin
46+
mkdir -p "$HOME/bin"
47+
48+
# Download elvish binary and add to path
49+
curl https://dl.elv.sh/linux-amd64/elvish-${elvish_semver}.tar.gz -o elvish-${elvish_semver}.tar.gz
50+
tar xzf elvish-${elvish_semver}.tar.gz
51+
rm elvish-${elvish_semver}.tar.gz
52+
mv elvish-${elvish_semver} "$HOME/bin/elvish"
53+
54+
# Download nushell binary and add to path
55+
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
56+
tar xzf nu-${nushell_semver}-x86_64-unknown-linux-gnu.tar.gz
57+
rm nu-${nushell_semver}-x86_64-unknown-linux-gnu.tar.gz
58+
mv nu-${nushell_semver}-x86_64-unknown-linux-gnu/* "$HOME/bin"
59+
60+
# Add $HOME/bin to path (add Elvish & Nushell to path)
61+
echo "$HOME/bin" >>"$GITHUB_PATH"
62+
fi
63+
64+
### Install dependencies on macOS
65+
if [ "$RUNNER_OS" = "macOS" ]; then
66+
printf "%s\n" "Installing dependencies on macOS"
67+
brew install coreutils parallel \
68+
elvish \
69+
fish \
70+
nushell \
71+
powershell
72+
fi
73+
74+
### Install bats-core
75+
printf "%s\n" "Installing bats-core"
76+
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"
77+
echo "$HOME/bats-core/bin" >>"$GITHUB_PATH"

0 commit comments

Comments
 (0)