1
0

release.yml 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. name: Release
  2. on:
  3. release:
  4. types: [published]
  5. pull_request:
  6. paths:
  7. - '.github/workflows/release.yml'
  8. env:
  9. GOPROXY: "https://proxy.golang.org"
  10. permissions:
  11. contents: write
  12. jobs:
  13. build:
  14. name: Build ${{ matrix.goos }}/${{ matrix.goarch }}${{ matrix.suffix }}
  15. runs-on: ubuntu-latest
  16. strategy:
  17. fail-fast: false
  18. matrix:
  19. include:
  20. - {goos: linux, goarch: amd64}
  21. - {goos: linux, goarch: arm64}
  22. - {goos: linux, goarch: "386"}
  23. - {goos: darwin, goarch: amd64}
  24. - {goos: darwin, goarch: arm64}
  25. - {goos: windows, goarch: amd64}
  26. - {goos: windows, goarch: arm64}
  27. - {goos: windows, goarch: "386"}
  28. - {goos: windows, goarch: amd64, suffix: "_mws", tags: minwinsvc}
  29. - {goos: windows, goarch: arm64, suffix: "_mws", tags: minwinsvc}
  30. - {goos: windows, goarch: "386", suffix: "_mws", tags: minwinsvc}
  31. steps:
  32. - name: Checkout code
  33. uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
  34. - name: Setup Go
  35. uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
  36. with:
  37. go-version: 1.25.x
  38. - name: Determine version
  39. id: version
  40. run: |
  41. if [ "${{ github.event_name }}" = "release" ]; then
  42. echo "version=${{ github.event.release.tag_name }}" >> "$GITHUB_OUTPUT"
  43. echo "release_tag=${{ github.event.release.tag_name }}" >> "$GITHUB_OUTPUT"
  44. else
  45. echo "version=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT"
  46. echo "release_tag=release-archive-testing" >> "$GITHUB_OUTPUT"
  47. fi
  48. - name: Build binary
  49. env:
  50. GOOS: ${{ matrix.goos }}
  51. GOARCH: ${{ matrix.goarch }}
  52. CGO_ENABLED: "0"
  53. run: |
  54. BINARY_NAME="gogs"
  55. if [ "${{ matrix.goos }}" = "windows" ]; then
  56. BINARY_NAME="gogs.exe"
  57. fi
  58. TAGS_FLAG=""
  59. if [ -n "${{ matrix.tags }}" ]; then
  60. TAGS_FLAG="-tags ${{ matrix.tags }}"
  61. fi
  62. go build -v \
  63. -ldflags "
  64. -X \"gogs.io/gogs/internal/conf.BuildTime=$(date -u '+%Y-%m-%d %I:%M:%S %Z')\"
  65. -X \"gogs.io/gogs/internal/conf.BuildCommit=$(git rev-parse HEAD)\"
  66. " \
  67. $TAGS_FLAG \
  68. -trimpath -o "$BINARY_NAME"
  69. - name: Prepare archive contents
  70. run: |
  71. mkdir -p dist/gogs
  72. BINARY_NAME="gogs"
  73. if [ "${{ matrix.goos }}" = "windows" ]; then
  74. BINARY_NAME="gogs.exe"
  75. fi
  76. cp "$BINARY_NAME" dist/gogs/
  77. cp LICENSE README.md README_ZH.md dist/gogs/
  78. cp -r scripts dist/gogs/
  79. - name: Create archives
  80. working-directory: dist
  81. run: |
  82. VERSION="${{ steps.version.outputs.version }}"
  83. ARCHIVE_BASE="gogs_${VERSION}_${{ matrix.goos }}_${{ matrix.goarch }}${{ matrix.suffix }}"
  84. zip -r "${ARCHIVE_BASE}.zip" gogs
  85. if [ "${{ matrix.goos }}" = "linux" ]; then
  86. tar -czvf "${ARCHIVE_BASE}.tar.gz" gogs
  87. fi
  88. - name: Upload to release
  89. env:
  90. GH_TOKEN: ${{ github.token }}
  91. run: |
  92. RELEASE_TAG="${{ steps.version.outputs.release_tag }}"
  93. if [ "${{ github.event_name }}" != "release" ]; then
  94. git tag -f "$RELEASE_TAG"
  95. git push origin "$RELEASE_TAG" --force || true
  96. gh release view "$RELEASE_TAG" || gh release create "$RELEASE_TAG" --title "Release Archive Testing" --notes "Automated testing release for workflow development." --prerelease
  97. fi
  98. PATTERN="_${{ matrix.goos }}_${{ matrix.goarch }}${{ matrix.suffix }}\."
  99. gh release view "$RELEASE_TAG" --json assets --jq ".assets[].name" | grep "$PATTERN" | while read -r asset; do
  100. gh release delete-asset "$RELEASE_TAG" "$asset" --yes || true
  101. done
  102. gh release upload "$RELEASE_TAG" dist/gogs_*.zip --clobber
  103. if [ "${{ matrix.goos }}" = "linux" ]; then
  104. gh release upload "$RELEASE_TAG" dist/gogs_*.tar.gz --clobber
  105. fi