Skip to content

Commit a49ab49

Browse files
authored
chore: minor changes (#8)
* refactor(go-air): move all pre-installation checks into check_packages * refactor(lefthook): consolidate pre-install checks into check_packages - Move all pre-installation checks into `check_packages` - Add fallback to latest version when previous version is not found * refactor(protolint): add fallback to latest version when previous version is not found * test(protolint): fix test scenario * chore(vscode): change launch test configurations - Remove --skip-scenarios argument - Set ubuntu as default base image * ci: simplify test workflow Remove test-autogenerated and change test-scenarios to avoid outdated test configuration
1 parent d3c2fe8 commit a49ab49

10 files changed

Lines changed: 49 additions & 50 deletions

File tree

.github/workflows/test.yaml

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,42 +7,22 @@ on:
77
workflow_dispatch:
88

99
jobs:
10-
test-autogenerated:
11-
runs-on: ubuntu-latest
12-
continue-on-error: true
13-
strategy:
14-
matrix:
15-
features:
16-
- lefthook
17-
baseImage:
18-
- debian:latest
19-
- ubuntu:latest
20-
- mcr.microsoft.com/devcontainers/base:ubuntu
21-
steps:
22-
- uses: actions/checkout@v4
23-
24-
- name: "Install latest devcontainer CLI"
25-
run: npm install -g @devcontainers/cli
26-
27-
- name: "Generating tests for '${{ matrix.features }}' against '${{ matrix.baseImage }}'"
28-
run: devcontainer features test --skip-scenarios -f ${{ matrix.features }} -i ${{ matrix.baseImage }} .
29-
3010
test-scenarios:
3111
runs-on: ubuntu-latest
3212
continue-on-error: true
3313
strategy:
3414
matrix:
35-
features:
36-
- lefthook
37-
- go-air
15+
images:
16+
- mcr.microsoft.com/devcontainers/base:debian
17+
- mcr.microsoft.com/devcontainers/base:ubuntu
3818
steps:
3919
- uses: actions/checkout@v4
4020

4121
- name: "Install latest devcontainer CLI"
4222
run: npm install -g @devcontainers/cli
4323

44-
- name: "Generating tests for '${{ matrix.features }}' scenarios"
45-
run: devcontainer features test -f ${{ matrix.features }} --skip-autogenerated --skip-duplicated .
24+
- name: "Generating tests for all scenarios against ${{ matrix.images }}"
25+
run: devcontainer features test -i ${{ matrix.images }} .
4626

4727
test-global:
4828
runs-on: ubuntu-latest

.vscode/launch.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
"args": [
2222
"features",
2323
"test",
24-
"--skip-scenarios",
2524
"-f",
2625
"${input:selectedFeatures}",
2726
"-i",
@@ -59,7 +58,7 @@
5958
"id": "selectedBaseImage",
6059
"type": "promptString",
6160
"description": "Base Image",
62-
"default": "mcr.microsoft.com/vscode/devcontainers/base:ubuntu"
61+
"default": "mcr.microsoft.com/vscode/devcontainers/base:debian"
6362
}
6463
]
6564
}

src/go-air/devcontainer-feature.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "Air",
33
"id": "go-air",
4-
"version": "1.1.0",
4+
"version": "1.1.1",
55
"documentationURL": "http://github.com/omoxyz/devcontainer-features/tree/main/src/go-air",
66
"description": "Install Air live reloader for Go apps.",
77
"options": {

src/go-air/install.sh

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,8 @@ install_from_github() {
7676
rm -rf /tmp/air
7777
}
7878

79-
# Install curl if missing
80-
check_packages curl ca-certificates
81-
82-
# Install git if missing
83-
if ! type git > /dev/null 2>&1; then
84-
check_packages git
85-
fi
79+
# Install curl, git if missing
80+
check_packages curl ca-certificates git
8681

8782
version_list=$(git ls-remote --tags ${GITHUB_REPO})
8883

src/go-air/utils.sh

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,24 @@ apt_get_update() {
1010

1111
# Checks if packages are installed and installs them if not
1212
check_packages() {
13-
if ! dpkg -s "$@" > /dev/null 2>&1; then
13+
for pkg in "$@"; do
14+
# Check if it's a command in PATH
15+
if command -v "$pkg" &> /dev/null; then
16+
echo "[OK] $pkg found in PATH"
17+
continue
18+
fi
19+
20+
# Check if it's a Debian/Ubuntu package installed
21+
if dpkg -s "$pkg" &> /dev/null; then
22+
echo "[OK] $pkg package installed"
23+
continue
24+
fi
25+
26+
# If not found, install package
27+
echo "$pkg not found. Installing..."
1428
apt_get_update
15-
echo "Installing $@..."
16-
apt-get install -y --no-install-recommends $@
17-
fi
29+
apt-get install -y --no-install-recommends $pkg
30+
done
1831
}
1932

2033
# Find 2 latest versions that appropriate to requested version

src/lefthook/devcontainer-feature.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "Lefthook",
33
"id": "lefthook",
4-
"version": "1.0.2",
4+
"version": "1.0.3",
55
"documentationURL": "http://github.com/omoxyz/devcontainer-features/tree/main/src/lefthook",
66
"description": "Install Lefthook fast polyglot Git hooks manager.",
77
"options": {

src/lefthook/install.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ install_from_github() {
3737
fi
3838

3939
latest_version=${versions[0]}
40-
prev_version=${versions[1]}
40+
prev_version=${versions[1]:-$latest_version}
4141

4242

4343
echo "Downloading lefthook v${latest_version}...."
@@ -90,9 +90,7 @@ check_packages curl ca-certificates
9090
# Install Lefthook
9191
if [ "${INSTALL_DIRECTLY_FROM_GITHUB_RELEASE}" = "true" ]; then
9292
# Install git if missing
93-
if ! type git > /dev/null 2>&1; then
94-
check_packages git
95-
fi
93+
check_packages git
9694

9795
install_from_github
9896
else

src/lefthook/utils.sh

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,25 @@ apt_get_update() {
1010

1111
# Checks if packages are installed and installs them if not
1212
check_packages() {
13-
if ! dpkg -s "$@" > /dev/null 2>&1; then
13+
for pkg in "$@"; do
14+
# Check if it's a command in PATH
15+
if command -v "$pkg" &> /dev/null; then
16+
echo "[OK] $pkg found in PATH"
17+
continue
18+
fi
19+
20+
# Check if it's a Debian/Ubuntu package installed
21+
if dpkg -s "$pkg" &> /dev/null; then
22+
echo "[OK] $pkg package installed"
23+
continue
24+
fi
25+
26+
# If not found, install package
27+
echo "$pkg not found. Installing..."
1428
apt_get_update
15-
echo "Installing $@..."
16-
apt-get install -y --no-install-recommends $@
17-
fi
29+
apt-get install -y --no-install-recommends $pkg
30+
31+
done
1832
}
1933

2034
# Find 2 latest versions that appropriate to requested version

src/protolint/install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ install_from_github() {
3737
fi
3838

3939
latest_version=${versions[0]}
40-
prev_version=${versions[1]}
40+
prev_version=${versions[1]:-$latest_version}
4141

4242
echo "Downloading protolint v${latest_version}...."
4343

test/protolint/scenarios.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"test": {
33
"image": "mcr.microsoft.com/devcontainers/base:debian",
44
"features": {
5-
"protoc": {}
5+
"protolint": {}
66
}
77
}
88
}

0 commit comments

Comments
 (0)