build.yml 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. env:
  78. CGO_ENABLED: 1
  79. GOOS: ${{ matrix.goos }}
  80. GOARCH: ${{ matrix.goarch }}
  81. DIST: nginx-ui-${{ matrix.GOOS }}-${{ matrix.GOARCH }}
  82. outputs:
  83. dist: ${{ env.DIST }}
  84. steps:
  85. - name: Checkout
  86. uses: actions/checkout@v2
  87. - name: Set up Go
  88. uses: actions/setup-go@v2
  89. with:
  90. go-version: ^1.17.7
  91. - name: Set up cache
  92. uses: actions/cache@v2
  93. with:
  94. path: |
  95. ~/.cache/go-build
  96. ~/go/pkg/mod
  97. key: ${{ runner.os }}-${{ env.GOOS }}-${{ env.GOARCH }}-go-${{ hashFiles('**/go.sum') }}
  98. restore-keys: |
  99. ${{ runner.os }}-${{ env.GOOS }}-${{ env.GOARCH }}-go-
  100. - name: Setup compiler environment
  101. id: info
  102. run: |
  103. export _ARCH=$(jq ".[\"$GOARCH\"].$GOOS" -r < .github/build/compiler_arch.json)
  104. echo "::set-output name=ARCH_NAME::$_ARCH"
  105. - name: Install musl cross compiler
  106. if: env.GOOS == 'linux'
  107. uses: Lesmiscore/musl-cross-compilers@v0.5
  108. id: musl
  109. with:
  110. target: ${{ steps.info.outputs.ARCH_NAME }}-linux-musl
  111. - name: Post install musl cross compiler
  112. if: env.GOOS == 'linux'
  113. run: |
  114. echo "PATH=${{ steps.musl.outputs.path }}:$PATH" >> $GITHUB_ENV
  115. echo "CC=${{ steps.info.outputs.ARCH_NAME }}-linux-musl-gcc" >> $GITHUB_ENV
  116. echo "CXX=${{ steps.info.outputs.ARCH_NAME }}-linux-musl-g++" >> $GITHUB_ENV
  117. echo "LD_FLAGS=--extldflags '-static'" >> $GITHUB_ENV
  118. - name: Install darwin cross compiler
  119. if: env.GOOS == 'darwin'
  120. run: |
  121. curl -L https://github.com/Hintay/crossosx/releases/latest/download/crossosx.tar.zst -o crossosx.tar.zst
  122. tar xvaf crossosx.tar.zst
  123. echo "LD_LIBRARY_PATH=$(pwd)/crossosx/lib/" >> $GITHUB_ENV
  124. echo "PATH=$(pwd)/crossosx/bin/:$PATH" >> $GITHUB_ENV
  125. echo "CC=${{ steps.info.outputs.ARCH_NAME }}-clang" >> $GITHUB_ENV
  126. echo "CXX=${{ steps.info.outputs.ARCH_NAME }}-clang++" >> $GITHUB_ENV
  127. echo "LD_FLAGS=-s -w" >> $GITHUB_ENV
  128. - name: Download frontend artifacts
  129. uses: actions/download-artifact@v2
  130. with:
  131. name: frontend-dist
  132. path: frontend/dist
  133. - name: Build
  134. run: |
  135. mkdir -p dist
  136. go build -ldflags "$LD_FLAGS -X 'github.com/0xJacky/Nginx-UI/server/settings.buildTime=$(date +%s)'" -o dist/nginx-ui -v main.go
  137. - name: Archive backend artifacts
  138. uses: actions/upload-artifact@v2
  139. with:
  140. name: ${{ env.DIST }}
  141. path: dist/nginx-ui
  142. - name: Prepare publish
  143. if: github.event_name == 'release'
  144. run: |
  145. cp README*.md ./dist
  146. find dist -printf '%P\n' | tar -C dist --no-recursion -zcvf ${{ env.DIST }}.tar.gz -T -
  147. - name: Publish
  148. uses: softprops/action-gh-release@v1
  149. if: github.event_name == 'release'
  150. with:
  151. files: ${{ env.DIST }}.tar.gz