build.yml 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. name: Build
  2. on:
  3. push:
  4. branches:
  5. - '*'
  6. paths:
  7. - "app/**/*.js"
  8. - "app/**/*.vue"
  9. - "app/src/language/**/*.po"
  10. - "app/i18n.json"
  11. - "app/package.json"
  12. - "app/.env*"
  13. - "**/*.go"
  14. - "go.mod"
  15. - "go.sum"
  16. - ".github/workflows/build*.yml"
  17. - "resources/docker/docker/*"
  18. - "resources/development/*"
  19. - "resources/demo/*"
  20. pull_request:
  21. types: [ opened, synchronize, reopened ]
  22. paths:
  23. - "**/*.js"
  24. - "**/*.vue"
  25. - "app/package.json"
  26. - "app/.env*"
  27. - "**/*.go"
  28. - "go.mod"
  29. - "go.sum"
  30. - ".github/workflows/*.yml"
  31. - "resources/docker/docker/*"
  32. - "resources/development/*"
  33. - "resources/demo/*"
  34. release:
  35. types:
  36. - published
  37. jobs:
  38. build_app:
  39. runs-on: macos-14
  40. steps:
  41. - name: Checkout
  42. uses: actions/checkout@v4
  43. - name: Set up nodejs
  44. uses: actions/setup-node@v4
  45. with:
  46. node-version: current
  47. - name: Install dependencies
  48. run: |
  49. corepack enable
  50. corepack prepare pnpm@latest --activate
  51. pnpm install
  52. working-directory: app
  53. - name: Check frontend code style
  54. run: |
  55. pnpm run lint
  56. working-directory: app
  57. - name: Check frontend types
  58. run: |
  59. pnpm run typecheck
  60. working-directory: app
  61. - name: Build
  62. run: |
  63. npx browserslist@latest --update-db
  64. pnpm build
  65. working-directory: app
  66. - name: Archive app artifacts
  67. uses: actions/upload-artifact@v4
  68. with:
  69. name: app-dist
  70. path: app/dist
  71. - name: Prepare publish
  72. if: github.event_name == 'release'
  73. run: |
  74. cp README*.md app/dist
  75. find app/dist -printf '%P\n' | tar -C app/dist --no-recursion -zcvf app-dist.tar.gz -T -
  76. - name: Publish
  77. uses: softprops/action-gh-release@v1
  78. if: github.event_name == 'release'
  79. with:
  80. files: app-dist.tar.gz
  81. build:
  82. runs-on: ubuntu-latest
  83. needs: build_app
  84. strategy:
  85. matrix:
  86. goos: [ linux, darwin ]
  87. goarch: [ amd64, 386, arm64 ]
  88. exclude:
  89. # Exclude i386 on darwin.
  90. - goarch: 386
  91. goos: darwin
  92. include:
  93. # BEGIN Linux ARM 5 6 7
  94. - goos: linux
  95. goarch: arm
  96. goarm: 7
  97. - goos: linux
  98. goarch: arm
  99. goarm: 6
  100. - goos: linux
  101. goarch: arm
  102. goarm: 5
  103. # END Linux ARM 5 6 7
  104. env:
  105. CGO_ENABLED: 1
  106. GOOS: ${{ matrix.goos }}
  107. GOARCH: ${{ matrix.goarch }}
  108. GOARM: ${{ matrix.goarm }}
  109. steps:
  110. - name: Checkout
  111. uses: actions/checkout@v4
  112. - name: Set up Go
  113. uses: actions/setup-go@v5
  114. with:
  115. go-version: ^1.22.0
  116. - name: Setup compiler environment
  117. id: info
  118. run: |
  119. export _NAME=nginx-ui-$(jq ".$GOOS[\"$GOARCH$GOARM\"].name" -r < .github/build/build_info.json)
  120. export _ARCH=$(jq ".$GOOS[\"$GOARCH$GOARM\"].arch" -r < .github/build/build_info.json)
  121. export _ABI=$(jq ".$GOOS[\"$GOARCH$GOARM\"].abi // \"\"" -r < .github/build/build_info.json)
  122. export _ARTIFACT=nginx-ui-$GOOS-$GOARCH$(if [[ "$GOARM" ]]; then echo "v$GOARM"; fi)
  123. echo "GOOS: $GOOS, GOARCH: $GOARCH, GOARM: $GOARM, ABI: $_ABI, RELEASE_NAME: $_NAME, ARTIFACT_NAME: $_ARTIFACT"
  124. echo "ARCH_NAME=$_ARCH" >> $GITHUB_ENV
  125. echo "ABI=$_ABI" >> $GITHUB_ENV
  126. echo "DIST=$_NAME" >> $GITHUB_ENV
  127. echo "ARTIFACT=$_ARTIFACT" >> $GITHUB_ENV
  128. - name: Install musl cross compiler
  129. if: env.GOOS == 'linux'
  130. uses: 0xJacky/musl-cross-compilers@v0.6.6
  131. id: musl
  132. with:
  133. target: ${{ env.ARCH_NAME }}-linux-musl${{ env.ABI }}
  134. - name: Post install musl cross compiler
  135. if: env.GOOS == 'linux'
  136. run: |
  137. echo "PATH=${{ steps.musl.outputs.path }}:$PATH" >> $GITHUB_ENV
  138. echo "CC=${{ env.ARCH_NAME }}-linux-musl${{ env.ABI }}-gcc" >> $GITHUB_ENV
  139. echo "CXX=${{ env.ARCH_NAME }}-linux-musl${{ env.ABI }}-g++" >> $GITHUB_ENV
  140. echo "LD_FLAGS=-w --extldflags '-static'" >> $GITHUB_ENV
  141. - name: Install darwin cross compiler
  142. if: env.GOOS == 'darwin'
  143. run: |
  144. curl -L https://github.com/Hintay/crossosx/releases/latest/download/crossosx.tar.zst -o crossosx.tar.zst
  145. tar xvaf crossosx.tar.zst
  146. echo "LD_LIBRARY_PATH=$(pwd)/crossosx/lib/" >> $GITHUB_ENV
  147. echo "PATH=$(pwd)/crossosx/bin/:$PATH" >> $GITHUB_ENV
  148. echo "CC=${{ env.ARCH_NAME }}-clang" >> $GITHUB_ENV
  149. echo "CXX=${{ env.ARCH_NAME }}-clang++" >> $GITHUB_ENV
  150. echo "LD_FLAGS=-w" >> $GITHUB_ENV
  151. - name: Download app artifacts
  152. uses: actions/download-artifact@v4
  153. with:
  154. name: app-dist
  155. path: app/dist
  156. - name: Build
  157. run: |
  158. mkdir -p dist
  159. go build -tags=jsoniter -ldflags "$LD_FLAGS -X 'github.com/0xJacky/Nginx-UI/server/settings.buildTime=$(date +%s)'" -o dist/nginx-ui -v main.go
  160. - name: Archive backend artifacts
  161. uses: actions/upload-artifact@v4
  162. with:
  163. name: ${{ env.ARTIFACT }}
  164. path: dist/nginx-ui
  165. - name: Prepare publish
  166. if: github.event_name == 'release'
  167. run: |
  168. cp README*.md ./dist
  169. find dist -printf '%P\n' | tar -C dist --no-recursion -zcvf ${{ env.DIST }}.tar.gz -T -
  170. openssl dgst -sha512 ${{ env.DIST }}.tar.gz | sed 's/([^)]*)//g' | awk '{print $NF}' >> ${{ env.DIST }}.tar.gz.digest
  171. - name: Publish
  172. uses: softprops/action-gh-release@v1
  173. if: github.event_name == 'release'
  174. with:
  175. files: |
  176. ${{ env.DIST }}.tar.gz
  177. ${{ env.DIST }}.tar.gz.digest
  178. docker-build:
  179. if: github.event_name != 'pull_request'
  180. runs-on: ubuntu-latest
  181. needs: build
  182. env:
  183. PLATFORMS: linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6,linux/arm/v5
  184. steps:
  185. - name: Checkout
  186. uses: actions/checkout@v4
  187. - name: Get the version
  188. id: get_version
  189. run: echo "VERSION=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_OUTPUT
  190. - name: Download artifacts
  191. uses: actions/download-artifact@v4
  192. with:
  193. path: ./dist
  194. - name: Prepare Artifacts
  195. run: chmod +x ./dist/nginx-ui-*/nginx-ui
  196. - name: Set up Docker Buildx
  197. id: buildx
  198. uses: docker/setup-buildx-action@v3
  199. - name: Login to DockerHub
  200. uses: docker/login-action@v3
  201. with:
  202. username: ${{ secrets.DOCKERHUB_USER }}
  203. password: ${{ secrets.DOCKERHUB_TOKEN }}
  204. - name: Prepare Dockerfile
  205. if: github.event_name == 'release'
  206. run: |
  207. cp ./Dockerfile ./dist
  208. cp -rp ./resources ./dist
  209. - name: Build and push
  210. if: github.event_name == 'release'
  211. uses: docker/build-push-action@v5
  212. with:
  213. context: ./dist
  214. file: ./dist/Dockerfile
  215. platforms: ${{ env.PLATFORMS }}
  216. push: ${{ github.event_name != 'pull_request' }}
  217. tags: |
  218. uozi/nginx-ui:latest
  219. uozi/nginx-ui:${{ steps.get_version.outputs.VERSION }}
  220. - name: Prepare Demo Dockerfile
  221. run: |
  222. cp ./demo.Dockerfile ./dist
  223. cp -rp ./resources ./dist
  224. - name: Build and push demo
  225. uses: docker/build-push-action@v5
  226. with:
  227. context: ./dist
  228. file: ./dist/demo.Dockerfile
  229. platforms: ${{ env.PLATFORMS }}
  230. push: ${{ github.event_name != 'pull_request' }}
  231. tags: |
  232. uozi/nginx-ui-demo:latest