name: Hexo Build and Deploy on: [push] jobs: build-and-deploy: name: Build Hexo and Deploy to GitHub runs-on: ubuntu-latest steps: - name: Checkout Source Code uses: https://gitea.com/actions/actions/checkout@v4 - name: Setup Node.js uses: https://gitea.com/actions/actions/setup-node@v4 with: node-version: '18' cache: 'npm' # 启用npm缓存 - name: Cache node_modules uses: actions/cache@v4 id: npm-cache with: path: | node_modules ~/.npm key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} restore-keys: | ${{ runner.os }}-node- - name: Install Dependencies run: | # 只有当缓存未命中时才执行完整安装 if [ ! -d "node_modules" ] || [ ! -f "node_modules/.installed" ]; then npm ci touch node_modules/.installed else echo "Using cached dependencies" fi - name: Setup SSH Key and Git Config env: HEXO_DEPLOY_PRI: ${{ secrets.HEXO_DEPLOY_PRI }} run: | mkdir -p ~/.ssh echo "$HEXO_DEPLOY_PRI" > ~/.ssh/id_rsa chmod 600 ~/.ssh/id_rsa ssh-keyscan github.com >> ~/.ssh/known_hosts git config --global user.name "gitea" git config --global user.email "979541498@qq.com" - name: Clean and Generate run: | hexo clean hexo generate - name: Deploy to GitHub run: | hexo deploy