1
0

publish_and_install.yml 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. name: Publish & Install
  2. on:
  3. workflow_dispatch:
  4. push:
  5. branches:
  6. - master
  7. - minor
  8. - major
  9. paths:
  10. - 'packages/**'
  11. - 'package.json'
  12. - 'package-lock.json'
  13. pull_request:
  14. branches:
  15. - master
  16. - major
  17. - minor
  18. paths:
  19. - 'packages/**'
  20. - 'package.json'
  21. - 'package-lock.json'
  22. defaults:
  23. run:
  24. shell: bash
  25. concurrency:
  26. group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
  27. cancel-in-progress: true
  28. jobs:
  29. # Job 1: Build all packages and publish to Verdaccio (runs once)
  30. build_and_publish:
  31. runs-on: ubuntu-latest
  32. permissions:
  33. contents: read
  34. steps:
  35. - uses: actions/checkout@v4
  36. - name: Use Node.js 22.x
  37. uses: actions/setup-node@v4
  38. with:
  39. node-version: 22.x
  40. cache: 'npm'
  41. - name: Install Verdaccio
  42. run: |
  43. npm install -g verdaccio
  44. npm install -g wait-on
  45. mkdir -p $HOME/.config/verdaccio
  46. cp -v ./.github/workflows/verdaccio/config.yaml $HOME/.config/verdaccio/config.yaml
  47. nohup verdaccio --config $HOME/.config/verdaccio/config.yaml &
  48. wait-on http://localhost:4873
  49. TOKEN_RES=$(curl -XPUT \
  50. -H "Content-type: application/json" \
  51. -d '{ "name": "test", "password": "test" }' \
  52. 'http://localhost:4873/-/user/org.couchdb.user:test')
  53. TOKEN=$(echo "$TOKEN_RES" | jq -r '.token')
  54. npm set //localhost:4873/:_authToken $TOKEN
  55. - name: npm install
  56. run: npm install
  57. env:
  58. CI: true
  59. - name: Publish to Verdaccio
  60. run: |
  61. nohup verdaccio --config $HOME/.config/verdaccio/config.yaml &
  62. wait-on http://localhost:4873
  63. npx lerna publish prepatch --preid ci --no-push --no-git-tag-version --no-commit-hooks --force-publish "*" --yes --dist-tag ci --registry http://localhost:4873
  64. - name: Package Verdaccio storage
  65. run: |
  66. cd $HOME/.config/verdaccio
  67. tar -czf verdaccio-storage.tar.gz storage htpasswd
  68. - name: Upload Verdaccio storage
  69. uses: actions/upload-artifact@v4
  70. with:
  71. name: verdaccio-storage
  72. path: ~/.config/verdaccio/verdaccio-storage.tar.gz
  73. retention-days: 1
  74. # Job 2: Test installation on various OS/Node combinations
  75. test:
  76. needs: build_and_publish
  77. runs-on: ${{ matrix.os }}
  78. permissions:
  79. contents: read
  80. strategy:
  81. matrix:
  82. # For PRs: run minimal matrix (1 job). For push: run full matrix (9 jobs)
  83. os: ${{ github.event_name == 'pull_request' && fromJSON('["ubuntu-latest"]') || fromJSON('["ubuntu-latest", "windows-latest", "macos-latest"]') }}
  84. node-version: ${{ github.event_name == 'pull_request' && fromJSON('["22.x"]') || fromJSON('["20.x", "22.x", "24.x"]') }}
  85. fail-fast: false
  86. steps:
  87. - uses: actions/checkout@v4
  88. - name: Use Node.js ${{ matrix.node-version }}
  89. uses: actions/setup-node@v4
  90. with:
  91. node-version: ${{ matrix.node-version }}
  92. - name: Download Verdaccio storage
  93. uses: actions/download-artifact@v4
  94. with:
  95. name: verdaccio-storage
  96. path: ~/verdaccio-download
  97. - name: Setup Verdaccio with pre-built packages
  98. run: |
  99. npm install -g verdaccio
  100. npm install -g wait-on
  101. mkdir -p $HOME/.config/verdaccio
  102. cp -v ./.github/workflows/verdaccio/config.yaml $HOME/.config/verdaccio/config.yaml
  103. # Extract the pre-built storage
  104. cd $HOME/.config/verdaccio
  105. tar -xzf ~/verdaccio-download/verdaccio-storage.tar.gz
  106. # Start Verdaccio
  107. nohup verdaccio --config $HOME/.config/verdaccio/config.yaml &
  108. wait-on http://localhost:4873
  109. # Setup auth token
  110. TOKEN_RES=$(curl -XPUT \
  111. -H "Content-type: application/json" \
  112. -d '{ "name": "test", "password": "test" }' \
  113. 'http://localhost:4873/-/user/org.couchdb.user:test')
  114. TOKEN=$(echo "$TOKEN_RES" | jq -r '.token')
  115. npm set //localhost:4873/:_authToken $TOKEN
  116. - name: Windows dependencies
  117. if: matrix.os == 'windows-latest'
  118. run: npm install -g @angular/cli
  119. - name: Install via @vendure/create
  120. run: |
  121. mkdir -p $HOME/install
  122. cd $HOME/install
  123. nohup verdaccio --config $HOME/.config/verdaccio/config.yaml &
  124. wait-on http://localhost:4873
  125. npm set registry=http://localhost:4873
  126. npm dist-tag ls @vendure/create
  127. npx @vendure/create@ci test-app --ci --use-npm --log-level info
  128. - name: Server smoke tests
  129. run: |
  130. cd $HOME/install/test-app
  131. npm run dev &
  132. node $GITHUB_WORKSPACE/.github/workflows/scripts/smoke-tests
  133. - name: Kill dev server after smoke tests
  134. shell: bash
  135. run: |
  136. # Kill everything on port 3000 so dashboard tests can start fresh
  137. # (npm run dev spawns child processes that aren't killed by killing the parent)
  138. if [[ "$RUNNER_OS" == "Windows" ]]; then
  139. # Windows: use netstat to find PID and taskkill
  140. netstat -ano | grep ':3000' | grep 'LISTENING' | awk '{print $5}' | head -1 | xargs -r taskkill //F //PID 2>/dev/null || true
  141. else
  142. # Linux/macOS: use lsof
  143. lsof -ti:3000 | xargs kill 2>/dev/null || true
  144. fi
  145. - name: Copy files (Windows)
  146. if: runner.os == 'Windows'
  147. shell: pwsh
  148. run: |
  149. cd ~/install/test-app
  150. New-Item -ItemType Directory -Force -Path src/plugins/test-plugin
  151. Copy-Item "$env:GITHUB_WORKSPACE/.github/workflows/scripts/vite.config.mts" -Destination "./vite.config.mts"
  152. Copy-Item "$env:GITHUB_WORKSPACE/.github/workflows/scripts/test-plugin/*" -Destination "src/plugins/test-plugin/" -Recurse -Force
  153. Copy-Item "$env:GITHUB_WORKSPACE/.github/workflows/scripts/setup-test-plugin.js" -Destination "./setup-test-plugin.js"
  154. - name: Copy files (Unix)
  155. if: runner.os != 'Windows'
  156. run: |
  157. cd ~/install/test-app
  158. mkdir -p src/plugins/test-plugin
  159. cp "$GITHUB_WORKSPACE/.github/workflows/scripts/vite.config.mts" ./vite.config.mts
  160. cp -r "$GITHUB_WORKSPACE/.github/workflows/scripts/test-plugin/." src/plugins/test-plugin/
  161. cp "$GITHUB_WORKSPACE/.github/workflows/scripts/setup-test-plugin.js" ./setup-test-plugin.js
  162. - name: Run setup script
  163. shell: bash
  164. run: |
  165. cd ~/install/test-app
  166. node setup-test-plugin.js
  167. - name: Cache Playwright browsers
  168. uses: actions/cache@v4
  169. with:
  170. path: ~/.cache/ms-playwright
  171. key: playwright-${{ runner.os }}-${{ hashFiles('**/package-lock.json') }}
  172. - name: Install Playwright
  173. run: |
  174. cd $GITHUB_WORKSPACE
  175. npm install playwright
  176. npx playwright install-deps
  177. npx playwright install chromium
  178. - name: Start dashboard and run tests
  179. run: |
  180. cd ~/install/test-app
  181. # start the dev server in the background
  182. npm run dev &
  183. DEV_PID=$!
  184. # Wait for the dev server to be available (use /health endpoint, not root)
  185. wait-on http://localhost:3000/health --timeout 60000
  186. # Start the dashboard with --strictPort to fail fast if port is in use
  187. npx vite --port 5173 --strictPort &
  188. DASHBOARD_PID=$!
  189. # Give Vite a moment to start or fail
  190. sleep 3
  191. # Check if Vite process is still running (it will exit immediately if port is in use)
  192. if ! kill -0 $DASHBOARD_PID 2>/dev/null; then
  193. echo "Vite failed to start - port 5173 may be in use"
  194. exit 1
  195. fi
  196. # Wait for the dashboard to be available
  197. wait-on http://localhost:5173 --timeout 120000
  198. # Run the dashboard tests
  199. node $GITHUB_WORKSPACE/.github/workflows/scripts/dashboard-tests.js
  200. # Clean up dashboard process
  201. kill $DASHBOARD_PID 2>/dev/null || true
  202. # Clean up dev server process
  203. kill $DEV_PID 2>/dev/null || true
  204. - name: Upload dashboard test screenshots
  205. if: always()
  206. uses: actions/upload-artifact@v4
  207. with:
  208. name: dashboard-test-screenshots-${{ matrix.os }}-${{ matrix.node-version }}
  209. path: /tmp/dashboard-test-*.png
  210. retention-days: 28