build.yml 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. name: Build
  2. on:
  3. push:
  4. branches: [ master ]
  5. paths:
  6. - "**/*.js"
  7. - "**/*.vue"
  8. - "frontend/package.json"
  9. - "frontend/.env*"
  10. - "**/*.go"
  11. - "go.mod"
  12. - "go.sum"
  13. - ".github/workflows/*.yml"
  14. pull_request:
  15. types: [ opened, synchronize, reopened ]
  16. paths:
  17. - "**/*.js"
  18. - "**/*.vue"
  19. - "frontend/package.json"
  20. - "frontend/.env*"
  21. - "**/*.go"
  22. - "go.mod"
  23. - "go.sum"
  24. - ".github/workflows/*.yml"
  25. release:
  26. types:
  27. - published
  28. jobs:
  29. build_frontend:
  30. runs-on: ubuntu-latest
  31. steps:
  32. - name: Checkout
  33. uses: actions/checkout@v2
  34. - name: Set up nodejs
  35. uses: actions/setup-node@v2
  36. with:
  37. node-version: '16.x'
  38. cache: 'yarn'
  39. cache-dependency-path: 'frontend/yarn.lock'
  40. - name: Install dependencies
  41. run: yarn install
  42. working-directory: frontend
  43. - name: Update tranlations
  44. run: make translations
  45. working-directory: frontend
  46. - name: Build
  47. run: |
  48. npx browserslist@latest --update-db
  49. yarn build
  50. working-directory: frontend
  51. - name: Archive frontend artifacts
  52. uses: actions/upload-artifact@v2
  53. with:
  54. name: frontend-dist
  55. path: frontend/dist
  56. - name: Prepare publish
  57. if: github.event_name == 'release'
  58. run: |
  59. cp README*.md frontend/dist
  60. find frontend/dist -printf '%P\n' | tar -C frontend/dist --no-recursion -zcvf frontend-dist.tar.gz -T -
  61. - name: Publish
  62. uses: softprops/action-gh-release@v1
  63. if: github.event_name == 'release'
  64. with:
  65. files: frontend-dist.tar.gz
  66. build:
  67. runs-on: ubuntu-latest
  68. needs: build_frontend
  69. strategy:
  70. matrix:
  71. goos: [linux, darwin]
  72. goarch: [amd64, 386, arm64]
  73. exclude:
  74. # Exclude i386 on darwin.
  75. - goarch: 386
  76. goos: darwin
  77. include:
  78. # BEGIN Linux ARM 5 6 7
  79. - goos: linux
  80. goarch: arm
  81. goarm: 7
  82. - goos: linux
  83. goarch: arm
  84. goarm: 6
  85. - goos: linux
  86. goarch: arm
  87. goarm: 5
  88. # END Linux ARM 5 6 7
  89. env:
  90. CGO_ENABLED: 1
  91. GOOS: ${{ matrix.goos }}
  92. GOARCH: ${{ matrix.goarch }}
  93. GOARM: ${{ matrix.goarm }}
  94. steps:
  95. - name: Checkout
  96. uses: actions/checkout@v2
  97. - name: Set up Go
  98. uses: actions/setup-go@v2
  99. with:
  100. go-version: ^1.17.7
  101. - name: Set up cache
  102. uses: actions/cache@v2
  103. with:
  104. path: |
  105. ~/.cache/go-build
  106. ~/go/pkg/mod
  107. key: ${{ runner.os }}-${{ env.GOOS }}-${{ env.GOARCH }}${{ env.GOARM }}-go-${{ hashFiles('**/go.sum') }}
  108. restore-keys: |
  109. ${{ runner.os }}-${{ env.GOOS }}-${{ env.GOARCH }}${{ env.GOARM }}-go-
  110. - name: Setup compiler environment
  111. id: info
  112. run: |
  113. export _NAME=nginx-ui-$(jq ".$GOOS[\"$GOARCH$GOARM\"].name" -r < .github/build/build_info.json)
  114. export _ARCH=$(jq ".$GOOS[\"$GOARCH$GOARM\"].arch" -r < .github/build/build_info.json)
  115. export _ABI=$(jq ".$GOOS[\"$GOARCH$GOARM\"].abi // \"\"" -r < .github/build/build_info.json)
  116. echo "GOOS: $GOOS, GOARCH: $GOARCH, GOARM: $GOARM, ABI: $_ABI, RELEASE_NAME: $_NAME"
  117. echo "ARCH_NAME=$_ARCH" >> $GITHUB_ENV
  118. echo "ABI=$_ABI" >> $GITHUB_ENV
  119. echo "DIST=$_NAME" >> $GITHUB_ENV
  120. - name: Install musl cross compiler
  121. if: env.GOOS == 'linux'
  122. uses: Lesmiscore/musl-cross-compilers@v0.5
  123. id: musl
  124. with:
  125. target: ${{ env.ARCH_NAME }}-linux-musl${{ env.ABI }}
  126. - name: Post install musl cross compiler
  127. if: env.GOOS == 'linux'
  128. run: |
  129. echo "PATH=${{ steps.musl.outputs.path }}:$PATH" >> $GITHUB_ENV
  130. echo "CC=${{ env.ARCH_NAME }}-linux-musl${{ env.ABI }}-gcc" >> $GITHUB_ENV
  131. echo "CXX=${{ env.ARCH_NAME }}-linux-musl${{ env.ABI }}-g++" >> $GITHUB_ENV
  132. echo "LD_FLAGS=--extldflags '-static'" >> $GITHUB_ENV
  133. - name: Install darwin cross compiler
  134. if: env.GOOS == 'darwin'
  135. run: |
  136. curl -L https://github.com/Hintay/crossosx/releases/latest/download/crossosx.tar.zst -o crossosx.tar.zst
  137. tar xvaf crossosx.tar.zst
  138. echo "LD_LIBRARY_PATH=$(pwd)/crossosx/lib/" >> $GITHUB_ENV
  139. echo "PATH=$(pwd)/crossosx/bin/:$PATH" >> $GITHUB_ENV
  140. echo "CC=${{ env.ARCH_NAME }}-clang" >> $GITHUB_ENV
  141. echo "CXX=${{ env.ARCH_NAME }}-clang++" >> $GITHUB_ENV
  142. echo "LD_FLAGS=-s -w" >> $GITHUB_ENV
  143. - name: Download frontend artifacts
  144. uses: actions/download-artifact@v2
  145. with:
  146. name: frontend-dist
  147. path: frontend/dist
  148. - name: Build
  149. run: |
  150. mkdir -p dist
  151. go build -ldflags "$LD_FLAGS -X 'github.com/0xJacky/Nginx-UI/server/settings.buildTime=$(date +%s)'" -o dist/nginx-ui -v main.go
  152. - name: Archive backend artifacts
  153. uses: actions/upload-artifact@v2
  154. with:
  155. name: ${{ env.DIST }}
  156. path: dist/nginx-ui
  157. - name: Prepare publish
  158. if: github.event_name == 'release'
  159. run: |
  160. cp README*.md ./dist
  161. find dist -printf '%P\n' | tar -C dist --no-recursion -zcvf ${{ env.DIST }}.tar.gz -T -
  162. - name: Publish
  163. uses: softprops/action-gh-release@v1
  164. if: github.event_name == 'release'
  165. with:
  166. files: ${{ env.DIST }}.tar.gz