firstsun-dev_git-files-sync/.github/workflows/ci.yml
Workflow config file is invalid. Please check your config file: yaml: unmarshal errors: line 18: mapping key "permissions" already defined at line 3
ClaudiaFang 684551b8f8
fix: resolve SonarCloud Quality Gate failures and improve marketplace readiness (#10)
This commit consolidates several improvements to satisfy SonarCloud Quality Gate and enhance the overall plugin stability:

- Code Quality & Refactoring:
  - Reduced duplication to 0% by refactoring SyncManager and SyncStatusView.
  - Implemented centralized 'processBatch' logic for multi-file sync operations.
  - Fixed security hotspots by replacing legacy atob/btoa with Buffer.
  - Added memory safety limits to the diff algorithm to prevent DoS.

- Test Coverage & Reliability:
  - Improved SyncManager coverage to 81.8% and GitignoreManager to 92.8%.
  - Added comprehensive unit tests for batch operations and complex .gitignore patterns.
  - Resolved all ESLint 'unsafe-member-access' and 'unbound-method' warnings in tests.

- Infrastructure & Metadata:
  - Consolidated GitHub Actions into a single optimized 'ci.yml' using latest versions (v6-v8).
  - Synchronized manifest.json and versions.json to v1.1.0.
  - Fixed workflow permission issues identified by CodeQL.
2026-04-25 23:35:32 +08:00

133 lines
3.7 KiB
YAML

name: CI/CD
permissions:
contents: read
on:
push:
branches:
- main
- master
- '**'
pull_request:
types: [opened, synchronize, reopened]
branches:
- main
- master
permissions:
contents: read
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version: '22'
cache: 'npm'
- run: npm ci
- run: npm run lint
test:
name: Test
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version: '22'
cache: 'npm'
- run: npm ci
- run: npm run test -- --coverage
- id: version
run: echo "version=$(node -p "require('./manifest.json').version")" >> $GITHUB_OUTPUT
- name: Upload coverage
uses: actions/upload-artifact@v7
with:
name: coverage-report
path: coverage/
sonar:
name: SonarQube
needs: test
runs-on: ubuntu-latest
continue-on-error: true
# Only run on push to main/master or PRs (not on every branch push unless it's a PR)
if: github.event_name == 'pull_request' || github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Download coverage
uses: actions/download-artifact@v8
with:
name: coverage-report
path: coverage/
- name: SonarQube Scan
uses: SonarSource/sonarqube-scan-action@v7.1.0
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: https://sonarcloud.io
with:
args: >
-Dsonar.qualitygate.wait=true
artifact:
name: Package Artifact
runs-on: ubuntu-latest
permissions:
contents: read
needs: test
# Run on PRs or feature branches (not on main/master as release handles that)
if: github.event_name == 'pull_request' || (github.ref != 'refs/heads/main' && github.ref != 'refs/heads/master')
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version: '22'
cache: 'npm'
- run: npm ci
- run: npm run build
- name: Create plugin package
run: |
VERSION=${{ needs.test.outputs.version }}
BRANCH_NAME=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}
BRANCH_NAME_SAFE=$(echo "$BRANCH_NAME" | sed 's/[^a-zA-Z0-9._-]/-/g')
ZIP_NAME="git-files-sync-${VERSION}-${BRANCH_NAME_SAFE}.zip"
zip -j "$ZIP_NAME" main.js manifest.json styles.css
echo "ZIP_NAME=$ZIP_NAME" >> $GITHUB_ENV
- uses: actions/upload-artifact@v7
with:
name: plugin-build-${{ needs.test.outputs.version }}-${{ github.sha }}
path: ${{ env.ZIP_NAME }}
retention-days: 7
release:
name: Build and Release
runs-on: ubuntu-latest
needs: [lint, test, sonar]
# Only run on push to main/master
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')
permissions:
contents: write
issues: write
pull-requests: write
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
persist-credentials: false
- uses: actions/setup-node@v6
with:
node-version: '22'
cache: 'npm'
- run: npm ci
- run: npm run build
- env:
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN || secrets.GITHUB_TOKEN }}
run: npx semantic-release