|
| 1 | +name: Sync Dashboard Build to Main Repository |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +jobs: |
| 10 | + sync: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + if: github.repository == 'apache/shenyu-dashboard' |
| 13 | + |
| 14 | + steps: |
| 15 | + - name: Checkout dashboard repository |
| 16 | + uses: actions/checkout@v4 |
| 17 | + with: |
| 18 | + fetch-depth: 0 |
| 19 | + |
| 20 | + - name: Setup Node.js |
| 21 | + uses: actions/setup-node@v4 |
| 22 | + with: |
| 23 | + node-version: '16' |
| 24 | + cache: 'npm' |
| 25 | + |
| 26 | + - name: Install dependencies |
| 27 | + run: npm ci |
| 28 | + |
| 29 | + - name: Build project |
| 30 | + run: npm run build |
| 31 | + |
| 32 | + - name: Checkout main repository |
| 33 | + uses: actions/checkout@v4 |
| 34 | + with: |
| 35 | + repository: apache/shenyu |
| 36 | + token: ${{ secrets.GH_PAT }} |
| 37 | + path: shenyu-main |
| 38 | + fetch-depth: 0 |
| 39 | + |
| 40 | + - name: Check for changes and sync |
| 41 | + run: | |
| 42 | + mkdir -p shenyu-main/shenyu-admin/src/main/resources/static |
| 43 | + |
| 44 | + # check different. |
| 45 | + if ! diff -r dist/ shenyu-main/shenyu-admin/src/main/resources/static/ > /dev/null 2>&1; then |
| 46 | + echo "Changes detected, syncing files..." |
| 47 | + |
| 48 | + # check change,start sync code |
| 49 | + rm -rf shenyu-main/shenyu-admin/src/main/resources/static/* |
| 50 | + cp -r dist/* shenyu-main/shenyu-admin/src/main/resources/static/ |
| 51 | + |
| 52 | + # create pull request git config |
| 53 | + cd shenyu-main |
| 54 | + git config --local user.email "[email protected]" |
| 55 | + git config --local user.name "GitHub Action" |
| 56 | + |
| 57 | + # create new branch to sync code |
| 58 | + BRANCH_NAME="sync-dashboard-$(date +%Y%m%d-%H%M%S)" |
| 59 | + git checkout -b "$BRANCH_NAME" |
| 60 | + |
| 61 | + # commit changes |
| 62 | + git add shenyu-admin/src/main/resources/static/ |
| 63 | + git commit -m "admin(dashboard): sync dashboard build from apache/shenyu-dashboard@${{ github.sha }} |
| 64 | + |
| 65 | + Auto-sync dashboard build artifacts from shenyu-dashboard repository. |
| 66 | + |
| 67 | + Source commit: ${{ github.sha }} |
| 68 | + Workflow run: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" |
| 69 | + |
| 70 | + # push |
| 71 | + git push origin "$BRANCH_NAME" |
| 72 | + |
| 73 | + # create pull request |
| 74 | + gh pr create \ |
| 75 | + --title "chore: sync dashboard build artifacts" \ |
| 76 | + --body "Auto-sync dashboard build artifacts from apache/shenyu-dashboard. |
| 77 | +
|
| 78 | + **Source Details:** |
| 79 | + - Repository: apache/shenyu-dashboard |
| 80 | + - Commit: ${{ github.sha }} |
| 81 | + - Workflow: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} |
| 82 | + |
| 83 | + This PR contains the latest build artifacts from the dashboard repository." \ |
| 84 | + --head "$BRANCH_NAME" \ |
| 85 | + --base master |
| 86 | + |
| 87 | + echo "✅ Pull request created successfully" |
| 88 | + else |
| 89 | + echo "No changes detected, skipping sync" |
| 90 | + fi |
| 91 | + env: |
| 92 | + GH_TOKEN: ${{ secrets.GH_PAT }} |
| 93 | + |
| 94 | + - name: Result Output |
| 95 | + run: | |
| 96 | + echo "## Sync Summary" >> $GITHUB_STEP_SUMMARY |
| 97 | + echo "- **Source Repository**: apache/shenyu-dashboard" >> $GITHUB_STEP_SUMMARY |
| 98 | + echo "- **Source Commit**: ${{ github.sha }}" >> $GITHUB_STEP_SUMMARY |
| 99 | + echo "- **Target Repository**: apache/shenyu" >> $GITHUB_STEP_SUMMARY |
| 100 | + echo "- **Target Path**: shenyu-admin/src/main/resources/static" >> $GITHUB_STEP_SUMMARY |
| 101 | + echo "- **Build Status**: ✅ Completed" >> $GITHUB_STEP_SUMMARY |
0 commit comments