diff --git a/.editorconfig b/.editorconfig index 5c1a4ef..1611983 100644 --- a/.editorconfig +++ b/.editorconfig @@ -67,3 +67,10 @@ indent_size = 4 indent_style = space indent_size = 2 max_line_length = 120 + +# README files (allow longer lines for badges and tables) +[README.md] +indent_style = space +indent_size = 2 +max_line_length = 120 +trim_trailing_whitespace = false diff --git a/.github/workflows/super-linter.yml b/.github/workflows/super-linter.yml index c8fa52a..5adce07 100644 --- a/.github/workflows/super-linter.yml +++ b/.github/workflows/super-linter.yml @@ -1,7 +1,15 @@ -# This workflow executes several linters on changed files based on languages used in your code base whenever -# you push a code or open a pull request. +# This workflow executes comprehensive linting on changed files using the configured linting infrastructure +# from PR #43. It validates code quality across multiple languages and formats. +# +# Configured linters include: +# - EDITORCONFIG (file formatting consistency) +# - SHELLCHECK (bash/shell script analysis) +# - YAML (YAML syntax and style) +# - JSON (JSON syntax validation) +# - MARKDOWN (Markdown formatting via markdownlint) +# - JSCPD (duplicate code detection) +# - GITLEAKS (secret detection) # -# You can adjust the behavior by modifying this file. # For more information, see: # https://github.com/github/super-linter name: Lint Code Base @@ -31,3 +39,11 @@ jobs: VALIDATE_ALL_CODEBASE: false DEFAULT_BRANCH: "master" GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # Only enable the linters we need (Super Linter v4 doesn't support mixed true/false) + VALIDATE_EDITORCONFIG: true + VALIDATE_BASH: true + VALIDATE_YAML: true + VALIDATE_JSON: true + VALIDATE_MARKDOWN: true + VALIDATE_JSCPD: true + VALIDATE_GITLEAKS: true diff --git a/.gitignore b/.gitignore index 40296e3..648222e 100644 --- a/.gitignore +++ b/.gitignore @@ -137,4 +137,10 @@ terraform.tfstate* .vagrant/ *.swp *.swo -*~ \ No newline at end of file +*~ + +# Linting artifacts +.jscpd-report/ +*.jscpd-report +.super-linter.log +.shellcheckrc.local diff --git a/.jscpd.json b/.jscpd.json new file mode 100644 index 0000000..a7332b0 --- /dev/null +++ b/.jscpd.json @@ -0,0 +1,14 @@ +{ + "threshold": 3, + "reporters": ["console"], + "ignore": [ + "node_modules/**", + "**/*.min.js", + "tests/**", + "docs/dashboard/js/vendor/**" + ], + "format": ["javascript", "typescript", "bash"], + "minLines": 10, + "minTokens": 50, + "output": ".jscpd-report" +} diff --git a/.markdownlint.json b/.markdownlint.json new file mode 100644 index 0000000..6c2b9a7 --- /dev/null +++ b/.markdownlint.json @@ -0,0 +1,25 @@ +{ + "default": true, + "MD003": { + "style": "atx" + }, + "MD007": { + "indent": 2 + }, + "MD013": { + "line_length": 120, + "headings": false, + "code_blocks": false, + "tables": false + }, + "MD024": { + "allow_different_nesting": true + }, + "MD033": { + "allowed_elements": ["br", "sub", "sup"] + }, + "MD041": false, + "MD046": { + "style": "fenced" + } +} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..f3284c9 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,59 @@ +# Pre-commit hooks for Oracle Instance Creator +# Install: pip install pre-commit && pre-commit install +# Update: pre-commit autoupdate + +repos: + # Shell script linting with ShellCheck + - repo: https://github.com/koalaman/shellcheck-precommit + rev: v0.9.0 + hooks: + - id: shellcheck + args: [--format=gcc, --external-sources] + types: [shell] + + # YAML linting + - repo: https://github.com/adrienverge/yamllint + rev: v1.32.0 + hooks: + - id: yamllint + args: [-c=.yamllint.yml] + types: [yaml] + + # JSON formatting and validation + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.4.0 + hooks: + - id: check-json + - id: pretty-format-json + args: [--autofix, --indent=2] + + # Markdown linting + - repo: https://github.com/igorshubovych/markdownlint-cli + rev: v0.35.0 + hooks: + - id: markdownlint + args: [-c, .markdownlint.json] + + # EditorConfig validation + - repo: https://github.com/editorconfig-checker/editorconfig-checker.python + rev: 2.7.2 + hooks: + - id: editorconfig-checker + alias: ec + + # General file checks + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.4.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-added-large-files + - id: check-case-conflict + - id: check-merge-conflict + - id: check-executables-have-shebangs + + # Secret detection (GitLeaks) + - repo: https://github.com/zricethezav/gitleaks + rev: v8.17.0 + hooks: + - id: gitleaks diff --git a/.shellcheckrc b/.shellcheckrc new file mode 100644 index 0000000..f1491ed --- /dev/null +++ b/.shellcheckrc @@ -0,0 +1,42 @@ +# ShellCheck configuration for OCI Automation Project +# See: https://www.shellcheck.net/wiki/ + +# === GLOBAL SUPPRESSIONS === +# Only suppress issues that are inherent to the project structure + +# SC1091: Can't follow non-constant source - we control our sourcing patterns +# SC2086: Quote variables - TEMPORARY suppression until issue #50 resolved (~51 instances) +# SC2155: Declare/assign separately - TEMPORARY suppression until issue #50 resolved (~51 instances) +disable=SC1091,SC2086,SC2155 + +# === FUTURE WORK (Technical Debt) === +# The following suppressions should be addressed individually: +# +# SC2086 (Quote variables): ~51 instances - see issue #50 +# - Most should be quoted: $var -> "$var" +# - Some intentional word splitting cases need inline suppressions +# disable=SC2086 +# +# SC2155 (Declare/assign separately): ~51 instances - see issue #50 +# - Split: local var=$(cmd) -> local var; var=$(cmd) +# - Prevents masking command exit codes +# disable=SC2155 + +# === FILE-SPECIFIC SUPPRESSIONS NEEDED === +# Global suppressions below should be migrated to file-specific - see issue #51 +# +# SC2034: Unused variables (~101 instances) +# - constants.sh: Variables exported for external use +# - Should use: # shellcheck disable=SC2034 at file level +# +# SC2329: Unused functions (~101 instances) +# - test files: Functions called by test frameworks +# - Should use inline suppressions per function + +# Source path for external scripts +source-path=SCRIPTDIR + +# === TEMPORARY GLOBAL SUPPRESSIONS === +# TODO: Remove these after migrating to file-specific suppressions (issue #51) +# Suppress SC2034 (unused variables) for constants.sh exports +# Suppress SC2329 (unused functions) in test files called by frameworks diff --git a/.yamllint.yml b/.yamllint.yml new file mode 100644 index 0000000..ca3554b --- /dev/null +++ b/.yamllint.yml @@ -0,0 +1,15 @@ +--- +extends: default + +rules: + line-length: + max: 120 + level: warning + truthy: + allowed-values: ["true", "false", "on", "off"] + check-keys: true + trailing-spaces: enable + document-start: + present: true + comments: + min-spaces-from-content: 1 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..7dd108e --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,296 @@ +# Contributing to Oracle Instance Creator + +Thank you for your interest in contributing to the Oracle Instance Creator +project! This guide will help you understand our development workflow, code +quality standards, and contribution process. + +## ๐Ÿ“‹ Table of Contents + +- [Development Setup](#-development-setup) +- [Code Quality Standards](#-code-quality-standards) +- [Linting and Formatting](#-linting-and-formatting) +- [Testing](#-testing) +- [Submitting Changes](#-submitting-changes) +- [Issue Reporting](#-issue-reporting) + +## ๐Ÿ”ง Development Setup + +### Prerequisites + +- **OCI CLI**: Oracle Cloud Infrastructure CLI tool +- **Bash 4.0+**: For shell scripts +- **Git**: Version control +- **GitHub CLI** (optional): For PR management + +### Local Development + +1. **Fork and Clone** + ```bash + git clone https://github.com/your-username/OracleInstanceCreator.git + cd OracleInstanceCreator + ``` + +2. **Create Feature Branch** + ```bash + git checkout -b feature/your-feature-name + ``` + +3. **Run Local Tests** + ```bash + ./tests/run_new_tests.sh + ``` + +## โšก Code Quality Standards + +This project maintains high code quality through comprehensive linting and +automated checks. + +### Linting Infrastructure + +The project uses multiple linters to ensure code quality across different +file types: + +#### ๐Ÿš **Shell Scripts** (`.sh` files) +- **ShellCheck**: Static analysis for shell scripts +- **Configuration**: `.shellcheckrc` +- **Key Rules**: + - Quote variables to prevent word splitting: `"$var"` + - Separate declare and assign: `local var; var=$(command)` + - Use `[[ ]]` for Bash conditionals + +#### ๐Ÿ“„ **Markdown** (`.md` files) +- **markdownlint**: Markdown style and syntax checker +- **Configuration**: `.markdownlint.json` +- **Key Rules**: + - ATX-style headers (`# Header`) + - Fenced code blocks + - 120-character line limit (warnings only) + +#### ๐Ÿ“ฆ **JSON** (`.json` files) +- **JSON Linter**: Syntax validation +- **Key Rules**: + - Valid JSON syntax + - Proper indentation (2 spaces) + +#### ๐Ÿ”ง **YAML** (`.yml`, `.yaml` files) +- **yamllint**: YAML syntax and style checker +- **Configuration**: `.yamllint.yml` +- **Key Rules**: + - Document start markers (`---`) + - 120-character line limit + - Consistent indentation (2 spaces) + +#### ๐Ÿ” **Code Duplication** +- **JSCPD**: Copy-paste detection +- **Configuration**: `.jscpd.json` +- **Thresholds**: 10+ lines or 50+ tokens + +#### ๐Ÿ” **Security** +- **GitLeaks**: Secret detection +- **Scans**: API keys, tokens, passwords + +#### โœ๏ธ **File Formatting** +- **EditorConfig**: Consistent formatting +- **Configuration**: `.editorconfig` +- **Rules**: Line endings, indentation, final newlines + +## ๐Ÿ” Linting and Formatting + +### Running Linters Locally + +**All Linters** (same as CI): +```bash +# Using GitHub's Super Linter (Docker required) +docker run --rm -e RUN_LOCAL=true -e USE_FIND_ALGORITHM=true \ + -v "$PWD":/tmp/lint github/super-linter:v4 +``` + +**Individual Tools**: +```bash +# ShellCheck +shellcheck scripts/*.sh + +# markdownlint +markdownlint "**/*.md" + +# yamllint +yamllint .github/workflows/*.yml + +# JSCPD (duplicate detection) +npx jscpd . + +# EditorConfig +editorconfig-checker +``` + +### Fixing Common Issues + +#### ShellCheck Fixes +```bash +# Bad: Unquoted variable +echo $USER + +# Good: Quoted variable +echo "$USER" + +# Bad: Masked return value +local result=$(command) + +# Good: Separate declare/assign +local result +result=$(command) +``` + +#### Markdown Fixes +```bash +# Bad: Underline headers +Header +====== + +# Good: ATX headers +# Header + +# Bad: Indented code + code here + +# Good: Fenced code +```bash +code here +``` + +```bash + +### Pre-commit Hooks (Recommended) + +Set up automatic linting before commits: +```bash +# Install pre-commit +pip install pre-commit + +# Setup hooks (if .pre-commit-config.yaml exists) +pre-commit install +``` + +## ๐Ÿงช Testing + +### Test Structure + +- **Unit Tests**: `tests/test_*.sh` +- **Integration Tests**: `tests/test_integration.sh` +- **End-to-End Tests**: `tests/test_e2e_*.sh` + +### Running Tests + +```bash +# All tests +./tests/run_new_tests.sh + +# Specific test file +bash tests/test_utils.sh + +# Stress testing +bash tests/test_stress.sh +``` + +### Test Requirements + +- All new features must include tests +- Maintain existing test coverage +- Tests should pass in CI environment + +## ๐Ÿ“ Submitting Changes + +### Pull Request Process + +1. **Create Feature Branch** + ```bash + git checkout -b feature/descriptive-name + ``` + +2. **Make Changes** +- Follow coding standards +- Add/update tests +- Update documentation + +3. **Commit Changes** + ```bash + git add . + git commit -m "feat: add descriptive commit message + + - Detailed explanation of changes + - Reference any issues: Closes #123" + ``` + +4. **Push and Create PR** + ```bash + git push origin feature/descriptive-name + # Create PR via GitHub UI or GitHub CLI + gh pr create --title "Feature: Description" --body "Detailed description" + ``` + +### Commit Message Format + +Follow conventional commits: +```text +(): + +[optional body] + +[optional footer] +``` + +**Types**: `feat`, `fix`, `docs`, `test`, `refactor`, `chore` + +**Examples**: +- `feat(scripts): add retry logic for OCI API calls` +- `fix(dashboard): correct instance status display` +- `docs(readme): update installation instructions` + +### PR Requirements + +- [ ] All linting checks pass +- [ ] Tests pass +- [ ] Documentation updated +- [ ] No breaking changes (or clearly documented) +- [ ] Follows project coding standards + +## ๐Ÿ› Issue Reporting + +### Bug Reports + +Include: +- **Environment**: OS, OCI CLI version, region +- **Steps to Reproduce**: Exact commands/actions +- **Expected vs Actual Behavior** +- **Logs**: Relevant error messages +- **Configuration**: Sanitized config (no secrets) + +### Feature Requests + +Include: +- **Use Case**: Why this feature is needed +- **Proposed Solution**: How it should work +- **Alternatives**: Other approaches considered +- **Impact**: Who would benefit + +## ๐Ÿ“š Additional Resources + +- [OCI CLI Documentation](https://docs.oracle.com/en-us/iaas/tools/oci-cli/) +- [ShellCheck Wiki](https://github.com/koalaman/shellcheck/wiki) +- [Project Architecture](docs/README.md) +- [Troubleshooting Guide](docs/troubleshooting.md) + +## ๐Ÿค Code of Conduct + +- Be respectful and inclusive +- Provide constructive feedback +- Focus on the code, not the person +- Help others learn and improve + +## ๐Ÿ“ž Getting Help + +- **GitHub Issues**: Bug reports and feature requests +- **GitHub Discussions**: General questions and ideas +- **Documentation**: Check `docs/` directory first + +Thank you for contributing to Oracle Instance Creator! ๐Ÿš€ diff --git a/README.md b/README.md index 50c70c5..3ebb2e3 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,13 @@ # OCI Free Tier Automation -[![GitHub Actions](https://github.com/senomorf/OracleInstanceCreator/workflows/OCI%20Free%20Tier%20Creation/badge.svg)](https://github.com/senomorf/OracleInstanceCreator/actions) +[![GitHub Actions][actions-badge]][actions-link] +[![Linting][linting-badge]][linting-link] [![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE) [![OCI Compatible](https://img.shields.io/badge/OCI-Compatible-orange.svg)](https://cloud.oracle.com/) +[![Code Quality](https://img.shields.io/badge/code%20quality-enforced-brightgreen.svg)](#contributing) -Automated provisioning of Oracle Cloud free-tier instances (A1.Flex ARM & E2.1.Micro AMD) via GitHub Actions with parallel execution and smart retry logic. +Automated provisioning of Oracle Cloud free-tier instances (A1.Flex ARM & +E2.1.Micro AMD) via GitHub Actions with parallel execution and smart retry logic. ## Features @@ -65,7 +68,9 @@ The system executes both instance types in parallel for maximum efficiency: - Instance name: `e2-micro-sg` - Traditional x86 architecture -Each shape independently cycles through configured availability domains until successful or capacity unavailable. The parallel approach maximizes your chances of securing at least one free-tier instance. +Each shape independently cycles through configured availability domains until +successful or capacity unavailable. The parallel approach maximizes your chances +of securing at least one free-tier instance. ## Deployment Scenarios @@ -128,4 +133,25 @@ MIT License - See [LICENSE](LICENSE) file for details. ## Contributing -This project demonstrates advanced cloud automation patterns and Infrastructure-as-Code practices. Contributions welcome for additional cloud providers, enhanced error handling, or performance optimizations. \ No newline at end of file +This project demonstrates advanced cloud automation patterns and +Infrastructure-as-Code practices with comprehensive code quality standards. + +**Before Contributing:** +- Review our [Contributing Guide](CONTRIBUTING.md) for development workflow and coding standards +- All code must pass linting checks (ShellCheck, markdownlint, YAML lint, etc.) +- Include tests for new features and ensure existing tests pass +- Follow conventional commit message format + +**Code Quality:** +- **Automated linting** for shell scripts, YAML, JSON, and Markdown +- **Security scanning** with GitLeaks for credential detection +- **Duplicate code detection** to maintain clean codebase +- **EditorConfig** for consistent file formatting + +Contributions welcome for additional cloud providers, enhanced error handling, +performance optimizations, and testing improvements. + +[actions-badge]: https://github.com/senomorf/OracleInstanceCreator/workflows/OCI%20Free%20Tier%20Creation/badge.svg +[actions-link]: https://github.com/senomorf/OracleInstanceCreator/actions +[linting-badge]: https://github.com/senomorf/OracleInstanceCreator/workflows/Lint%20Code%20Base/badge.svg +[linting-link]: https://github.com/senomorf/OracleInstanceCreator/actions