Update main.yml #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: tool.bearune CICD | |
| on: | |
| push: | |
| branches: [develop] # 當推送到 develop 分支時觸發 | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| # Step 1: Checkout the code | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| # Step 2: Setup Node.js | |
| - name: Install Node.js | |
| uses: actions/setup-node@v3 | |
| with: | |
| node-version: 18 | |
| # Step 3: npm install | |
| - name: Install dependencies | |
| run: npm install | |
| # Step 4: Build | |
| - name: Build application | |
| run: npm run build # 根據你的專案需求修改 | |
| # Step 5: Setup SSH Key | |
| - name: Install SSH key | |
| uses: webfactory/ssh-agent@v0.5.3 | |
| with: | |
| ssh-private-key: ${{ secrets.BEARUNE_DEPLOY_SSH }} | |
| # Step 6: Update known_hosts | |
| - name: Update known_hosts | |
| run: | | |
| mkdir -p ~/.ssh | |
| ssh-keyscan -H 172.233.65.93 >> ~/.ssh/known_hosts | |
| # Step 7: Transfer files using rsync | |
| - name: Transfer files | |
| run: | | |
| rsync -avz --delete ./dist/ root@172.233.65.93:/var/www/tool/ | |
| env: | |
| SSH_AUTH_SOCK: ${{ env.SSH_AUTH_SOCK }} # 確保 SSH 代理可用 | |
| # Step 8: Set permissions | |
| - name: Set permissions | |
| run: | | |
| ssh root@172.233.65.93 'chown -R www-data:www-data /var/www/tool' |