Skip to content

Commit 439c48e

Browse files
committed
feat: add alias support and QA tooling
1 parent e80d869 commit 439c48e

11 files changed

Lines changed: 1230 additions & 0 deletions

File tree

.github/workflows/quality.yml

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
name: Quality Assurance
2+
3+
on:
4+
push:
5+
branches: [main, development, 'fix/**', 'feature/**']
6+
pull_request:
7+
branches: [main, development]
8+
workflow_dispatch:
9+
10+
jobs:
11+
# Linting and formatting checks
12+
lint:
13+
name: 'Lint & Format Check'
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout Repository
17+
uses: actions/checkout@v4
18+
19+
- name: Install ShellCheck
20+
run: |
21+
sudo apt-get update
22+
sudo apt-get install -y shellcheck
23+
24+
- name: Install shfmt
25+
run: |
26+
wget -O shfmt https://github.com/mvdan/sh/releases/latest/download/shfmt_v3.8.0_linux_amd64
27+
chmod +x shfmt
28+
sudo mv shfmt /usr/local/bin/
29+
30+
- name: Run ShellCheck
31+
run: |
32+
echo "Running ShellCheck..."
33+
shellcheck phpvm.sh install.sh || exit 1
34+
35+
- name: Check Code Formatting
36+
run: |
37+
echo "Checking code formatting..."
38+
shfmt -d -i 4 -sr phpvm.sh install.sh || {
39+
echo "Code formatting issues detected!"
40+
echo "Run 'make format' locally to fix."
41+
exit 1
42+
}
43+
44+
- name: Check for Common Issues
45+
run: |
46+
echo "Checking for common issues..."
47+
48+
# Check for trailing whitespace
49+
if grep -n '[[:space:]]$' phpvm.sh install.sh; then
50+
echo "Trailing whitespace found (see above)"
51+
exit 1
52+
fi
53+
54+
# Check for tabs (should use spaces)
55+
if grep -P '\t' phpvm.sh install.sh; then
56+
echo "Tabs found - please use spaces for indentation"
57+
exit 1
58+
fi
59+
60+
echo "No common issues found!"
61+
62+
# BATS test suite
63+
bats-tests:
64+
name: 'BATS Tests (${{ matrix.os }})'
65+
runs-on: ${{ matrix.os }}
66+
needs: lint
67+
strategy:
68+
fail-fast: false
69+
matrix:
70+
os: [ubuntu-latest, macos-latest]
71+
72+
steps:
73+
- name: Checkout Repository
74+
uses: actions/checkout@v4
75+
76+
- name: Install BATS
77+
run: |
78+
if [ "${{ matrix.os }}" = "macos-latest" ]; then
79+
brew install bats-core
80+
else
81+
sudo apt-get update
82+
sudo apt-get install -y bats
83+
fi
84+
85+
- name: Run BATS Test Suite
86+
run: |
87+
echo "Running BATS tests..."
88+
bats tests/ -t
89+
90+
- name: Upload Test Results
91+
if: always()
92+
uses: actions/upload-artifact@v4
93+
with:
94+
name: bats-results-${{ matrix.os }}
95+
path: test-results/
96+
retention-days: 30
97+
98+
# Built-in phpvm tests
99+
builtin-tests:
100+
name: 'Built-in Tests (${{ matrix.os }})'
101+
runs-on: ${{ matrix.os }}
102+
needs: lint
103+
strategy:
104+
fail-fast: false
105+
matrix:
106+
os: [ubuntu-latest, macos-latest]
107+
108+
steps:
109+
- name: Checkout Repository
110+
uses: actions/checkout@v4
111+
112+
- name: Run phpvm Built-in Tests
113+
run: |
114+
echo "Running built-in tests..."
115+
bash phpvm.sh test
116+
117+
# Integration tests - Test with actual PHP installations
118+
integration-tests:
119+
name: 'Integration Tests (${{ matrix.os }})'
120+
runs-on: ${{ matrix.os }}
121+
needs: [lint, bats-tests, builtin-tests]
122+
strategy:
123+
fail-fast: false
124+
matrix:
125+
os: [ubuntu-latest, macos-latest]
126+
127+
steps:
128+
- name: Checkout Repository
129+
uses: actions/checkout@v4
130+
131+
- name: Setup Test Environment
132+
run: |
133+
export PHPVM_DIR="$HOME/.phpvm-test"
134+
mkdir -p "$PHPVM_DIR"
135+
./install.sh
136+
137+
- name: Test PHP Installation (macOS)
138+
if: matrix.os == 'macos-latest'
139+
run: |
140+
source "$HOME/.phpvm-test/phpvm.sh"
141+
142+
# Test install
143+
phpvm install 8.2 || echo "PHP 8.2 already installed"
144+
145+
# Test use
146+
phpvm use 8.2
147+
148+
# Verify PHP version
149+
php -v
150+
151+
# Test current
152+
phpvm current
153+
154+
- name: Test PHP Installation (Ubuntu)
155+
if: matrix.os == 'ubuntu-latest'
156+
run: |
157+
source "$HOME/.phpvm-test/phpvm.sh"
158+
159+
# Add repository
160+
sudo add-apt-repository -y ppa:ondrej/php
161+
sudo apt-get update
162+
163+
# Test install
164+
phpvm install 8.2 || echo "PHP 8.2 installation attempted"
165+
166+
# Test current
167+
phpvm current || echo "No active version yet"
168+
169+
- name: Cleanup
170+
if: always()
171+
run: |
172+
rm -rf "$HOME/.phpvm-test"
173+
174+
# Quality gate - All checks must pass
175+
quality-gate:
176+
name: 'Quality Gate'
177+
runs-on: ubuntu-latest
178+
needs: [lint, bats-tests, builtin-tests]
179+
if: always()
180+
steps:
181+
- name: Check All Jobs
182+
run: |
183+
if [ "${{ needs.lint.result }}" != "success" ]; then
184+
echo "Linting failed!"
185+
exit 1
186+
fi
187+
if [ "${{ needs.bats-tests.result }}" != "success" ]; then
188+
echo "BATS tests failed!"
189+
exit 1
190+
fi
191+
if [ "${{ needs.builtin-tests.result }}" != "success" ]; then
192+
echo "Built-in tests failed!"
193+
exit 1
194+
fi
195+
echo "All quality checks passed! ✅"

