release.yml 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. name: Build and Release
  2. on:
  3. workflow_dispatch:
  4. release:
  5. types: [ released,prereleased ]
  6. jobs:
  7. build:
  8. permissions:
  9. contents: write
  10. strategy:
  11. matrix:
  12. goos: [ windows, linux, darwin ]
  13. goarch: [ amd64, arm64 ]
  14. runs-on: ubuntu-latest
  15. env:
  16. CGO_ENABLED: 0
  17. GOOS: ${{ matrix.goos }}
  18. GOARCH: ${{ matrix.goarch }}
  19. steps:
  20. - name: Get version
  21. id: get_version
  22. run: |
  23. echo "VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
  24. echo "${GITHUB_REF}"
  25. - name: Checkout
  26. uses: actions/checkout@v4.0.0
  27. - name: Setup Node.js environment
  28. uses: actions/setup-node@v3.8.1
  29. - name: Install Dependencies
  30. run: npm install --global yarn
  31. - name: Setup Go environment
  32. uses: actions/setup-go@v4.1.0
  33. with:
  34. check-latest: true
  35. - name: Gen output name
  36. run: |
  37. echo "FILENAME=pmail_${{ matrix.goos }}_${{ matrix.goarch }}" >> ${GITHUB_ENV}
  38. echo "TGFILENAME=telegram_push_${{ matrix.goos }}_${{ matrix.goarch }}" >> ${GITHUB_ENV}
  39. echo "WCFILENAME=wechat_push_${{ matrix.goos }}_${{ matrix.goarch }}" >> ${GITHUB_ENV}
  40. echo "SPAMBLOCKFILENAME=spam_block_${{ matrix.goos }}_${{ matrix.goarch }}" >> ${GITHUB_ENV}
  41. echo "ZIPNAME=${{ matrix.goos }}_${{ matrix.goarch }}" >> ${GITHUB_ENV}
  42. - name: Rename Windows File
  43. if: matrix.goos == 'windows'
  44. run: |
  45. echo "FILENAME=pmail_${{ matrix.goos }}_${{ matrix.goarch }}.exe" >> ${GITHUB_ENV}
  46. echo "TGFILENAME=telegram_push_${{ matrix.goos }}_${{ matrix.goarch }}.exe" >> ${GITHUB_ENV}
  47. echo "WCFILENAME=wechat_push_${{ matrix.goos }}_${{ matrix.goarch }}.exe" >> ${GITHUB_ENV}
  48. echo "SPAMBLOCKFILENAME=spam_block_${{ matrix.goos }}_${{ matrix.goarch }}.exe" >> ${GITHUB_ENV}
  49. - name: FE Build
  50. run: cd fe && yarn && yarn build
  51. - name: BE Build
  52. run: |
  53. cd server && cp -rf ../fe/dist listen/http_server
  54. go build -ldflags "-s -w -X 'main.version=${{ env.VERSION }}' -X 'main.goVersion=$(go version)' -X 'main.gitHash=$(git show -s --format=%H)' -X 'main.buildTime=$(TZ=UTC-8 date +%Y-%m-%d" "%H:%M:%S)'" -o ${{ env.FILENAME }} main.go
  55. go build -ldflags "-s -w" -o ${{ env.TGFILENAME }} hooks/telegram_push/telegram_push.go
  56. go build -ldflags "-s -w" -o ${{ env.WCFILENAME }} hooks/wechat_push/wechat_push.go
  57. go build -ldflags "-s -w" -o ${{ env.SPAMBLOCKFILENAME }} hooks/spam_block/spam_block.go
  58. ls -alh
  59. - name: Zip
  60. run: |
  61. cd ./server
  62. mkdir plugins
  63. mv ${{ env.TGFILENAME }} plugins/
  64. mv ${{ env.WCFILENAME }} plugins/
  65. mv ${{ env.SPAMBLOCKFILENAME }} plugins/
  66. zip -r ${{ env.ZIPNAME }}.zip ${{ env.FILENAME }} plugins
  67. ls
  68. - name: Upload files to Artifacts
  69. uses: actions/upload-artifact@v4
  70. with:
  71. name: ${{ env.ZIPNAME }}
  72. path: server/${{ env.ZIPNAME }}.zip
  73. - name: Upload binaries to release
  74. uses: svenstaro/upload-release-action@v2
  75. with:
  76. repo_token: ${{ secrets.GITHUB_TOKEN }}
  77. file: server/${{ env.ZIPNAME }}.zip
  78. tag: ${{ github.ref }}
  79. file_glob: true