diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..3a626c3 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,6 @@ +version: 2 +updates: + - package-ecosystem: github-actions + directory: / + schedule: + interval: monthly diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..a5ca909 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,149 @@ +name: CI + +on: + push: + branches: [ main ] + pull_request: + workflow_dispatch: + workflow_call: # réutilisé par release.yml avant de publier + +permissions: + contents: read + +concurrency: + group: ci-${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +env: + # Scripts exécutés par Android (/system/bin/sh = mksh) + MODULE_SCRIPTS: caros_config.sh post-fs-data.sh service.sh grant_permissions.sh META-INF/com/google/android/update-binary + +jobs: + shellcheck: + name: ShellCheck + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: ShellCheck (scripts du module, dialecte ksh/mksh) + run: | + # shellcheck disable=SC2086 # découpage voulu de la liste + shellcheck --shell=ksh --severity=warning $MODULE_SCRIPTS + - name: ShellCheck (build.sh, bash) + run: shellcheck --shell=bash --severity=warning build.sh + + syntax: + name: Syntax (mksh / bash) + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install mksh + run: sudo apt-get update -qq && sudo apt-get install -y -qq mksh + - name: mksh -n (shell d'Android) + run: | + for f in $MODULE_SCRIPTS; do + echo "mksh -n $f" + mksh -n "$f" + done + - name: bash -n build.sh + run: bash -n build.sh + + hygiene: + name: Fichiers (CRLF, BOM, shebang) + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Pas de CRLF ni de BOM dans les fichiers du module + run: | + fail=0 + for f in $MODULE_SCRIPTS module.prop system.prop META-INF/com/google/android/updater-script; do + if grep -q $'\r' "$f"; then echo "::error file=$f::fins de ligne CRLF (Android exige LF)"; fail=1; fi + if [ "$(head -c3 "$f" | xxd -p)" = "efbbbf" ]; then echo "::error file=$f::BOM UTF-8 présent"; fail=1; fi + done + exit $fail + - name: Shebang présent + run: | + fail=0 + for f in $MODULE_SCRIPTS; do + case "$(head -n1 "$f")" in + '#!'*) ;; + *) echo "::error file=$f::shebang manquant"; fail=1 ;; + esac + done + exit $fail + - name: updater-script contient #MAGISK + run: grep -qx '#MAGISK' META-INF/com/google/android/updater-script + + metadata: + name: Métadonnées et versions + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: module.prop valide + run: | + fail=0 + for key in id name version versionCode author description; do + grep -q "^${key}=." module.prop || { echo "::error file=module.prop::champ '$key' manquant ou vide"; fail=1; } + done + grep -Eq '^versionCode=[0-9]+$' module.prop || { echo "::error file=module.prop::versionCode doit être un entier"; fail=1; } + grep -Eq '^version=[0-9]+\.[0-9]+\.[0-9]+$' module.prop || { echo "::error file=module.prop::version doit être de la forme X.Y.Z"; fail=1; } + exit $fail + - name: Cohérence des versions (module.prop, service.sh, caros_config.sh) + run: | + V=$(sed -n 's/^version=//p' module.prop | tr -d '\r') + S=$(sed -n 's/.*CarOS Profile Switcher service v\([0-9][0-9.]*\).*/\1/p' service.sh | head -n1) + C=$(sed -n 's/.*Centralized Configuration v\([0-9][0-9.]*\).*/\1/p' caros_config.sh | head -n1) + echo "module.prop=$V service.sh=$S caros_config.sh=$C" + if [ "$V" != "$S" ] || [ "$V" != "$C" ]; then + echo "::error::versions incohérentes"; exit 1 + fi + - name: CHANGELOG contient la version courante + run: | + V=$(sed -n 's/^version=//p' module.prop) + grep -q "^## \[$V\]" CHANGELOG.md || { echo "::error file=CHANGELOG.md::pas de section '## [$V]'"; exit 1; } + + actionlint: + name: Lint des workflows + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: actionlint + run: | + bash <(curl -fsSL https://raw.githubusercontent.com/rhysd/actionlint/v1.7.7/scripts/download-actionlint.bash) 1.7.7 + ./actionlint -color + + build: + name: Build du ZIP Magisk + runs-on: ubuntu-latest + needs: [ shellcheck, syntax, hygiene, metadata ] + steps: + - uses: actions/checkout@v4 + - name: Build (build.sh) + run: bash build.sh + - name: Vérifier le contenu du ZIP + run: | + ZIP=$(ls rel/CarOS_Profile_Switcher-v*.zip) + unzip -Z1 "$ZIP" | sort > actual.txt + cat > expected.txt <<'LIST' + META-INF/ + META-INF/com/ + META-INF/com/google/ + META-INF/com/google/android/ + META-INF/com/google/android/update-binary + META-INF/com/google/android/updater-script + caros_config.sh + grant_permissions.sh + module.prop + post-fs-data.sh + service.sh + system.prop + LIST + sort -o expected.txt expected.txt + diff expected.txt actual.txt && echo "Contenu du ZIP conforme" + unzip -tq "$ZIP" + - name: Publier le ZIP (artefact) + uses: actions/upload-artifact@v4 + with: + name: caros-profile-switcher-${{ github.sha }} + path: rel/*.zip + retention-days: 14 + if-no-files-found: error diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d31c2be..52e3fbf 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,97 +1,71 @@ -name: Build and Release +name: Release on: push: tags: - - 'v*.*.*' # Triggers on version tags like v0.2.4 - workflow_dispatch: # Allows manual trigger + - 'v[0-9]+.[0-9]+.[0-9]+' permissions: - contents: write + contents: read jobs: - build: + ci: + name: CI + uses: ./.github/workflows/ci.yml + + release: + name: Publier la release + needs: ci runs-on: ubuntu-latest - + permissions: + contents: write steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Extract version from tag - id: get_version - run: | - if [ "${{ github.ref_type }}" == "tag" ]; then - VERSION=${GITHUB_REF#refs/tags/v} - else - VERSION=$(grep "^version=" module.prop | cut -d'=' -f2) - fi - echo "VERSION=$VERSION" >> $GITHUB_OUTPUT - echo "Building version: $VERSION" - - - name: Validate required files - run: | - echo "Checking required files..." - for file in caros_config.sh module.prop post-fs-data.sh service.sh system.prop grant_permissions.sh META-INF/com/google/android/update-binary META-INF/com/google/android/updater-script; do - if [ ! -f "$file" ]; then - echo "Error: Missing required file: $file" + - uses: actions/checkout@v4 + + - name: Le tag correspond à module.prop + id: ver + run: | + TAG_VERSION="${GITHUB_REF_NAME#v}" + PROP_VERSION=$(sed -n 's/^version=//p' module.prop | tr -d '\r') + if [ "$TAG_VERSION" != "$PROP_VERSION" ]; then + echo "::error::tag $GITHUB_REF_NAME != version=$PROP_VERSION dans module.prop" exit 1 fi - done - echo "All required files present ✓" - - - name: Create release directory - run: mkdir -p rel - - - name: Build release ZIP - run: | - VERSION=${{ steps.get_version.outputs.VERSION }} - OUTPUT_FILE="rel/CarOS_Profile_Switcher-v${VERSION}.zip" - - zip -r "$OUTPUT_FILE" \ - caros_config.sh \ - module.prop \ - post-fs-data.sh \ - service.sh \ - system.prop \ - grant_permissions.sh \ - META-INF - - echo "Created: $OUTPUT_FILE" - ls -lh "$OUTPUT_FILE" - - - name: Create Release - uses: softprops/action-gh-release@v2 - if: startsWith(github.ref, 'refs/tags/') - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - files: rel/*.zip - body: | - ## CarOS Profile Switcher v${{ steps.get_version.outputs.VERSION }} - + echo "version=$PROP_VERSION" >> "$GITHUB_OUTPUT" + + - name: Build (build.sh) + run: bash build.sh "${{ steps.ver.outputs.version }}" + + - name: Notes de release (extraites de CHANGELOG.md) + env: + VERSION: ${{ steps.ver.outputs.version }} + REPO: ${{ github.repository }} + run: | + { + echo "## CarOS Profile Switcher v${VERSION}" + echo + awk -v v="$VERSION" ' + $0 ~ "^## \\[" v "\\]" { on=1; next } + on && /^## \[/ { exit } + on { print } + ' CHANGELOG.md + cat < release-notes.md + cat release-notes.md + + - name: Créer la release GitHub + uses: softprops/action-gh-release@v2 + with: + files: rel/*.zip + body_path: release-notes.md + fail_on_unmatched_files: true diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml deleted file mode 100644 index 040c108..0000000 --- a/.github/workflows/validate.yml +++ /dev/null @@ -1,126 +0,0 @@ -name: Validate Module - -on: - push: - branches: [ main, develop ] - pull_request: - branches: [ main ] - workflow_dispatch: - -jobs: - validate: - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Check required files exist - run: | - echo "Validating module structure..." - MISSING=0 - - for file in caros_config.sh module.prop post-fs-data.sh service.sh system.prop grant_permissions.sh; do - if [ ! -f "$file" ]; then - echo "❌ Missing: $file" - MISSING=1 - else - echo "✓ Found: $file" - fi - done - - if [ ! -d "META-INF/com/google/android" ]; then - echo "❌ Missing: META-INF directory structure" - MISSING=1 - else - echo "✓ Found: META-INF structure" - fi - - if [ $MISSING -eq 1 ]; then - echo "Validation failed!" - exit 1 - fi - - echo "All files present ✓" - - - name: Validate shell scripts syntax - run: | - echo "Checking shell script syntax..." - for script in caros_config.sh post-fs-data.sh service.sh grant_permissions.sh; do - echo "Checking $script..." - bash -n "$script" || { echo "Syntax error in $script"; exit 1; } - done - echo "All scripts valid ✓" - - - name: Check version consistency - run: | - echo "Checking version consistency..." - MODULE_VERSION=$(grep "^version=" module.prop | cut -d'=' -f2) - SERVICE_VERSION=$(grep "CarOS Profile Switcher service v" service.sh | sed 's/.*service v\([0-9.]*\).*/\1/') - CONFIG_VERSION=$(grep "Centralized Configuration v" caros_config.sh | sed 's/.*v\([0-9.]*\).*/\1/') - - echo "module.prop version: $MODULE_VERSION" - echo "service.sh version: $SERVICE_VERSION" - echo "caros_config.sh version: $CONFIG_VERSION" - - if [ "$MODULE_VERSION" != "$SERVICE_VERSION" ] || [ "$MODULE_VERSION" != "$CONFIG_VERSION" ]; then - echo "❌ Version mismatch detected!" - exit 1 - fi - - echo "✓ All versions consistent: $MODULE_VERSION" - - - name: Validate module.prop format - run: | - echo "Validating module.prop..." - - if ! grep -q "^id=" module.prop; then - echo "❌ Missing 'id' field" - exit 1 - fi - - if ! grep -q "^name=" module.prop; then - echo "❌ Missing 'name' field" - exit 1 - fi - - if ! grep -q "^version=" module.prop; then - echo "❌ Missing 'version' field" - exit 1 - fi - - if ! grep -q "^versionCode=" module.prop; then - echo "❌ Missing 'versionCode' field" - exit 1 - fi - - echo "✓ module.prop format valid" - - - name: Test build process - run: | - echo "Testing build process..." - VERSION=$(grep "^version=" module.prop | cut -d'=' -f2) - mkdir -p rel - - zip -r "rel/CarOS_Profile_Switcher-v${VERSION}.zip" \ - caros_config.sh \ - module.prop \ - post-fs-data.sh \ - service.sh \ - system.prop \ - grant_permissions.sh \ - META-INF - - if [ ! -f "rel/CarOS_Profile_Switcher-v${VERSION}.zip" ]; then - echo "❌ Build failed" - exit 1 - fi - - SIZE=$(stat -f%z "rel/CarOS_Profile_Switcher-v${VERSION}.zip" 2>/dev/null || stat -c%s "rel/CarOS_Profile_Switcher-v${VERSION}.zip") - echo "✓ Build successful: $(($SIZE / 1024)) KB" - - - name: Summary - run: | - echo "=========================================" - echo "✅ All validation checks passed!" - echo "=========================================" diff --git a/.shellcheckrc b/.shellcheckrc new file mode 100644 index 0000000..d8eec03 --- /dev/null +++ b/.shellcheckrc @@ -0,0 +1,4 @@ +# SC1090: les fichiers sourcés (config.env) n'existent que sur le téléphone +# SC2034: variables de l'API Magisk (OUTFD, ZIPFILE...) utilisées par util_functions.sh +# SC2145: "$@" dans les fonctions de log, comportement voulu +disable=SC1090,SC2034,SC2145