11name : Deploy Apps
22
33on :
4- push :
5- branches : [ main ]
6- paths :
7- - ' */package.json'
8- - ' */index.html'
9- - ' */**'
4+ workflow_run :
5+ workflows : ["Test Apps"]
6+ types :
7+ - completed
8+ branches : [main]
109 pull_request :
1110 types : [opened, synchronize, reopened, closed]
1211 paths :
1615
1716jobs :
1817 build-and-deploy :
19- if : github.event.action != 'closed'
18+ if : |
19+ (github.event_name == 'pull_request' && github.event.action != 'closed') ||
20+ (github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success')
2021 runs-on : ubuntu-latest
2122 permissions :
2223 contents : write
2324 pull-requests : write
2425
2526 steps :
2627 - uses : actions/checkout@v3
28+ with :
29+ ref : ${{ github.event.workflow_run.head_sha }}
2730
2831 - name : Set up Node.js
2932 uses : actions/setup-node@v3
@@ -33,20 +36,76 @@ jobs:
3336 - name : Install root dependencies
3437 run : npm install
3538
39+ - name : Show initial directory structure
40+ run : |
41+ echo "Current directory structure:"
42+ tree -L 3 || (apt-get update && apt-get install -y tree && tree -L 3)
43+
3644 - name : Build all apps
3745 run : |
3846 if [[ "${{ github.event_name }}" == "pull_request" ]]; then
3947 npm run build pr-preview ${{ github.event.pull_request.number }}
48+ echo "PR Preview build output structure:"
49+ tree pr-preview -L 3
4050 else
4151 npm run build _site
52+ echo "_site build output structure:"
53+ tree _site -L 3
4254 fi
4355
4456 - name : Deploy to GitHub Pages
4557 uses : peaceiris/actions-gh-pages@v3
4658 with :
4759 github_token : ${{ secrets.GITHUB_TOKEN }}
4860 publish_dir : ${{ github.event_name == 'pull_request' && './pr-preview' || './_site' }}
49- destination_dir : ${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.pull_request.number) || '.' }}
61+ destination_dir : ${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.pull_request.number) || 'main' }}
62+ keep_files : true
63+ enable_jekyll : false
64+
65+ - name : Create and deploy root index.html
66+ if : github.event_name != 'pull_request'
67+ run : |
68+ mkdir -p root
69+ cat > root/index.html << 'EOL'
70+ <!DOCTYPE html>
71+ <html>
72+ <head>
73+ <title>Pollinations Hive</title>
74+ <meta http-equiv="refresh" content="0; url=./main/" />
75+ <style>
76+ body {
77+ font-family: system-ui, -apple-system, sans-serif;
78+ max-width: 800px;
79+ margin: 2rem auto;
80+ padding: 0 1rem;
81+ line-height: 1.5;
82+ }
83+ a {
84+ color: #0366d6;
85+ text-decoration: none;
86+ }
87+ a:hover {
88+ text-decoration: underline;
89+ }
90+ </style>
91+ </head>
92+ <body>
93+ <h1>Pollinations Hive</h1>
94+ <p>Redirecting to <a href="./main/">main deployment</a>...</p>
95+ <script>
96+ window.location.href = './main/';
97+ </script>
98+ </body>
99+ </html>
100+ EOL
101+
102+ - name : Deploy root index
103+ if : github.event_name != 'pull_request'
104+ uses : peaceiris/actions-gh-pages@v3
105+ with :
106+ github_token : ${{ secrets.GITHUB_TOKEN }}
107+ publish_dir : ./root
108+ destination_dir : .
50109 keep_files : true
51110 enable_jekyll : false
52111
@@ -73,11 +132,21 @@ jobs:
73132 with :
74133 ref : gh-pages
75134
135+ - name : Show directory before cleanup
136+ run : |
137+ echo "Directory structure before cleanup:"
138+ tree -L 3 || (apt-get update && apt-get install -y tree && tree -L 3)
139+
76140 - name : Remove PR Preview
77141 run : |
78142 rm -rf pr-${{ github.event.pull_request.number }}
79143 git config user.name github-actions
80144 git config user.email github-actions@github.com
81145 git add .
82146 git commit -m "Remove PR preview for #${{ github.event.pull_request.number }}" || echo "No changes to commit"
83- git push
147+ git push
148+
149+ - name : Show directory after cleanup
150+ run : |
151+ echo "Directory structure after cleanup:"
152+ tree -L 3 || (apt-get update && apt-get install -y tree && tree -L 3)
0 commit comments