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.

387 lines
13 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@v2
  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@v1
  38. with:
  39. username: ${{ secrets.DOCKERHUB_USERNAME }}
  40. password: ${{ secrets.DOCKERHUB_TOKEN }}
  41. - name: Login to GitHub Container Registry
  42. uses: docker/login-action@v1
  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@v2.9.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@v2.3.1
  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@v2
  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@v2
  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@v1
  124. - name: Set up Docker Buildx
  125. uses: docker/setup-buildx-action@v1
  126. - name: Login to DockerHub
  127. uses: docker/login-action@v1
  128. with:
  129. username: ${{ secrets.DOCKERHUB_USERNAME }}
  130. password: ${{ secrets.DOCKERHUB_TOKEN }}
  131. - name: Login to GitHub Container Registry
  132. uses: docker/login-action@v1
  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@v2.1.0
  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@v2.9.0
  148. with:
  149. context: .
  150. file: dev/build-arm/Dockerfile
  151. platforms: ${{ matrix.platform }}
  152. push: true
  153. tags: |
  154. requarks/wiki:canary-${{ matrix.docker }}-${{ env.REL_VERSION_STRICT }}
  155. ghcr.io/requarks/wiki:canary-${{ matrix.docker }}-${{ env.REL_VERSION_STRICT }}
  156. windows:
  157. name: Windows Build
  158. runs-on: windows-latest
  159. needs: [cypress]
  160. steps:
  161. - name: Setup Node.js environment
  162. uses: actions/setup-node@v2.5.1
  163. with:
  164. node-version: 12.x
  165. - name: Download a Build Artifact
  166. uses: actions/download-artifact@v2.1.0
  167. with:
  168. name: drop
  169. path: drop
  170. - name: Extract Build
  171. run: |
  172. mkdir -p win
  173. tar -xzf $env:GITHUB_WORKSPACE\drop\wiki-js.tar.gz -C $env:GITHUB_WORKSPACE\win --exclude=node_modules
  174. - name: Install Dependencies
  175. run: yarn --production --frozen-lockfile --non-interactive
  176. working-directory: win
  177. - name: Create Bundle
  178. run: tar -czf wiki-js-windows.tar.gz -C $env:GITHUB_WORKSPACE\win .
  179. - name: Upload a Build Artifact
  180. uses: actions/upload-artifact@v2.3.1
  181. with:
  182. name: drop-win
  183. path: wiki-js-windows.tar.gz
  184. beta:
  185. name: Publish Beta Images
  186. runs-on: ubuntu-latest
  187. if: startsWith(github.ref, 'refs/tags/v')
  188. needs: [build, arm, windows]
  189. permissions:
  190. packages: write
  191. steps:
  192. - name: Set Version Variables
  193. run: |
  194. echo "Using TAG mode: $GITHUB_REF_NAME"
  195. echo "REL_VERSION_STRICT=${GITHUB_REF_NAME#?}" >> $GITHUB_ENV
  196. - name: Login to DockerHub
  197. uses: docker/login-action@v1
  198. with:
  199. username: ${{ secrets.DOCKERHUB_USERNAME }}
  200. password: ${{ secrets.DOCKERHUB_TOKEN }}
  201. - name: Login to GitHub Container Registry
  202. uses: docker/login-action@v1
  203. with:
  204. registry: ghcr.io
  205. username: ${{ github.repository_owner }}
  206. password: ${{ secrets.GITHUB_TOKEN }}
  207. - name: Create and Push Manifests
  208. run: |
  209. echo "Creating the manifests..."
  210. 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
  211. 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
  212. echo "Pushing the manifests..."
  213. docker manifest push -p requarks/wiki:beta-$REL_VERSION_STRICT
  214. docker manifest push -p ghcr.io/requarks/wiki:beta-$REL_VERSION_STRICT
  215. release:
  216. name: Publish Release Images
  217. runs-on: ubuntu-latest
  218. if: startsWith(github.ref, 'refs/tags/v')
  219. environment: prod
  220. needs: [beta]
  221. permissions:
  222. packages: write
  223. contents: write
  224. steps:
  225. - name: Set Version Variables
  226. run: |
  227. echo "Using TAG mode: $GITHUB_REF_NAME"
  228. echo "REL_VERSION_STRICT=${GITHUB_REF_NAME#?}" >> $GITHUB_ENV
  229. - name: Login to DockerHub
  230. uses: docker/login-action@v1
  231. with:
  232. username: ${{ secrets.DOCKERHUB_USERNAME }}
  233. password: ${{ secrets.DOCKERHUB_TOKEN }}
  234. - name: Login to GitHub Container Registry
  235. uses: docker/login-action@v1
  236. with:
  237. registry: ghcr.io
  238. username: ${{ github.repository_owner }}
  239. password: ${{ secrets.GITHUB_TOKEN }}
  240. - name: Create and Push Manifests
  241. run: |
  242. echo "Fetching semver tool..."
  243. curl -LJO https://static.requarks.io/semver
  244. chmod +x semver
  245. MAJOR=`./semver get major $REL_VERSION_STRICT`
  246. MINOR=`./semver get minor $REL_VERSION_STRICT`
  247. MAJORMINOR="$MAJOR.$MINOR"
  248. echo "Using major $MAJOR and minor $MINOR..."
  249. echo "Creating the manifests..."
  250. 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
  251. 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
  252. 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
  253. 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
  254. 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
  255. 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
  256. 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
  257. 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
  258. echo "Pushing the manifests..."
  259. docker manifest push -p requarks/wiki:$REL_VERSION_STRICT
  260. docker manifest push -p requarks/wiki:$MAJOR
  261. docker manifest push -p requarks/wiki:$MAJORMINOR
  262. docker manifest push -p requarks/wiki:latest
  263. docker manifest push -p ghcr.io/requarks/wiki:$REL_VERSION_STRICT
  264. docker manifest push -p ghcr.io/requarks/wiki:$MAJOR
  265. docker manifest push -p ghcr.io/requarks/wiki:$MAJORMINOR
  266. docker manifest push -p ghcr.io/requarks/wiki:latest
  267. - name: Download Linux Build
  268. uses: actions/download-artifact@v2.1.0
  269. with:
  270. name: drop
  271. path: drop
  272. - name: Download Windows Build
  273. uses: actions/download-artifact@v2.1.0
  274. with:
  275. name: drop-win
  276. path: drop-win
  277. - name: Generate Changelog
  278. id: changelog
  279. uses: Requarks/changelog-action@v1
  280. with:
  281. token: ${{ github.token }}
  282. tag: ${{ github.ref_name }}
  283. writeToFile: false
  284. - name: Update GitHub Release
  285. uses: ncipollo/release-action@v1
  286. with:
  287. allowUpdates: true
  288. draft: false
  289. name: ${{ github.ref_name }}
  290. body: ${{ steps.changelog.outputs.changes }}
  291. token: ${{ github.token }}
  292. artifacts: 'drop/wiki-js.tar.gz,drop-win/wiki-js-windows.tar.gz'
  293. - name: Notify Slack Releases Channel
  294. uses: slackapi/slack-github-action@v1.18.0
  295. with:
  296. payload: |
  297. {
  298. "text": "Wiki.js ${{ github.ref_name }} has been released."
  299. }
  300. env:
  301. SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
  302. SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
  303. build-do-image:
  304. name: Build DigitalOcean Image
  305. runs-on: ubuntu-latest
  306. needs: [release]
  307. steps:
  308. - uses: actions/checkout@v2
  309. - name: Set Version Variables
  310. run: |
  311. echo "Using TAG mode: $GITHUB_REF_NAME"
  312. echo "REL_VERSION_STRICT=${GITHUB_REF_NAME#?}" >> $GITHUB_ENV
  313. - name: Install Packer
  314. run: |
  315. curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
  316. sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
  317. sudo apt-get update && sudo apt-get install packer
  318. - name: Build Droplet Image
  319. env:
  320. DIGITALOCEAN_API_TOKEN: ${{ secrets.DO_TOKEN }}
  321. WIKI_APP_VERSION: ${{ env.REL_VERSION_STRICT }}
  322. working-directory: dev/packer
  323. run: |
  324. packer build digitalocean.json