diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml index 65568f5..b972ff8 100644 --- a/.gitea/workflows/build.yml +++ b/.gitea/workflows/build.yml @@ -1,6 +1,6 @@ name: adminpanel-ci-cd -# CI/CD: только push git-тега (ручное тегирование на ветке prod|test|stage). +# Pre-deploy: Jest + coverage on test|stage tags. Prod — без автотестов. on: push: @@ -13,18 +13,6 @@ env: IMAGE_DEPLOY: git.sova.local/sova/adminpanel jobs: - test: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 - with: - node-version: '24' - - name: Install dependencies - run: | - if [ -f package-lock.json ]; then npm ci; else npm install; fi - - run: npm run build - parse-tag: runs-on: ubuntu-latest outputs: @@ -40,8 +28,42 @@ jobs: echo "env=$(echo "$TAG" | sed -E 's/adminpanel-v([0-9.]+)-([a-z]+)/\2/')" >> "$GITHUB_OUTPUT" echo "version=$(echo "$TAG" | sed -E 's/adminpanel-v([0-9.]+).*/\1/')" >> "$GITHUB_OUTPUT" + test: + needs: [parse-tag] + if: needs.parse-tag.outputs.env != 'prod' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: '24' + - name: Install dependencies + run: | + if [ -f package-lock.json ]; then npm ci; else npm install; fi + - name: Lint + run: npm run lint + - name: Unit tests + coverage + run: npm run test:ci + - name: Build + run: npm run build + - name: Upload coverage + if: always() + uses: actions/upload-artifact@v4 + with: + name: adminpanel-coverage-${{ needs.parse-tag.outputs.full_tag }} + path: coverage/ + retention-days: 14 + + test-prod-skip: + needs: [parse-tag] + if: needs.parse-tag.outputs.env == 'prod' + runs-on: ubuntu-latest + steps: + - run: echo "Prod tag — automated tests skipped." + build-and-push: - needs: [test, parse-tag] + needs: [parse-tag, test, test-prod-skip] + if: always() && (needs.test.result == 'success' || needs.test.result == 'skipped') && (needs.test-prod-skip.result == 'success' || needs.test-prod-skip.result == 'skipped') runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -95,13 +117,8 @@ jobs: git add "apps/adminpanel/values-${ENV}.yaml" git diff --cached --quiet && { echo "No changes"; exit 0; } git commit -m "chore(adminpanel): bump ${ENV} to ${TAG}" - if git push origin "${ENV}"; then - echo "Push OK on attempt ${attempt}" - exit 0 - fi - echo "Push failed, retry ${attempt}/${MAX_RETRIES}..." + if git push origin "${ENV}"; then exit 0; fi git reset --hard HEAD~1 sleep $((attempt * 2)) done - echo "Failed to push after ${MAX_RETRIES} attempts" exit 1 diff --git a/package.json b/package.json index 2a79f31..31ba874 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "lint-fix": "eslint . --fix", "preview": "vite preview", "test": "jest --runInBand", + "test:ci": "jest --runInBand --coverage --coverageReporters=text-summary --coverageReporters=lcov", "test-watch": "jest --watch", "test-clear-cache": "jest --clearCache" },