You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

414 lines
14 KiB

  1. name: Build + Publish
  2. on:
  3. push:
  4. branches:
  5. - main
  6. tags:
  7. - 'v*'
  8. env:
  9. BASE_DEV_VERSION: 2.5.0
  10. jobs:
  11. build:
  12. name: Build
  13. runs-on: ubuntu-latest
  14. permissions:
  15. packages: write
  16. steps:
  17. - uses: actions/checkout@v3
  18. - name: Set Build Variables
  19. run: |
  20. if [[ "$GITHUB_REF" =~ ^refs/tags/v* ]]; then
  21. echo "Using TAG mode: $GITHUB_REF_NAME"
  22. echo "REL_VERSION=$GITHUB_REF_NAME" >> $GITHUB_ENV
  23. echo "REL_VERSION_STRICT=${GITHUB_REF_NAME#?}" >> $GITHUB_ENV
  24. else
  25. echo "Using BRANCH mode: v$BASE_DEV_VERSION-dev.$GITHUB_RUN_NUMBER"
  26. echo "REL_VERSION=v$BASE_DEV_VERSION-dev.$GITHUB_RUN_NUMBER" >> $GITHUB_ENV
  27. echo "REL_VERSION_STRICT=$BASE_DEV_VERSION-dev.$GITHUB_RUN_NUMBER" >> $GITHUB_ENV
  28. fi
  29. - name: Disable DEV Flag + Set Version
  30. run: |
  31. sudo apt-get install jq -y
  32. mv package.json pkg-temp.json
  33. jq --arg vs "$REL_VERSION_STRICT" -r '. + {dev:false, version:$vs}' pkg-temp.json > package.json
  34. rm pkg-temp.json
  35. cat package.json
  36. - name: Login to DockerHub
  37. uses: docker/login-action@v2.1.0
  38. with:
  39. username: ${{ secrets.DOCKERHUB_USERNAME }}
  40. password: ${{ secrets.DOCKERHUB_TOKEN }}
  41. - name: Login to GitHub Container Registry
  42. uses: docker/login-action@v2.1.0
  43. with:
  44. registry: ghcr.io
  45. username: ${{ github.repository_owner }}
  46. password: ${{ secrets.GITHUB_TOKEN }}
  47. - name: Build and push Docker images
  48. uses: docker/build-push-action@v4.0.0
  49. with:
  50. context: .
  51. file: dev/build/Dockerfile
  52. push: true
  53. tags: |
  54. requarks/wiki:canary
  55. requarks/wiki:canary-${{ env.REL_VERSION_STRICT }}
  56. ghcr.io/requarks/wiki:canary
  57. ghcr.io/requarks/wiki:canary-${{ env.REL_VERSION_STRICT }}
  58. - name: Extract compiled files
  59. run: |
  60. mkdir -p _dist
  61. docker create --name wiki ghcr.io/requarks/wiki:canary-$REL_VERSION_STRICT
  62. docker cp wiki:/wiki _dist
  63. docker rm wiki
  64. rm _dist/wiki/config.yml
  65. cp ./config.sample.yml _dist/wiki/config.sample.yml
  66. find _dist/wiki/ -printf "%P\n" | tar -czf wiki-js.tar.gz --no-recursion -C _dist/wiki/ -T -
  67. - name: Upload a Build Artifact
  68. uses: actions/upload-artifact@v3.1.2
  69. with:
  70. name: drop
  71. path: wiki-js.tar.gz
  72. cypress:
  73. name: Run Cypress Tests
  74. runs-on: ubuntu-latest
  75. needs: [build]
  76. strategy:
  77. matrix:
  78. dbtype: [postgres, mysql, mariadb, mssql, sqlite]
  79. steps:
  80. - uses: actions/checkout@v3
  81. - name: Set Test Variables
  82. run: |
  83. if [[ "$GITHUB_REF" =~ ^refs/tags/v* ]]; then
  84. echo "Using TAG mode: $GITHUB_REF_NAME"
  85. echo "REL_VERSION_STRICT=${GITHUB_REF_NAME#?}" >> $GITHUB_ENV
  86. else
  87. echo "Using BRANCH mode: v$BASE_DEV_VERSION-dev.$GITHUB_RUN_NUMBER"
  88. echo "REL_VERSION_STRICT=$BASE_DEV_VERSION-dev.$GITHUB_RUN_NUMBER" >> $GITHUB_ENV
  89. fi
  90. - name: Run Tests
  91. env:
  92. MATRIXENV: ${{ matrix.dbtype }}
  93. CYPRESS_KEY: ${{ secrets.CYPRESS_KEY }}
  94. run: |
  95. chmod u+x dev/cypress/ci-setup.sh
  96. dev/cypress/ci-setup.sh
  97. docker run --name cypress --ipc=host --shm-size 1G -v $GITHUB_WORKSPACE:/e2e -w /e2e cypress/included:4.9.0 --record --key "$CYPRESS_KEY" --headless --group "$MATRIXENV" --ci-build-id "$REL_VERSION_STRICT-run$GITHUB_RUN_NUMBER.$GITHUB_RUN_ATTEMPT" --tag "$REL_VERSION_STRICT" --config baseUrl=http://172.17.0.1:3000
  98. arm:
  99. name: ARM Build
  100. runs-on: ubuntu-latest
  101. needs: [cypress]
  102. permissions:
  103. packages: write
  104. strategy:
  105. matrix:
  106. include:
  107. - platform: linux/arm64
  108. docker: arm64
  109. - platform: linux/arm/v7
  110. docker: armv7
  111. steps:
  112. - uses: actions/checkout@v3
  113. - name: Set Version Variables
  114. run: |
  115. if [[ "$GITHUB_REF" =~ ^refs/tags/v* ]]; then
  116. echo "Using TAG mode: $GITHUB_REF_NAME"
  117. echo "REL_VERSION_STRICT=${GITHUB_REF_NAME#?}" >> $GITHUB_ENV
  118. else
  119. echo "Using BRANCH mode: v$BASE_DEV_VERSION-dev.$GITHUB_RUN_NUMBER"
  120. echo "REL_VERSION_STRICT=$BASE_DEV_VERSION-dev.$GITHUB_RUN_NUMBER" >> $GITHUB_ENV
  121. fi
  122. - name: Set up QEMU
  123. uses: docker/setup-qemu-action@v2.1.0
  124. - name: Set up Docker Buildx
  125. uses: docker/setup-buildx-action@v2.4.0
  126. - name: Login to DockerHub
  127. uses: docker/login-action@v2.1.0
  128. with:
  129. username: ${{ secrets.DOCKERHUB_USERNAME }}
  130. password: ${{ secrets.DOCKERHUB_TOKEN }}
  131. - name: Login to GitHub Container Registry
  132. uses: docker/login-action@v2.1.0
  133. with:
  134. registry: ghcr.io
  135. username: ${{ github.repository_owner }}
  136. password: ${{ secrets.GITHUB_TOKEN }}
  137. - name: Download a Build Artifact
  138. uses: actions/download-artifact@v3.0.2
  139. with:
  140. name: drop
  141. path: drop
  142. - name: Extract Build
  143. run: |
  144. mkdir -p build
  145. tar -xzf $GITHUB_WORKSPACE/drop/wiki-js.tar.gz -C $GITHUB_WORKSPACE/build --exclude=node_modules
  146. - name: Build and push Docker images
  147. uses: docker/build-push-action@v4.0.0
  148. with:
  149. context: .
  150. file: dev/build-arm/Dockerfile
  151. platforms: ${{ matrix.platform }}
  152. provenance: false
  153. push: true
  154. tags: |
  155. requarks/wiki:canary-${{ matrix.docker }}-${{ env.REL_VERSION_STRICT }}
  156. ghcr.io/requarks/wiki:canary-${{ matrix.docker }}-${{ env.REL_VERSION_STRICT }}
  157. windows:
  158. name: Windows Build
  159. runs-on: windows-latest
  160. needs: [cypress]
  161. steps:
  162. - name: Setup Node.js environment
  163. uses: actions/setup-node@v3.6.0
  164. with:
  165. node-version: 18.x
  166. - name: Download a Build Artifact
  167. uses: actions/download-artifact@v3.0.2
  168. with:
  169. name: drop
  170. path: drop
  171. - name: Extract Build
  172. run: |
  173. mkdir -p win
  174. tar -xzf $env:GITHUB_WORKSPACE\drop\wiki-js.tar.gz -C $env:GITHUB_WORKSPACE\win
  175. Copy-Item win\node_modules\extract-files\package.json patch-extractfile.json -Force
  176. Remove-Item -Path win\node_modules -Force -Recurse
  177. - name: Install Dependencies
  178. run: |
  179. yarn --production --frozen-lockfile --non-interactive
  180. yarn patch-package
  181. working-directory: win
  182. - name: Fix patched packages
  183. run: |
  184. Copy-Item patch-extractfile.json win\node_modules\extract-files\package.json -Force
  185. - name: Create Bundle
  186. run: tar -czf wiki-js-windows.tar.gz -C $env:GITHUB_WORKSPACE\win .
  187. - name: Upload a Build Artifact
  188. uses: actions/upload-artifact@v3.1.2
  189. with:
  190. name: drop-win
  191. path: wiki-js-windows.tar.gz
  192. beta:
  193. name: Publish Beta Images
  194. runs-on: ubuntu-latest
  195. if: startsWith(github.ref, 'refs/tags/v')
  196. needs: [build, arm, windows]
  197. permissions:
  198. packages: write
  199. steps:
  200. - name: Set Version Variables
  201. run: |
  202. echo "Using TAG mode: $GITHUB_REF_NAME"
  203. echo "REL_VERSION_STRICT=${GITHUB_REF_NAME#?}" >> $GITHUB_ENV
  204. - name: Login to DockerHub
  205. uses: docker/login-action@v2.1.0
  206. with:
  207. username: ${{ secrets.DOCKERHUB_USERNAME }}
  208. password: ${{ secrets.DOCKERHUB_TOKEN }}
  209. - name: Login to GitHub Container Registry
  210. uses: docker/login-action@v2.1.0
  211. with:
  212. registry: ghcr.io
  213. username: ${{ github.repository_owner }}
  214. password: ${{ secrets.GITHUB_TOKEN }}
  215. - name: Create and Push Manifests
  216. run: |
  217. echo "Creating the manifests..."
  218. docker manifest create requarks/wiki:beta-$REL_VERSION_STRICT requarks/wiki:canary-$REL_VERSION_STRICT requarks/wiki:canary-arm64-$REL_VERSION_STRICT requarks/wiki:canary-armv7-$REL_VERSION_STRICT
  219. docker manifest create ghcr.io/requarks/wiki:beta-$REL_VERSION_STRICT ghcr.io/requarks/wiki:canary-$REL_VERSION_STRICT ghcr.io/requarks/wiki:canary-arm64-$REL_VERSION_STRICT ghcr.io/requarks/wiki:canary-armv7-$REL_VERSION_STRICT
  220. echo "Pushing the manifests..."
  221. docker manifest push -p requarks/wiki:beta-$REL_VERSION_STRICT
  222. docker manifest push -p ghcr.io/requarks/wiki:beta-$REL_VERSION_STRICT
  223. release:
  224. name: Publish Release Images
  225. runs-on: ubuntu-latest
  226. if: startsWith(github.ref, 'refs/tags/v')
  227. environment: prod
  228. needs: [beta]
  229. permissions:
  230. packages: write
  231. contents: write
  232. steps:
  233. - name: Set Version Variables
  234. run: |
  235. echo "Using TAG mode: $GITHUB_REF_NAME"
  236. echo "REL_VERSION_STRICT=${GITHUB_REF_NAME#?}" >> $GITHUB_ENV
  237. - name: Login to DockerHub
  238. uses: docker/login-action@v2.1.0
  239. with:
  240. username: ${{ secrets.DOCKERHUB_USERNAME }}
  241. password: ${{ secrets.DOCKERHUB_TOKEN }}
  242. - name: Login to GitHub Container Registry
  243. uses: docker/login-action@v2.1.0
  244. with:
  245. registry: ghcr.io
  246. username: ${{ github.repository_owner }}
  247. password: ${{ secrets.GITHUB_TOKEN }}
  248. - name: Create and Push Manifests
  249. run: |
  250. echo "Fetching semver tool..."
  251. curl -LJO https://static.requarks.io/semver
  252. chmod +x semver
  253. MAJOR=`./semver get major $REL_VERSION_STRICT`
  254. MINOR=`./semver get minor $REL_VERSION_STRICT`
  255. MAJORMINOR="$MAJOR.$MINOR"
  256. echo "Using major $MAJOR and minor $MINOR..."
  257. echo "Creating the manifests..."
  258. docker manifest create requarks/wiki:$REL_VERSION_STRICT requarks/wiki:canary-$REL_VERSION_STRICT requarks/wiki:canary-arm64-$REL_VERSION_STRICT requarks/wiki:canary-armv7-$REL_VERSION_STRICT
  259. docker manifest create requarks/wiki:$MAJOR requarks/wiki:canary-$REL_VERSION_STRICT requarks/wiki:canary-arm64-$REL_VERSION_STRICT requarks/wiki:canary-armv7-$REL_VERSION_STRICT
  260. docker manifest create requarks/wiki:$MAJORMINOR requarks/wiki:canary-$REL_VERSION_STRICT requarks/wiki:canary-arm64-$REL_VERSION_STRICT requarks/wiki:canary-armv7-$REL_VERSION_STRICT
  261. docker manifest create requarks/wiki:latest requarks/wiki:canary-$REL_VERSION_STRICT requarks/wiki:canary-arm64-$REL_VERSION_STRICT requarks/wiki:canary-armv7-$REL_VERSION_STRICT
  262. docker manifest create ghcr.io/requarks/wiki:$REL_VERSION_STRICT ghcr.io/requarks/wiki:canary-$REL_VERSION_STRICT ghcr.io/requarks/wiki:canary-arm64-$REL_VERSION_STRICT ghcr.io/requarks/wiki:canary-armv7-$REL_VERSION_STRICT
  263. docker manifest create ghcr.io/requarks/wiki:$MAJOR ghcr.io/requarks/wiki:canary-$REL_VERSION_STRICT ghcr.io/requarks/wiki:canary-arm64-$REL_VERSION_STRICT ghcr.io/requarks/wiki:canary-armv7-$REL_VERSION_STRICT
  264. docker manifest create ghcr.io/requarks/wiki:$MAJORMINOR ghcr.io/requarks/wiki:canary-$REL_VERSION_STRICT ghcr.io/requarks/wiki:canary-arm64-$REL_VERSION_STRICT ghcr.io/requarks/wiki:canary-armv7-$REL_VERSION_STRICT
  265. docker manifest create ghcr.io/requarks/wiki:latest ghcr.io/requarks/wiki:canary-$REL_VERSION_STRICT ghcr.io/requarks/wiki:canary-arm64-$REL_VERSION_STRICT ghcr.io/requarks/wiki:canary-armv7-$REL_VERSION_STRICT
  266. echo "Pushing the manifests..."
  267. docker manifest push -p requarks/wiki:$REL_VERSION_STRICT
  268. docker manifest push -p requarks/wiki:$MAJOR
  269. docker manifest push -p requarks/wiki:$MAJORMINOR
  270. docker manifest push -p requarks/wiki:latest
  271. docker manifest push -p ghcr.io/requarks/wiki:$REL_VERSION_STRICT
  272. docker manifest push -p ghcr.io/requarks/wiki:$MAJOR
  273. docker manifest push -p ghcr.io/requarks/wiki:$MAJORMINOR
  274. docker manifest push -p ghcr.io/requarks/wiki:latest
  275. - name: Download Linux Build
  276. uses: actions/download-artifact@v3.0.2
  277. with:
  278. name: drop
  279. path: drop
  280. - name: Download Windows Build
  281. uses: actions/download-artifact@v3.0.2
  282. with:
  283. name: drop-win
  284. path: drop-win
  285. - name: Generate Changelog
  286. id: changelog
  287. uses: Requarks/changelog-action@v1
  288. with:
  289. token: ${{ github.token }}
  290. tag: ${{ github.ref_name }}
  291. writeToFile: false
  292. - name: Update GitHub Release
  293. uses: ncipollo/release-action@v1.12.0
  294. with:
  295. allowUpdates: true
  296. draft: false
  297. makeLatest: true
  298. name: ${{ github.ref_name }}
  299. body: ${{ steps.changelog.outputs.changes }}
  300. token: ${{ github.token }}
  301. artifacts: 'drop/wiki-js.tar.gz,drop-win/wiki-js-windows.tar.gz'
  302. - name: Notify Slack Releases Channel
  303. uses: slackapi/slack-github-action@v1.18.0
  304. with:
  305. payload: |
  306. {
  307. "text": "Wiki.js ${{ github.ref_name }} has been released."
  308. }
  309. env:
  310. SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
  311. SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
  312. - name: Notify Telegram Channel
  313. uses: appleboy/telegram-action@v0.1.1
  314. with:
  315. to: ${{ secrets.TELEGRAM_TO }}
  316. token: ${{ secrets.TELEGRAM_TOKEN }}
  317. format: markdown
  318. disable_web_page_preview: true
  319. message: |
  320. Wiki.js *${{ github.ref_name }}* has been released!
  321. See [release notes](https://github.com/requarks/wiki/releases) for details.
  322. - name: Notify Discord Channel
  323. uses: sebastianpopp/discord-action@v1.0
  324. with:
  325. webhook: ${{ secrets.DISCORD_WEBHOOK }}
  326. message: Wiki.js ${{ github.ref_name }} has been released! See https://github.com/requarks/wiki/releases for details.
  327. build-do-image:
  328. name: Build DigitalOcean Image
  329. runs-on: ubuntu-latest
  330. needs: [release]
  331. steps:
  332. - uses: actions/checkout@v3
  333. - name: Set Version Variables
  334. run: |
  335. echo "Using TAG mode: $GITHUB_REF_NAME"
  336. echo "REL_VERSION_STRICT=${GITHUB_REF_NAME#?}" >> $GITHUB_ENV
  337. - name: Install Packer
  338. run: |
  339. curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
  340. sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
  341. sudo apt-get update && sudo apt-get install packer
  342. - name: Build Droplet Image
  343. env:
  344. DIGITALOCEAN_API_TOKEN: ${{ secrets.DO_TOKEN }}
  345. WIKI_APP_VERSION: ${{ env.REL_VERSION_STRICT }}
  346. working-directory: dev/packer
  347. run: |
  348. packer build digitalocean.json