opsscript-gate 0.2.1__tar.gz → 0.4.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {opsscript_gate-0.2.1 → opsscript_gate-0.4.0}/.github/workflows/demo.yml +2 -0
- opsscript_gate-0.4.0/.github/workflows/release.yml +213 -0
- {opsscript_gate-0.2.1 → opsscript_gate-0.4.0}/CHANGELOG.md +34 -0
- opsscript_gate-0.4.0/PKG-INFO +301 -0
- opsscript_gate-0.4.0/README.md +273 -0
- opsscript_gate-0.4.0/ROADMAP.md +44 -0
- {opsscript_gate-0.2.1 → opsscript_gate-0.4.0}/SECURITY.md +9 -5
- {opsscript_gate-0.2.1 → opsscript_gate-0.4.0}/action.yml +34 -6
- opsscript_gate-0.4.0/docs/promotion/awesome-lists-pr.md +59 -0
- opsscript_gate-0.4.0/docs/promotion/juejin-zhihu-article.md +144 -0
- opsscript_gate-0.4.0/docs/promotion/reddit-devops.md +56 -0
- opsscript_gate-0.4.0/docs/promotion/show-hn.md +67 -0
- opsscript_gate-0.4.0/docs/promotion/v2ex-post.md +68 -0
- {opsscript_gate-0.2.1 → opsscript_gate-0.4.0}/examples/github-actions/workflow.yml +2 -1
- {opsscript_gate-0.2.1 → opsscript_gate-0.4.0}/pyproject.toml +1 -1
- {opsscript_gate-0.2.1 → opsscript_gate-0.4.0}/src/opsscript_gate/__init__.py +1 -1
- opsscript_gate-0.4.0/src/opsscript_gate/cli.py +233 -0
- opsscript_gate-0.4.0/src/opsscript_gate/discovery.py +106 -0
- {opsscript_gate-0.2.1 → opsscript_gate-0.4.0}/src/opsscript_gate/models.py +49 -0
- opsscript_gate-0.4.0/src/opsscript_gate/remediation.py +104 -0
- opsscript_gate-0.4.0/src/opsscript_gate/reporter.py +368 -0
- {opsscript_gate-0.2.1 → opsscript_gate-0.4.0}/src/opsscript_gate/runner.py +166 -9
- {opsscript_gate-0.2.1 → opsscript_gate-0.4.0}/tests/test_runner.py +615 -2
- opsscript_gate-0.2.1/.github/workflows/release.yml +0 -121
- opsscript_gate-0.2.1/PKG-INFO +0 -277
- opsscript_gate-0.2.1/README.md +0 -249
- opsscript_gate-0.2.1/ROADMAP.md +0 -33
- opsscript_gate-0.2.1/src/opsscript_gate/cli.py +0 -136
- opsscript_gate-0.2.1/src/opsscript_gate/reporter.py +0 -158
- {opsscript_gate-0.2.1 → opsscript_gate-0.4.0}/.gitattributes +0 -0
- {opsscript_gate-0.2.1 → opsscript_gate-0.4.0}/.github/ISSUE_TEMPLATE/bug_report.yml +0 -0
- {opsscript_gate-0.2.1 → opsscript_gate-0.4.0}/.github/ISSUE_TEMPLATE/distro_request.yml +0 -0
- {opsscript_gate-0.2.1 → opsscript_gate-0.4.0}/.github/ISSUE_TEMPLATE/feature_request.yml +0 -0
- {opsscript_gate-0.2.1 → opsscript_gate-0.4.0}/.github/assets/social-preview.png +0 -0
- {opsscript_gate-0.2.1 → opsscript_gate-0.4.0}/.github/pull_request_template.md +0 -0
- {opsscript_gate-0.2.1 → opsscript_gate-0.4.0}/.github/workflows/test.yml +0 -0
- {opsscript_gate-0.2.1 → opsscript_gate-0.4.0}/.gitignore +0 -0
- {opsscript_gate-0.2.1 → opsscript_gate-0.4.0}/CONTRIBUTING.md +0 -0
- {opsscript_gate-0.2.1 → opsscript_gate-0.4.0}/LICENSE +0 -0
- {opsscript_gate-0.2.1 → opsscript_gate-0.4.0}/examples/alpine-incompatibility/README.md +0 -0
- {opsscript_gate-0.2.1 → opsscript_gate-0.4.0}/examples/alpine-incompatibility/apt_dependency.sh +0 -0
- {opsscript_gate-0.2.1 → opsscript_gate-0.4.0}/examples/basic/README.md +0 -0
- {opsscript_gate-0.2.1 → opsscript_gate-0.4.0}/examples/basic/clean_setup.sh +0 -0
- {opsscript_gate-0.2.1 → opsscript_gate-0.4.0}/examples/github-actions/README.md +0 -0
- {opsscript_gate-0.2.1 → opsscript_gate-0.4.0}/examples/interactive-hang/README.md +0 -0
- {opsscript_gate-0.2.1 → opsscript_gate-0.4.0}/examples/interactive-hang/prompt_confirm.sh +0 -0
- {opsscript_gate-0.2.1 → opsscript_gate-0.4.0}/tests/fixtures/fail_deps.sh +0 -0
- {opsscript_gate-0.2.1 → opsscript_gate-0.4.0}/tests/fixtures/fail_hang.sh +0 -0
- {opsscript_gate-0.2.1 → opsscript_gate-0.4.0}/tests/fixtures/pass_basic.sh +0 -0
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
name: Build and Release
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
tags:
|
|
8
|
+
- 'v*'
|
|
9
|
+
workflow_dispatch:
|
|
10
|
+
|
|
11
|
+
concurrency:
|
|
12
|
+
group: opsscript-gate-release
|
|
13
|
+
cancel-in-progress: false
|
|
14
|
+
queue: max
|
|
15
|
+
|
|
16
|
+
permissions:
|
|
17
|
+
contents: read
|
|
18
|
+
|
|
19
|
+
jobs:
|
|
20
|
+
test:
|
|
21
|
+
name: Run Test Suite
|
|
22
|
+
runs-on: ubuntu-latest
|
|
23
|
+
steps:
|
|
24
|
+
- name: Checkout Code
|
|
25
|
+
uses: actions/checkout@v7
|
|
26
|
+
|
|
27
|
+
- name: Set up Python
|
|
28
|
+
uses: actions/setup-python@v7
|
|
29
|
+
with:
|
|
30
|
+
python-version: '3.12'
|
|
31
|
+
|
|
32
|
+
- name: Install Dependencies
|
|
33
|
+
run: |
|
|
34
|
+
python -m pip install --upgrade pip
|
|
35
|
+
pip install -e .[test]
|
|
36
|
+
|
|
37
|
+
- name: Run Tests
|
|
38
|
+
run: |
|
|
39
|
+
pytest -v -m "not integration"
|
|
40
|
+
|
|
41
|
+
integration:
|
|
42
|
+
name: Docker Integration Tests
|
|
43
|
+
runs-on: ubuntu-latest
|
|
44
|
+
steps:
|
|
45
|
+
- name: Checkout Code
|
|
46
|
+
uses: actions/checkout@v7
|
|
47
|
+
|
|
48
|
+
- name: Set up Python
|
|
49
|
+
uses: actions/setup-python@v7
|
|
50
|
+
with:
|
|
51
|
+
python-version: '3.12'
|
|
52
|
+
|
|
53
|
+
- name: Install Dependencies
|
|
54
|
+
run: |
|
|
55
|
+
python -m pip install --upgrade pip
|
|
56
|
+
pip install -e .[test]
|
|
57
|
+
|
|
58
|
+
- name: Verify Docker Available
|
|
59
|
+
run: docker version
|
|
60
|
+
|
|
61
|
+
- name: Run Docker Integration Tests
|
|
62
|
+
run: |
|
|
63
|
+
pytest -v -m integration
|
|
64
|
+
|
|
65
|
+
build:
|
|
66
|
+
name: Build Distribution Packages
|
|
67
|
+
needs: [test, integration]
|
|
68
|
+
runs-on: ubuntu-latest
|
|
69
|
+
permissions:
|
|
70
|
+
contents: write
|
|
71
|
+
outputs:
|
|
72
|
+
is_new_release: ${{ steps.release-check.outputs.is_new_release }}
|
|
73
|
+
should_tag: ${{ steps.release-check.outputs.should_tag }}
|
|
74
|
+
release_tag: ${{ steps.release-check.outputs.release_tag }}
|
|
75
|
+
steps:
|
|
76
|
+
- name: Checkout Code
|
|
77
|
+
uses: actions/checkout@v7
|
|
78
|
+
with:
|
|
79
|
+
fetch-depth: 0
|
|
80
|
+
|
|
81
|
+
- name: Set up Python
|
|
82
|
+
uses: actions/setup-python@v7
|
|
83
|
+
with:
|
|
84
|
+
python-version: '3.12'
|
|
85
|
+
|
|
86
|
+
- name: Determine Release Readiness
|
|
87
|
+
id: release-check
|
|
88
|
+
shell: bash
|
|
89
|
+
run: |
|
|
90
|
+
set -euo pipefail
|
|
91
|
+
|
|
92
|
+
TOML_VERSION=$(python -c "import tomllib; f=open('pyproject.toml', 'rb'); print(tomllib.load(f)['project']['version'])")
|
|
93
|
+
INIT_VERSION=$(python -c "import sys; sys.path.insert(0, 'src'); import opsscript_gate; print(opsscript_gate.__version__)")
|
|
94
|
+
|
|
95
|
+
echo "pyproject.toml version: $TOML_VERSION"
|
|
96
|
+
echo "opsscript_gate version: $INIT_VERSION"
|
|
97
|
+
|
|
98
|
+
if [ "$TOML_VERSION" != "$INIT_VERSION" ]; then
|
|
99
|
+
echo "::error::Version mismatch: pyproject.toml ($TOML_VERSION) != __init__.py ($INIT_VERSION)"
|
|
100
|
+
exit 1
|
|
101
|
+
fi
|
|
102
|
+
|
|
103
|
+
TARGET_TAG="v$TOML_VERSION"
|
|
104
|
+
echo "Target release tag: $TARGET_TAG"
|
|
105
|
+
echo "Triggering ref: ${{ github.ref }}"
|
|
106
|
+
echo "Triggering SHA: ${{ github.sha }}"
|
|
107
|
+
echo "Triggering event: ${{ github.event_name }}"
|
|
108
|
+
|
|
109
|
+
IS_NEW_RELEASE="false"
|
|
110
|
+
SHOULD_TAG="false"
|
|
111
|
+
|
|
112
|
+
if [[ "${{ github.ref }}" =~ ^refs/tags/v ]]; then
|
|
113
|
+
TAG_VERSION="${GITHUB_REF_NAME#v}"
|
|
114
|
+
echo "Triggered via explicit Git tag: $GITHUB_REF_NAME (version: $TAG_VERSION)"
|
|
115
|
+
if [ "$TAG_VERSION" != "$TOML_VERSION" ]; then
|
|
116
|
+
echo "::error::Tag mismatch: Git tag $GITHUB_REF_NAME does not match project version $TOML_VERSION"
|
|
117
|
+
exit 1
|
|
118
|
+
fi
|
|
119
|
+
IS_NEW_RELEASE="true"
|
|
120
|
+
SHOULD_TAG="false"
|
|
121
|
+
elif [ "${{ github.ref }}" = "refs/heads/main" ]; then
|
|
122
|
+
if git rev-parse -q --verify "refs/tags/$TARGET_TAG" >/dev/null; then
|
|
123
|
+
TAG_SHA=$(git rev-list -n 1 "$TARGET_TAG")
|
|
124
|
+
echo "Tag $TARGET_TAG already exists, pointing to commit: $TAG_SHA"
|
|
125
|
+
if [ "$TAG_SHA" = "${{ github.sha }}" ]; then
|
|
126
|
+
echo "Tag $TARGET_TAG points to current commit (${{ github.sha }}). Treating as retry/resume of release."
|
|
127
|
+
IS_NEW_RELEASE="true"
|
|
128
|
+
SHOULD_TAG="false"
|
|
129
|
+
else
|
|
130
|
+
echo "Tag $TARGET_TAG was released from earlier commit ($TAG_SHA != ${{ github.sha }}). Skipping release."
|
|
131
|
+
IS_NEW_RELEASE="false"
|
|
132
|
+
SHOULD_TAG="false"
|
|
133
|
+
fi
|
|
134
|
+
else
|
|
135
|
+
echo "Target tag $TARGET_TAG does not exist. Scheduling new release for commit ${{ github.sha }}."
|
|
136
|
+
IS_NEW_RELEASE="true"
|
|
137
|
+
SHOULD_TAG="true"
|
|
138
|
+
fi
|
|
139
|
+
else
|
|
140
|
+
echo "Workflow triggered on unsupported ref (${{ github.ref }}). Release is strictly prohibited."
|
|
141
|
+
IS_NEW_RELEASE="false"
|
|
142
|
+
SHOULD_TAG="false"
|
|
143
|
+
fi
|
|
144
|
+
|
|
145
|
+
echo "is_new_release=$IS_NEW_RELEASE" >> "$GITHUB_OUTPUT"
|
|
146
|
+
echo "should_tag=$SHOULD_TAG" >> "$GITHUB_OUTPUT"
|
|
147
|
+
echo "release_tag=$TARGET_TAG" >> "$GITHUB_OUTPUT"
|
|
148
|
+
|
|
149
|
+
- name: Install build tools
|
|
150
|
+
if: steps.release-check.outputs.is_new_release == 'true'
|
|
151
|
+
run: |
|
|
152
|
+
python -m pip install --upgrade pip
|
|
153
|
+
pip install build twine
|
|
154
|
+
|
|
155
|
+
- name: Build sdist and wheel
|
|
156
|
+
if: steps.release-check.outputs.is_new_release == 'true'
|
|
157
|
+
run: |
|
|
158
|
+
python -m build
|
|
159
|
+
|
|
160
|
+
- name: Verify Package Metadata
|
|
161
|
+
if: steps.release-check.outputs.is_new_release == 'true'
|
|
162
|
+
run: |
|
|
163
|
+
python -m twine check dist/*
|
|
164
|
+
|
|
165
|
+
- name: Upload dist artifacts
|
|
166
|
+
if: steps.release-check.outputs.is_new_release == 'true'
|
|
167
|
+
uses: actions/upload-artifact@v4
|
|
168
|
+
with:
|
|
169
|
+
name: dist
|
|
170
|
+
path: dist/
|
|
171
|
+
retention-days: 7
|
|
172
|
+
|
|
173
|
+
- name: Create and push Git tag
|
|
174
|
+
if: steps.release-check.outputs.is_new_release == 'true' && steps.release-check.outputs.should_tag == 'true'
|
|
175
|
+
shell: bash
|
|
176
|
+
run: |
|
|
177
|
+
TARGET_TAG="${{ steps.release-check.outputs.release_tag }}"
|
|
178
|
+
echo "Creating and pushing Git tag: $TARGET_TAG pointing to commit $GITHUB_SHA"
|
|
179
|
+
git config user.name "github-actions[bot]"
|
|
180
|
+
git config user.email "github-actions[bot]@users.noreply.github.com"
|
|
181
|
+
git tag "$TARGET_TAG" "$GITHUB_SHA"
|
|
182
|
+
git push origin "$TARGET_TAG"
|
|
183
|
+
|
|
184
|
+
- name: Create GitHub Release and Upload Assets
|
|
185
|
+
uses: softprops/action-gh-release@v3
|
|
186
|
+
if: steps.release-check.outputs.is_new_release == 'true'
|
|
187
|
+
with:
|
|
188
|
+
tag_name: ${{ steps.release-check.outputs.release_tag }}
|
|
189
|
+
target_commitish: ${{ github.sha }}
|
|
190
|
+
files: dist/*
|
|
191
|
+
generate_release_notes: true
|
|
192
|
+
|
|
193
|
+
publish-pypi:
|
|
194
|
+
name: Publish to PyPI via OIDC
|
|
195
|
+
needs: [test, build]
|
|
196
|
+
if: needs.build.outputs.is_new_release == 'true'
|
|
197
|
+
runs-on: ubuntu-latest
|
|
198
|
+
environment:
|
|
199
|
+
name: pypi
|
|
200
|
+
url: https://pypi.org/p/opsscript-gate
|
|
201
|
+
permissions:
|
|
202
|
+
id-token: write
|
|
203
|
+
steps:
|
|
204
|
+
- name: Download dist artifacts
|
|
205
|
+
uses: actions/download-artifact@v4
|
|
206
|
+
with:
|
|
207
|
+
name: dist
|
|
208
|
+
path: dist
|
|
209
|
+
|
|
210
|
+
- name: Publish package distributions to PyPI
|
|
211
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
212
|
+
with:
|
|
213
|
+
packages-dir: dist/
|
|
@@ -5,6 +5,40 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [0.4.0] - 2026-09-19
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- **High-confidence line-level GitHub Actions annotations**: Emits inline `::error` annotations with exact script line numbers directly on pull request file diffs.
|
|
12
|
+
- **Workflow command injection defense**: Strictly escapes parameters (`%`, `\r`, `\n`, `:`, `,`) and message bodies (`%`, `\r`, `\n`) to eliminate command injection from unclassified container logs.
|
|
13
|
+
- **Conservative distro-aware remediation hints**: Suggests testable, high-confidence remediation recommendations (`RemediationRule`) with conservative phrasing (`normally`, `may`, `consider`), covering:
|
|
14
|
+
- Alpine package manager mismatches (`apt`/`apt-get` -> `apk`)
|
|
15
|
+
- Debian/Ubuntu package manager mismatches (`apk` -> `apt-get`)
|
|
16
|
+
- Alpine minimal missing Bash (`bash` -> consider POSIX sh or installing bash)
|
|
17
|
+
- Missing network prerequisites (`curl`, `wget`)
|
|
18
|
+
- Missing shebang interpreter paths.
|
|
19
|
+
- **Re-engineered Compatibility Card**: Overhauled GitHub Actions Step Summary with an instant 5-second triage table and an expandable copy-pasteable Markdown snippet ready for PR descriptions and Issue comments.
|
|
20
|
+
- **Parallel matrix execution (`--jobs` / `jobs`)**: Concurrently runs container checks using `ThreadPoolExecutor` (defaults to `min(2, matrix_size)`), strictly preserving matrix output order and ensuring reliable container cleanup.
|
|
21
|
+
- **Hardened container resource limits**: Added `--mem-limit` (default: 256m) and `--pids-limit` (default: 128) flags and Action inputs to prevent runaway resource exhaustion.
|
|
22
|
+
- **Configurable network isolation (`--network`)**: Supports `--network bridge` (default) and `--network none` for offline script execution.
|
|
23
|
+
- **Zero-config repository script auto-discovery**: Running `opsscript-gate run` without arguments automatically discovers and validates shell scripts in the repository, ignoring directories like `.git`, `node_modules`, and `.venv`, capped at 20 scripts and 1 MB per file.
|
|
24
|
+
- **Multi-script test consolidation (`MultiScriptReport`)**: Supports aggregate reporting and Step Summary cards when multiple scripts are evaluated in a single run.
|
|
25
|
+
|
|
26
|
+
### Changed
|
|
27
|
+
- **Action initialization performance**: Removed redundant `pip install --upgrade pip` step in composite `action.yml` to minimize Action startup latency.
|
|
28
|
+
- **Flexible Action inputs**: Made `script-path` optional in `action.yml` (triggers auto-discovery if omitted); added inputs `jobs`, `mem-limit`, `pids-limit`, and `network`.
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## [0.3.0] - 2026-09-19
|
|
33
|
+
|
|
34
|
+
### Added
|
|
35
|
+
- Structured runtime failure diagnostics: detect common "command not found" failures across Linux distributions (Alpine/BusyBox ash, Debian/Ubuntu dash, Bash, and missing interpreter paths).
|
|
36
|
+
- High-confidence dual-signal classification: requires exit code 127 and matching shell output to produce a `missing_command` diagnostic.
|
|
37
|
+
- Additive `diagnostic` field in JSON report format (`SingleResult.to_dict()`) providing structured diagnostic information (backward-compatible for consumers tolerating additional fields).
|
|
38
|
+
- Enhanced terminal table formatting and GitHub Actions Step Summary showing clear failure causes in the summary overview.
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
8
42
|
## [0.2.1] - 2026-09-19
|
|
9
43
|
|
|
10
44
|
### Fixed
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: opsscript-gate
|
|
3
|
+
Version: 0.4.0
|
|
4
|
+
Summary: Run Linux shell scripts across Debian, Ubuntu and Alpine before release to catch runtime compatibility failures
|
|
5
|
+
Project-URL: Homepage, https://github.com/Mresyzz/opsscript-gate
|
|
6
|
+
Project-URL: Repository, https://github.com/Mresyzz/opsscript-gate
|
|
7
|
+
Project-URL: Issues, https://github.com/Mresyzz/opsscript-gate/issues
|
|
8
|
+
Project-URL: Changelog, https://github.com/Mresyzz/opsscript-gate/blob/main/CHANGELOG.md
|
|
9
|
+
Author: Mresyzz
|
|
10
|
+
License: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: ci,compatibility,cross-distro,devops,docker,github-actions,linux,posix,shell,testing
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Intended Audience :: System Administrators
|
|
16
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Topic :: Software Development :: Testing
|
|
22
|
+
Classifier: Topic :: System :: Systems Administration
|
|
23
|
+
Requires-Python: >=3.10
|
|
24
|
+
Requires-Dist: docker>=7.0.0
|
|
25
|
+
Provides-Extra: test
|
|
26
|
+
Requires-Dist: pytest>=8.0.0; extra == 'test'
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
|
|
29
|
+
# OpsScript Gate
|
|
30
|
+
|
|
31
|
+
> **ShellCheck tells you if your script looks portable. OpsScript Gate checks if it actually runs there.**
|
|
32
|
+
|
|
33
|
+
[](https://github.com/Mresyzz/opsscript-gate/actions/workflows/test.yml)
|
|
34
|
+
[](https://github.com/Mresyzz/opsscript-gate/actions/workflows/demo.yml)
|
|
35
|
+
[](https://pypi.org/project/opsscript-gate/)
|
|
36
|
+
[](https://pypi.org/project/opsscript-gate/)
|
|
37
|
+
[](https://github.com/marketplace/actions/opsscript-gate)
|
|
38
|
+
[](https://github.com/Mresyzz/opsscript-gate/releases)
|
|
39
|
+
[](https://opensource.org/licenses/MIT)
|
|
40
|
+
[](#default-test-matrix)
|
|
41
|
+
|
|
42
|
+
**OpsScript Gate** is a drop-in runtime compatibility gate for Linux shell scripts. It executes your scripts inside unprivileged Debian, Ubuntu, and Alpine containers before merge, catching environment-specific runtime failures, missing interpreters, and package-manager assumptions that static analysis cannot detect.
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## ⚡ 30-Second Quickstart
|
|
47
|
+
|
|
48
|
+
### In GitHub Actions (Zero Config)
|
|
49
|
+
|
|
50
|
+
Drop this minimal workflow into `.github/workflows/shell-compat.yml`:
|
|
51
|
+
|
|
52
|
+
```yaml
|
|
53
|
+
name: Shell Compatibility Gate
|
|
54
|
+
on: [pull_request, push]
|
|
55
|
+
|
|
56
|
+
jobs:
|
|
57
|
+
compat:
|
|
58
|
+
runs-on: ubuntu-latest
|
|
59
|
+
steps:
|
|
60
|
+
- uses: actions/checkout@v7
|
|
61
|
+
- uses: Mresyzz/opsscript-gate@v0.4.0
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
> **Zero Config**: If `script-path` is omitted, OpsScript Gate automatically discovers shell scripts in your repository and tests them concurrently!
|
|
65
|
+
|
|
66
|
+
Or test a specific script with custom execution modes:
|
|
67
|
+
|
|
68
|
+
```yaml
|
|
69
|
+
- uses: Mresyzz/opsscript-gate@v0.4.0
|
|
70
|
+
with:
|
|
71
|
+
script-path: scripts/install.sh
|
|
72
|
+
shell: auto
|
|
73
|
+
jobs: 4
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### In Local Terminal (CLI)
|
|
77
|
+
|
|
78
|
+
Requires Python 3.10+ and a running local Docker engine:
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
# Install from PyPI
|
|
82
|
+
pip install opsscript-gate
|
|
83
|
+
|
|
84
|
+
# Run against a specific script
|
|
85
|
+
opsscript-gate run ./scripts/install.sh
|
|
86
|
+
|
|
87
|
+
# Or auto-discover scripts across your repository
|
|
88
|
+
opsscript-gate run
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
## 🎯 Reviewer-First Experience: What It Produces
|
|
94
|
+
|
|
95
|
+
Every run of OpsScript Gate generates clean, actionable feedback right where developers and reviewers need it:
|
|
96
|
+
|
|
97
|
+
### 1. Line-Level GitHub Annotations
|
|
98
|
+
When a failure occurs, OpsScript Gate flags the exact script line on your Pull Request's **Files Changed** view with high-confidence diagnostics and conservative remediation hints:
|
|
99
|
+
|
|
100
|
+
```text
|
|
101
|
+
::error file=scripts/setup.sh,line=4,title=OpsScript Gate: [alpine:3.20] command not found: apt-get::command not found: apt-get — Alpine normally uses apk instead of apt-get.
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### 2. GitHub Step Summary Compatibility Card
|
|
105
|
+
A beautifully formatted markdown summary is automatically posted to `$GITHUB_STEP_SUMMARY`:
|
|
106
|
+
|
|
107
|
+
```markdown
|
|
108
|
+
## 🛡️ OpsScript Gate Compatibility Report
|
|
109
|
+
|
|
110
|
+
**Target Script**: `scripts/setup.sh`
|
|
111
|
+
**Status**: ❌ **CHECKS FAILED (3/4 Passed)**
|
|
112
|
+
**Total Duration**: `1.24s`
|
|
113
|
+
|
|
114
|
+
### 📊 Compatibility Matrix
|
|
115
|
+
|
|
116
|
+
| Distribution | Status | Exit Code | Time | Diagnostic & Recommendation |
|
|
117
|
+
| :--- | :---: | :---: | :---: | :--- |
|
|
118
|
+
| `debian:12-slim` | ✅ PASS | `0` | `0.42s` | OK |
|
|
119
|
+
| `ubuntu:22.04` | ✅ PASS | `0` | `0.38s` | OK |
|
|
120
|
+
| `ubuntu:24.04` | ✅ PASS | `0` | `0.35s` | OK |
|
|
121
|
+
| `alpine:3.20` | ❌ FAIL | `127` | `0.19s` | ⚠️ Missing command: `apt-get` (line 4)<br>💡 *Alpine normally uses apk instead of apt-get.* |
|
|
122
|
+
|
|
123
|
+
<details>
|
|
124
|
+
<summary>📋 <b>Copyable Markdown (Click to expand & copy to PR / Issue)</b></summary>
|
|
125
|
+
...
|
|
126
|
+
</details>
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
---
|
|
130
|
+
|
|
131
|
+
## 🔍 Example: What Static Analysis Misses
|
|
132
|
+
|
|
133
|
+
Consider this clean deployment script:
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
#!/bin/sh
|
|
137
|
+
set -e
|
|
138
|
+
echo "Fetching package information..."
|
|
139
|
+
apt-get --version
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Running `shellcheck` reports **0 errors, 0 warnings** because the syntax is syntactically valid POSIX shell.
|
|
143
|
+
|
|
144
|
+
However, when verified with **OpsScript Gate**:
|
|
145
|
+
|
|
146
|
+
```text
|
|
147
|
+
+----------------+----------+-----------+----------+------------------------------------+
|
|
148
|
+
| Distro | Status | Exit Code | Duration | Details |
|
|
149
|
+
+----------------+----------+-----------+----------+------------------------------------+
|
|
150
|
+
| debian:12-slim | PASS | 0 | 0.42s | OK |
|
|
151
|
+
| ubuntu:22.04 | PASS | 0 | 0.38s | OK |
|
|
152
|
+
| ubuntu:24.04 | PASS | 0 | 0.35s | OK |
|
|
153
|
+
| alpine:3.20 | FAIL | 127 | 0.19s | command not found: apt-get (line 4)|
|
|
154
|
+
+----------------+----------+-----------+----------+------------------------------------+
|
|
155
|
+
Total duration: 0.58s | Result: FAILED
|
|
156
|
+
|
|
157
|
+
Remediation Recommendations:
|
|
158
|
+
* [alpine:3.20] Alpine normally uses apk instead of apt-get.
|
|
159
|
+
|
|
160
|
+
============================================================
|
|
161
|
+
Failed Distributions - Output Snippets (last 15 lines):
|
|
162
|
+
============================================================
|
|
163
|
+
|
|
164
|
+
--- [alpine:3.20] (FAIL) ---
|
|
165
|
+
sh: line 4: apt-get: not found
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
**Why it failed:** Alpine Linux is musl/BusyBox-based and uses `apk`, not `apt-get`. OpsScript Gate catches the missing command (`exit code 127`) and gives you the exact line number and conservative remediation hint before deployment.
|
|
169
|
+
|
|
170
|
+
---
|
|
171
|
+
|
|
172
|
+
## 🛡️ Why OpsScript Gate?
|
|
173
|
+
|
|
174
|
+
### OpsScript Gate vs ShellCheck vs Custom CI Matrix
|
|
175
|
+
|
|
176
|
+
| Capability | OpsScript Gate | ShellCheck | Handwritten CI Matrix |
|
|
177
|
+
| :--- | :---: | :---: | :---: |
|
|
178
|
+
| **Runtime execution** | **Yes** | No (Static AST only) | Yes |
|
|
179
|
+
| **Real distro environments** | **Yes (Debian, Ubuntu, Alpine)** | No | Yes |
|
|
180
|
+
| **Preconfigured defaults** | **Yes** | Yes | Requires custom workflow configuration |
|
|
181
|
+
| **Hardened container defaults** | **Built-in (`ro`, `cap_drop`, resource limits)** | N/A | User-defined |
|
|
182
|
+
| **Anti-hang stdin protection** | **Built-in (`</dev/null`, noninteractive)** | No | User-defined |
|
|
183
|
+
| **Line-Level Annotations & Hints** | **Built-in (Zero config)** | Static warnings | User-defined |
|
|
184
|
+
| **Parallel Matrix Execution** | **Built-in (`--jobs`)** | N/A | Manual matrix config |
|
|
185
|
+
|
|
186
|
+
- **ShellCheck** is indispensable for static analysis (syntax, quoting, SC warnings). OpsScript Gate complements it by testing actual execution behavior in real distributions.
|
|
187
|
+
- **Handwritten CI Matrix** requires maintaining complex Docker configurations, volume mounts, timeout guards, and log parsers across every project. OpsScript Gate packages this into a single check.
|
|
188
|
+
|
|
189
|
+
---
|
|
190
|
+
|
|
191
|
+
## 🔒 Security Boundaries & Hardened Isolation
|
|
192
|
+
|
|
193
|
+
OpsScript Gate is not a security sandbox for untrusted code. Containers may run as the image's default user, and Docker containers still share the host kernel.
|
|
194
|
+
|
|
195
|
+
OpsScript Gate applies conservative, restricted container defaults when running scripts:
|
|
196
|
+
|
|
197
|
+
1. **Restricted Container Defaults**:
|
|
198
|
+
- Containers run with `privileged=False`.
|
|
199
|
+
- All Linux capabilities are dropped: `cap_drop=["ALL"]`.
|
|
200
|
+
- Privilege escalation is disabled: `security_opt=["no-new-privileges:true"]`.
|
|
201
|
+
2. **Resource Constraints**:
|
|
202
|
+
- Memory limits enforced per container (`--mem-limit`, default: `256m`).
|
|
203
|
+
- Process caps enforced to prevent fork bombs (`--pids-limit`, default: `128`).
|
|
204
|
+
- Network isolation configurable (`--network bridge` or `--network none`).
|
|
205
|
+
3. **Read-Only Target Mount**:
|
|
206
|
+
- The tested script is mounted read-only (`:ro`) at `/tmp/target_script.sh`.
|
|
207
|
+
- No host directories or sensitive sockets are mounted into test containers.
|
|
208
|
+
4. **Anti-Hang Deadlock Defense**:
|
|
209
|
+
- Disables TTY and stdin (`stdin_open=False`, `tty=False`).
|
|
210
|
+
- Disconnects standard input: `/bin/sh -c "... /tmp/target_script.sh </dev/null"`.
|
|
211
|
+
- Injects `DEBIAN_FRONTEND=noninteractive` and `CI=true`. Interactive prompts (`read -p`) fail immediately instead of hanging CI runners.
|
|
212
|
+
5. **Hard Timeout & Container Cleanup**:
|
|
213
|
+
- Enforces configurable timeout (default: 60s). Timed-out containers are sent `SIGKILL` and marked `TIMED_OUT`.
|
|
214
|
+
- Container removal is attempted from a `finally` block in normal, failure, and timeout execution paths.
|
|
215
|
+
6. **Command Injection Defense**:
|
|
216
|
+
- Workflow commands (`::error`) apply strict percent-encoding for all properties and message bodies, preventing unclassified container logs from injecting GitHub Actions workflow commands.
|
|
217
|
+
7. **Windows CRLF Defense**:
|
|
218
|
+
- Automatically detects and normalizes carriage returns (`\r\n` -> `\n`) before container execution, preventing false `\r: command not found` errors.
|
|
219
|
+
|
|
220
|
+
---
|
|
221
|
+
|
|
222
|
+
## 📦 Default Test Matrix
|
|
223
|
+
|
|
224
|
+
| Image | Distribution | Focus |
|
|
225
|
+
| :--- | :--- | :--- |
|
|
226
|
+
| `debian:12-slim` | Debian 12 (Bookworm) | Minimal glibc + APT base |
|
|
227
|
+
| `ubuntu:22.04` | Ubuntu 22.04 LTS (Jammy) | Enterprise long-term support baseline |
|
|
228
|
+
| `ubuntu:24.04` | Ubuntu 24.04 LTS (Noble) | Modern glibc, updated coreutils & defaults |
|
|
229
|
+
| `alpine:3.20` | Alpine Linux 3.20 | Minimal musl libc + BusyBox /bin/sh environment |
|
|
230
|
+
|
|
231
|
+
Customize the matrix at any time via `--matrix` or Action input `matrix`.
|
|
232
|
+
|
|
233
|
+
---
|
|
234
|
+
|
|
235
|
+
## 🛠️ CLI Reference
|
|
236
|
+
|
|
237
|
+
```text
|
|
238
|
+
usage: opsscript-gate run [-h] [--matrix MATRIX] [-j JOBS] [--timeout TIMEOUT]
|
|
239
|
+
[--format {table,markdown,json}]
|
|
240
|
+
[--shell {posix,shebang,auto}]
|
|
241
|
+
[--mem-limit MEM_LIMIT] [--pids-limit PIDS_LIMIT]
|
|
242
|
+
[--network NETWORK]
|
|
243
|
+
[script_path]
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
| Parameter | Type | Default | Description |
|
|
247
|
+
| :--- | :--- | :--- | :--- |
|
|
248
|
+
| `script_path` | Positional | *Optional* | Path to target shell script (auto-discovers if omitted) |
|
|
249
|
+
| `-j, --jobs` | Integer | `min(2, size)` | Number of concurrent container jobs |
|
|
250
|
+
| `--matrix` | String | `debian:12-slim,ubuntu:22.04,ubuntu:24.04,alpine:3.20` | Comma-separated list of Docker images |
|
|
251
|
+
| `--timeout` | Integer | `60` | Hard timeout per container in seconds |
|
|
252
|
+
| `--format` | Choice | `table` | Output format: `table`, `markdown`, or `json` |
|
|
253
|
+
| `--shell` | Choice | `posix` | Execution mode: `posix` (default), `shebang`, or `auto` |
|
|
254
|
+
| `--mem-limit` | String | `256m` | Memory limit per container (e.g. `256m`, `512m`) |
|
|
255
|
+
| `--pids-limit`| Integer | `128` | Maximum number of processes per container |
|
|
256
|
+
| `--network` | Choice | `bridge` | Container network mode: `bridge` or `none` |
|
|
257
|
+
| `--version` | Flag | - | Show version number |
|
|
258
|
+
| `-h, --help` | Flag | - | Show argument help |
|
|
259
|
+
|
|
260
|
+
### Shell Execution Modes (`--shell`)
|
|
261
|
+
|
|
262
|
+
- **`posix`** (default): Strictly executes with `/bin/sh`, ignoring any script shebang to verify portability against minimal POSIX environments (including Alpine BusyBox).
|
|
263
|
+
- **`shebang`**: Strictly honors the interpreter specified in the script's shebang (`#!/bin/sh`, `#!/bin/bash`, `#!/usr/bin/sh`, `#!/usr/bin/bash`, `#!/usr/bin/env sh`, `#!/usr/bin/env bash`). Fails immediately if shebang is missing, malformed, or unsupported.
|
|
264
|
+
- **`auto`**: Honors recognized shebangs if present; safely falls back to `/bin/sh` if no shebang is present.
|
|
265
|
+
|
|
266
|
+
### Exit Code Convention
|
|
267
|
+
- **`0`**: All tested scripts and distributions passed (`PASS`).
|
|
268
|
+
- **`1`**: At least one distribution failed (`FAIL`), timed out (`TIMED_OUT`), or errored (`ERROR`).
|
|
269
|
+
|
|
270
|
+
---
|
|
271
|
+
|
|
272
|
+
## 🐶 Dogfooding
|
|
273
|
+
|
|
274
|
+
OpsScript Gate is actively used in [`Mresyzz/linux-dev-bootstrap`](https://github.com/Mresyzz/linux-dev-bootstrap) to validate `install.sh` across the default Debian, Ubuntu, and Alpine matrix in GitHub Actions.
|
|
275
|
+
|
|
276
|
+
See the downstream workflow: [`.github/workflows/test.yml`](https://github.com/Mresyzz/linux-dev-bootstrap/blob/main/.github/workflows/test.yml).
|
|
277
|
+
|
|
278
|
+
---
|
|
279
|
+
|
|
280
|
+
## 🧪 Development & Testing
|
|
281
|
+
|
|
282
|
+
```bash
|
|
283
|
+
# Clone repository
|
|
284
|
+
git clone https://github.com/Mresyzz/opsscript-gate.git
|
|
285
|
+
cd opsscript-gate
|
|
286
|
+
|
|
287
|
+
# Install in editable mode with test dependencies
|
|
288
|
+
pip install -e .[test]
|
|
289
|
+
|
|
290
|
+
# Run unit tests (Mocked, no Docker daemon required)
|
|
291
|
+
pytest -v -m "not integration"
|
|
292
|
+
|
|
293
|
+
# Run integration tests (Requires local Docker daemon)
|
|
294
|
+
pytest -v
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
---
|
|
298
|
+
|
|
299
|
+
## 📄 License
|
|
300
|
+
|
|
301
|
+
OpsScript Gate is licensed under the [MIT License](LICENSE).
|