release.yml 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. name: release-binaries
  2. on:
  3. push:
  4. tags:
  5. - "v*"
  6. workflow_dispatch:
  7. permissions:
  8. contents: write
  9. jobs:
  10. web:
  11. runs-on: ubuntu-latest
  12. steps:
  13. - name: Checkout
  14. uses: actions/checkout@v4
  15. - name: Set up Node.js
  16. uses: actions/setup-node@v4
  17. with:
  18. node-version: "20"
  19. cache: npm
  20. cache-dependency-path: web/package-lock.json
  21. - name: Build embedded web UI
  22. working-directory: web
  23. run: |
  24. npm ci --no-audit --no-fund
  25. npm run build
  26. - name: Upload embedded web UI
  27. uses: actions/upload-artifact@v4
  28. with:
  29. name: web-dist
  30. path: web/dist
  31. if-no-files-found: error
  32. retention-days: 1
  33. test:
  34. needs: web
  35. runs-on: ubuntu-latest
  36. steps:
  37. - name: Checkout
  38. uses: actions/checkout@v4
  39. - name: Set up Go
  40. uses: actions/setup-go@v5
  41. with:
  42. go-version-file: go.mod
  43. cache: true
  44. - name: Download embedded web UI
  45. uses: actions/download-artifact@v4
  46. with:
  47. name: web-dist
  48. path: web/dist
  49. - name: Test
  50. run: go test ./...
  51. binaries:
  52. needs: [web, test]
  53. runs-on: ubuntu-latest
  54. strategy:
  55. fail-fast: false
  56. matrix:
  57. include:
  58. - target: linux-amd64
  59. goarch: amd64
  60. goarm: ""
  61. filename: vocat-linux-amd64
  62. - target: linux-386
  63. goarch: "386"
  64. goarm: ""
  65. filename: vocat-linux-386
  66. - target: linux-arm64
  67. goarch: arm64
  68. goarm: ""
  69. filename: vocat-linux-arm64
  70. - target: linux-armv7
  71. goarch: arm
  72. goarm: "7"
  73. filename: vocat-linux-armv7
  74. steps:
  75. - name: Checkout
  76. uses: actions/checkout@v4
  77. - name: Set up Go
  78. uses: actions/setup-go@v5
  79. with:
  80. go-version-file: go.mod
  81. cache: true
  82. - name: Download embedded web UI
  83. uses: actions/download-artifact@v4
  84. with:
  85. name: web-dist
  86. path: web/dist
  87. - name: Build ${{ matrix.target }}
  88. env:
  89. GOOS: linux
  90. GOARCH: ${{ matrix.goarch }}
  91. GOARM: ${{ matrix.goarm }}
  92. CGO_ENABLED: "0"
  93. OUTPUT: dist/${{ matrix.filename }}
  94. VERSION: ${{ github.ref_name }}
  95. run: |
  96. mkdir -p dist
  97. VERSION="${VERSION#v}"
  98. BUILD_TIME="$(git show -s --format=%cI HEAD)"
  99. go build -trimpath \
  100. -ldflags "-s -w -X vocat/internal/buildinfo.Version=${VERSION} -X vocat/internal/buildinfo.BuildTime=${BUILD_TIME}" \
  101. -o "$OUTPUT" \
  102. ./cmd/vocat
  103. chmod 0755 "$OUTPUT"
  104. - name: Upload ${{ matrix.target }}
  105. uses: actions/upload-artifact@v4
  106. with:
  107. name: binary-${{ matrix.target }}
  108. path: dist/${{ matrix.filename }}
  109. if-no-files-found: error
  110. retention-days: 1
  111. github-release:
  112. if: github.ref_type == 'tag'
  113. needs: binaries
  114. runs-on: ubuntu-latest
  115. env:
  116. GH_TOKEN: ${{ github.token }}
  117. steps:
  118. - name: Download binaries
  119. uses: actions/download-artifact@v4
  120. with:
  121. pattern: binary-*
  122. path: dist
  123. merge-multiple: true
  124. - name: Generate checksums
  125. working-directory: dist
  126. run: sha256sum vocat-linux-* | sort > SHA256SUMS
  127. - name: Create or update GitHub Release
  128. run: |
  129. if gh release view "$GITHUB_REF_NAME" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then
  130. gh release upload "$GITHUB_REF_NAME" dist/* --repo "$GITHUB_REPOSITORY" --clobber
  131. else
  132. gh release create "$GITHUB_REF_NAME" dist/* \
  133. --repo "$GITHUB_REPOSITORY" \
  134. --title "$GITHUB_REF_NAME" \
  135. --generate-notes \
  136. --verify-tag
  137. fi