cache
cache copied to clipboard
Update action.yml
Description
Motivation and Context
How Has This Been Tested?
Screenshots (if appropriate):
Types of changes
- [x] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [x] Breaking change (fix or feature that would cause existing functionality to change)
- [x] Documentation (add or update README or docs)
Checklist:
- [x] My code follows the code style of this project.
- [x] My change requires a change to the documentation.
- [x] I have updated the documentation accordingly.
- [x] I have read the CONTRIBUTING document.
- [x] I have added tests to cover my changes.
- [x] All new and existing tests passed.
-----------------------------------------------------------------------------
| 🤖 THE ULTIMATE ALL-IN-ONE AUTONOMOUS CI SYSTEM 🤖 |
| Designed for 100% Production Readiness |
-----------------------------------------------------------------------------
name: '🚀 Ultimate Autonomous CI'
=============================================================================
| 🧠 1. TRIGGERS (THE SENSES) - ส่วนรับรู้และสั่งการทำงาน |
=============================================================================
on:
ทริกเกอร์เชิงรุก (Proactive): ตรวจสอบและบำรุงรักษาระบบทุกวันตอนตี 2 UTC
schedule: - cron: '0 2 * * *'
ทริกเกอร์เชิงรับ (Reactive): ทำงานทันทีเมื่อมีโค้ดใหม่เข้ามา
push: branches: - 'main' - 'develop'
ทริกเกอร์ตรวจสอบคุณภาพ: ทำงานเมื่อมีการเปิด Pull Request
pull_request: branches: - 'main' - 'develop'
ทริกเกอร์ด้วยมือ: อนุญาตให้สั่งรันระบบได้เอง عندความต้องการ
workflow_dispatch:
=============================================================================
| ⚙️ PERMISSIONS - การกำหนดสิทธิ์การเข้าถึง |
=============================================================================
ตั้งค่าสิทธิ์ให้ Workflow สามารถสร้าง PR และ Issue ได้ ซึ่งจำเป็นสำหรับระบบ Self-Healing
permissions: contents: write pull-requests: write issues: write
=============================================================================
| JOBS - กระบวนการทำงาน |
=============================================================================
jobs:
---------------------------------------------------------------------------
| JOB 1: AUTONOMOUS MAINTENANCE & VALIDATION |
---------------------------------------------------------------------------
autonomous_system: name: '🛡️ Autonomous Maintain & Validate' runs-on: ubuntu-latest
steps:
# --- Setup Phase ---
- name: '1.1. System Checkout'
uses: actions/checkout@v4
with:
# ดึงข้อมูล commit ทั้งหมดเพื่อให้สามารถเปรียบเทียบการเปลี่ยนแปลงได้
fetch-depth: 0
- name: '1.2. Environment Setup (Node.js + Cache)'
uses: actions/setup-node@v4
with:
node-version: '20.x'
# เปิดใช้งาน Cache สำหรับ npm โดยอัตโนมัติตาม Best Practice
cache: 'npm'
- name: '1.3. Dependency Synchronization'
run: npm ci
# --- Self-Healing Phase ---
- name: '2.1. Heal: Auto-Patch Vulnerabilities & Format Code'
id: auto_heal_step
run: |
echo "Changes detected before healing: $(git status --porcelain=v1 2>/dev/null | wc -l)"
# ซ่อมแซมช่องโหว่ความปลอดภัยระดับต่ำถึงกลางโดยอัตโนมัติ
npm audit fix --audit-level=moderate
# จัดระเบียบโค้ดทั้งหมดให้เป็นมาตรฐานเดียวกัน
npx prettier --write .
echo "Changes detected after healing: $(git status --porcelain=v1 2>/dev/null | wc -l)"
# ตรวจสอบว่ามีการเปลี่ยนแปลงไฟล์หรือไม่ และส่งผลลัพธ์ออกไป
if [[ -n $(git status --porcelain) ]]; then
echo "changes_detected=true" >> $GITHUB_OUTPUT
else
echo "changes_detected=false" >> $GITHUB_OUTPUT
fi
- name: '2.2. Remediate: Create Pull Request with Applied Fixes'
if: steps.auto_heal_step.outputs.changes_detected == 'true'
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: 'fix(auto): Apply automated security patches and formatting'
title: '🤖 CI [Auto-Heal]: Security & Style Fixes'
body: |
This Pull Request was automatically generated by the **Ultimate Autonomous CI** workflow.
It contains the following automated fixes to maintain project health and security:
- **Security Patches**: Applied via `npm audit fix`.
- **Code Formatting**: Standardized using `prettier`.
This is a routine maintenance action. Please review and merge.
branch: 'ci/auto-fixes'
delete-branch: true
labels: 'automated-pr, maintenance'
assignees: '${{ github.actor }}'
# --- Validation Phase ---
- name: '3.1. Validate: Build Project'
run: npm run build --if-present
- name: '3.2. Validate: Run All Tests'
run: npm test
# --- Failure Response Phase ---
- name: '4.1. Report: Auto-Create Issue on Critical Failure'
if: failure() && github.event_name != 'pull_request'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh issue create \
--title "🚨 CRITICAL FAILURE in CI on branch '${{ github.ref_name }}' [${{ github.sha }}]" \
--body "The **Ultimate Autonomous CI** workflow failed and could not self-heal.
- **Triggered by:** ${{ github.event_name }} by @${{ github.actor }}
- **Branch:** `${{ github.ref_name }}`
- **Commit:** `${{ github.sha }}`
- **Workflow Log:** [Click here to view logs](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
### **Manual intervention is urgently required.**" \
--label "bug,critical,ci-failure" \
--assignee "${{ github.actor }}"