build.yml 9.8 KB

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