release.yml 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. go-version: '1.22'
  35. check-latest: true
  36. - name: Gen output name
  37. run: |
  38. echo "FILENAME=pmail_${{ matrix.goos }}_${{ matrix.goarch }}" >> ${GITHUB_ENV}
  39. echo "TGFILENAME=telegram_push_${{ matrix.goos }}_${{ matrix.goarch }}" >> ${GITHUB_ENV}
  40. echo "WCFILENAME=wechat_push_${{ matrix.goos }}_${{ matrix.goarch }}" >> ${GITHUB_ENV}
  41. echo "SPAMBLOCKFILENAME=spam_block_${{ matrix.goos }}_${{ matrix.goarch }}" >> ${GITHUB_ENV}
  42. echo "ZIPNAME=${{ matrix.goos }}_${{ matrix.goarch }}" >> ${GITHUB_ENV}
  43. - name: Rename Windows File
  44. if: matrix.goos == 'windows'
  45. run: |
  46. echo "FILENAME=pmail_${{ matrix.goos }}_${{ matrix.goarch }}.exe" >> ${GITHUB_ENV}
  47. echo "TGFILENAME=telegram_push_${{ matrix.goos }}_${{ matrix.goarch }}.exe" >> ${GITHUB_ENV}
  48. echo "WCFILENAME=wechat_push_${{ matrix.goos }}_${{ matrix.goarch }}.exe" >> ${GITHUB_ENV}
  49. echo "SPAMBLOCKFILENAME=spam_block_${{ matrix.goos }}_${{ matrix.goarch }}.exe" >> ${GITHUB_ENV}
  50. - name: FE Build
  51. run: cd fe && yarn && yarn build
  52. - name: BE Build
  53. run: |
  54. cd server && cp -rf ../fe/dist listen/http_server
  55. 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
  56. go build -ldflags "-s -w" -o ${{ env.TGFILENAME }} hooks/telegram_push/telegram_push.go
  57. go build -ldflags "-s -w" -o ${{ env.WCFILENAME }} hooks/wechat_push/wechat_push.go
  58. go build -ldflags "-s -w" -o ${{ env.SPAMBLOCKFILENAME }} hooks/spam_block/spam_block.go
  59. ls -alh
  60. - name: Zip
  61. run: |
  62. cd ./server
  63. mkdir plugins
  64. mv ${{ env.TGFILENAME }} plugins/
  65. mv ${{ env.WCFILENAME }} plugins/
  66. mv ${{ env.SPAMBLOCKFILENAME }} plugins/
  67. zip -r ${{ env.ZIPNAME }}.zip ${{ env.FILENAME }} plugins
  68. ls
  69. - name: Upload files to Artifacts
  70. uses: actions/upload-artifact@v4
  71. with:
  72. name: ${{ env.ZIPNAME }}
  73. path: server/${{ env.ZIPNAME }}.zip
  74. - name: Upload binaries to release
  75. uses: svenstaro/upload-release-action@v2
  76. with:
  77. repo_token: ${{ secrets.GITHUB_TOKEN }}
  78. file: server/${{ env.ZIPNAME }}.zip
  79. tag: ${{ github.ref }}
  80. file_glob: true