.shellcheckrc

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# ShellCheck configuration for phpvm
2+
# See https://github.com/koalaman/shellcheck/wiki
3+
4+
# Disable specific checks that are intentional or not applicable
5+
6+
# SC2155: Declare and assign separately to avoid masking return values
7+
# We use this pattern intentionally for readability in some cases
8+
disable=SC2155
9+
10+
# SC1091: Not following: file not included in repository
11+
# We source files that may not exist yet
12+
disable=SC1091
13+
14+
# SC2317: Command appears to be unreachable (in functions)
15+
# False positives with our function structure
16+
disable=SC2317
17+
18+
# SC2034: Variable appears unused
19+
# Some variables are used in eval or sourced contexts
20+
disable=SC2034
21+
22+
# Enable optional checks
23+
enable=quote-safe-variables
24+
enable=require-variable-braces
25+
enable=check-unassigned-uppercase
26+
27+
# Set shell to bash
28+
shell=bash
29+
30+
# External sources that we know about
31+
source-path=SCRIPTDIR
32+
33+
# Exclude patterns
34+
exclude=SC1090,SC1091

.shfmt.config

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# shfmt configuration for phpvm
2+
# Format: bash
3+
# See https://github.com/mvdan/sh
4+
5+
# Use bash syntax
6+
--language-dialect bash
7+
8+
# Indent with 4 spaces (matches .editorconfig)
9+
--indent 4
10+
11+
# Use spaces for indentation
12+
--space-redirects
13+
14+
# Simplify code
15+
--simplify
16+
17+
# Keep column alignment for readability
18+
# (don't use --minify)

.vscode/settings.json

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,49 @@
1010
},
1111
"**/*.js.map": true,
1212
".mule": true
13+
},
14+
// Shell script settings
15+
"shellcheck.enable": true,
16+
"shellcheck.run": "onType",
17+
"shellcheck.executablePath": "shellcheck",
18+
"[shellscript]": {
19+
"editor.formatOnSave": false,
20+
"editor.tabSize": 4,
21+
"editor.insertSpaces": true
22+
},
23+
// File associations
24+
"files.associations": {
25+
"*.sh": "shellscript",
26+
".shellcheckrc": "properties",
27+
"Makefile": "makefile"
28+
},
29+
// Markdown settings
30+
"[markdown]": {
31+
"editor.formatOnSave": true,
32+
"editor.wordWrap": "on",
33+
"editor.quickSuggestions": {
34+
"comments": "off",
35+
"strings": "off",
36+
"other": "off"
37+
}
38+
},
39+
// Terminal settings
40+
"terminal.integrated.env.osx": {
41+
"PHPVM_DIR": "${env:HOME}/.phpvm"
42+
},
43+
"terminal.integrated.env.linux": {
44+
"PHPVM_DIR": "${env:HOME}/.phpvm"
45+
},
46+
// Testing
47+
"bats.enabled": true,
48+
// Git
49+
"git.ignoreLimitWarning": true,
50+
// Search exclusions
51+
"search.exclude": {
52+
"**/node_modules": true,
53+
"**/bower_components": true,
54+
"**/.phpvm": true,
55+
"**/versions": true,
56+
"**/.git": true
1357
}
1458
}

0 commit comments

Comments
 (0)