development.yml 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. name: CI
  2. on:
  3. push:
  4. branches: [main]
  5. pull_request:
  6. jobs:
  7. test-deploy:
  8. name: Test and deploy
  9. runs-on: ${{ matrix.os }}
  10. strategy:
  11. matrix:
  12. go: ['1.20']
  13. os: [ubuntu-latest, macos-latest]
  14. upload-coverage: [true]
  15. include:
  16. - go: '1.20'
  17. os: windows-latest
  18. upload-coverage: false
  19. steps:
  20. - uses: actions/checkout@v3
  21. with:
  22. fetch-depth: 0
  23. - name: Set up Go
  24. uses: actions/setup-go@v4
  25. with:
  26. go-version: ${{ matrix.go }}
  27. - name: Build for Linux/macOS x86_64
  28. if: startsWith(matrix.os, 'windows-') != true
  29. run: |
  30. go build -trimpath -tags nopgxregisterdefaulttypes -ldflags "-s -w -X github.com/drakkan/sftpgo/v2/internal/version.commit=`git describe --always --abbrev=8 --dirty` -X github.com/drakkan/sftpgo/v2/internal/version.date=`date -u +%FT%TZ`" -o sftpgo
  31. cd tests/eventsearcher
  32. go build -trimpath -ldflags "-s -w" -o eventsearcher
  33. cd -
  34. cd tests/ipfilter
  35. go build -trimpath -ldflags "-s -w" -o ipfilter
  36. cd -
  37. ./sftpgo initprovider
  38. ./sftpgo resetprovider --force
  39. - name: Build for macOS arm64
  40. if: startsWith(matrix.os, 'macos-') == true
  41. run: CGO_ENABLED=1 GOOS=darwin GOARCH=arm64 SDKROOT=$(xcrun --sdk macosx --show-sdk-path) go build -trimpath -tags nopgxregisterdefaulttypes -ldflags "-s -w -X github.com/drakkan/sftpgo/v2/internal/version.commit=`git describe --always --abbrev=8 --dirty` -X github.com/drakkan/sftpgo/v2/internal/version.date=`date -u +%FT%TZ`" -o sftpgo_arm64
  42. - name: Build for Windows
  43. if: startsWith(matrix.os, 'windows-')
  44. run: |
  45. $GIT_COMMIT = (git describe --always --abbrev=8 --dirty) | Out-String
  46. $DATE_TIME = ([datetime]::Now.ToUniversalTime().toString("yyyy-MM-ddTHH:mm:ssZ")) | Out-String
  47. $LATEST_TAG = ((git describe --tags $(git rev-list --tags --max-count=1)) | Out-String).Trim()
  48. $REV_LIST=$LATEST_TAG+"..HEAD"
  49. $COMMITS_FROM_TAG= ((git rev-list $REV_LIST --count) | Out-String).Trim()
  50. $FILE_VERSION = $LATEST_TAG.substring(1) + "." + $COMMITS_FROM_TAG
  51. go install github.com/tc-hib/go-winres@latest
  52. go-winres simply --arch amd64 --product-version $LATEST_TAG-dev-$GIT_COMMIT --file-version $FILE_VERSION --file-description "SFTPGo server" --product-name SFTPGo --copyright "AGPL-3.0" --original-filename sftpgo.exe --icon .\windows-installer\icon.ico
  53. go build -trimpath -tags nopgxregisterdefaulttypes -ldflags "-s -w -X github.com/drakkan/sftpgo/v2/internal/version.commit=$GIT_COMMIT -X github.com/drakkan/sftpgo/v2/internal/version.date=$DATE_TIME" -o sftpgo.exe
  54. cd tests/eventsearcher
  55. go build -trimpath -ldflags "-s -w" -o eventsearcher.exe
  56. cd ../..
  57. cd tests/ipfilter
  58. go build -trimpath -ldflags "-s -w" -o ipfilter.exe
  59. cd ../..
  60. mkdir arm64
  61. $Env:CGO_ENABLED='0'
  62. $Env:GOOS='windows'
  63. $Env:GOARCH='arm64'
  64. go-winres simply --arch arm64 --product-version $LATEST_TAG-dev-$GIT_COMMIT --file-version $FILE_VERSION --file-description "SFTPGo server" --product-name SFTPGo --copyright "AGPL-3.0" --original-filename sftpgo.exe --icon .\windows-installer\icon.ico
  65. go build -trimpath -tags nopgxregisterdefaulttypes,nosqlite -ldflags "-s -w -X github.com/drakkan/sftpgo/v2/internal/version.commit=$GIT_COMMIT -X github.com/drakkan/sftpgo/v2/internal/version.date=$DATE_TIME" -o .\arm64\sftpgo.exe
  66. mkdir x86
  67. $Env:GOARCH='386'
  68. go-winres simply --arch 386 --product-version $LATEST_TAG-dev-$GIT_COMMIT --file-version $FILE_VERSION --file-description "SFTPGo server" --product-name SFTPGo --copyright "AGPL-3.0" --original-filename sftpgo.exe --icon .\windows-installer\icon.ico
  69. go build -trimpath -tags nopgxregisterdefaulttypes,nosqlite -ldflags "-s -w -X github.com/drakkan/sftpgo/v2/internal/version.commit=$GIT_COMMIT -X github.com/drakkan/sftpgo/v2/internal/version.date=$DATE_TIME" -o .\x86\sftpgo.exe
  70. Remove-Item Env:\CGO_ENABLED
  71. Remove-Item Env:\GOOS
  72. Remove-Item Env:\GOARCH
  73. - name: Run test cases using SQLite provider
  74. run: go test -v -tags nopgxregisterdefaulttypes -p 1 -timeout 15m ./... -coverprofile=coverage.txt -covermode=atomic
  75. - name: Upload coverage to Codecov
  76. if: ${{ matrix.upload-coverage }}
  77. uses: codecov/codecov-action@v3
  78. with:
  79. file: ./coverage.txt
  80. fail_ci_if_error: false
  81. - name: Run test cases using bolt provider
  82. run: |
  83. go test -v -tags nopgxregisterdefaulttypes -p 1 -timeout 2m ./internal/config -covermode=atomic
  84. go test -v -tags nopgxregisterdefaulttypes -p 1 -timeout 5m ./internal/common -covermode=atomic
  85. go test -v -tags nopgxregisterdefaulttypes -p 1 -timeout 5m ./internal/httpd -covermode=atomic
  86. go test -v -tags nopgxregisterdefaulttypes -p 1 -timeout 8m ./internal/sftpd -covermode=atomic
  87. go test -v -tags nopgxregisterdefaulttypes -p 1 -timeout 5m ./internal/ftpd -covermode=atomic
  88. go test -v -tags nopgxregisterdefaulttypes -p 1 -timeout 5m ./internal/webdavd -covermode=atomic
  89. go test -v -tags nopgxregisterdefaulttypes -p 1 -timeout 2m ./internal/telemetry -covermode=atomic
  90. go test -v -tags nopgxregisterdefaulttypes -p 1 -timeout 2m ./internal/mfa -covermode=atomic
  91. go test -v -tags nopgxregisterdefaulttypes -p 1 -timeout 2m ./internal/command -covermode=atomic
  92. env:
  93. SFTPGO_DATA_PROVIDER__DRIVER: bolt
  94. SFTPGO_DATA_PROVIDER__NAME: 'sftpgo_bolt.db'
  95. - name: Run test cases using memory provider
  96. run: go test -v -tags nopgxregisterdefaulttypes -p 1 -timeout 15m ./... -covermode=atomic
  97. env:
  98. SFTPGO_DATA_PROVIDER__DRIVER: memory
  99. SFTPGO_DATA_PROVIDER__NAME: ''
  100. - name: Prepare build artifact for macOS
  101. if: startsWith(matrix.os, 'macos-') == true
  102. run: |
  103. mkdir -p output/{init,bash_completion,zsh_completion}
  104. cp sftpgo output/sftpgo_x86_64
  105. cp sftpgo_arm64 output/
  106. cp sftpgo.json output/
  107. cp -r templates output/
  108. cp -r static output/
  109. cp -r openapi output/
  110. cp init/com.github.drakkan.sftpgo.plist output/init/
  111. ./sftpgo gen completion bash > output/bash_completion/sftpgo
  112. ./sftpgo gen completion zsh > output/zsh_completion/_sftpgo
  113. ./sftpgo gen man -d output/man/man1
  114. gzip output/man/man1/*
  115. - name: Prepare Windows installer
  116. if: ${{ startsWith(matrix.os, 'windows-') && github.event_name != 'pull_request' }}
  117. run: |
  118. Remove-Item -LiteralPath "output" -Force -Recurse -ErrorAction Ignore
  119. mkdir output
  120. copy .\sftpgo.exe .\output
  121. copy .\sftpgo.json .\output
  122. copy .\sftpgo.db .\output
  123. copy .\LICENSE .\output\LICENSE.txt
  124. mkdir output\templates
  125. xcopy .\templates .\output\templates\ /E
  126. mkdir output\static
  127. xcopy .\static .\output\static\ /E
  128. mkdir output\openapi
  129. xcopy .\openapi .\output\openapi\ /E
  130. $LATEST_TAG = ((git describe --tags $(git rev-list --tags --max-count=1)) | Out-String).Trim()
  131. $REV_LIST=$LATEST_TAG+"..HEAD"
  132. $COMMITS_FROM_TAG= ((git rev-list $REV_LIST --count) | Out-String).Trim()
  133. $Env:SFTPGO_ISS_DEV_VERSION = $LATEST_TAG + "." + $COMMITS_FROM_TAG
  134. $CERT_PATH=(Get-Location -PSProvider FileSystem).ProviderPath + "\cert.pfx"
  135. [IO.File]::WriteAllBytes($CERT_PATH,[System.Convert]::FromBase64String($Env:CERT_DATA))
  136. certutil -f -p "$Env:CERT_PASS" -importpfx MY "$CERT_PATH"
  137. rm "$CERT_PATH"
  138. & 'C:/Program Files (x86)/Windows Kits/10/bin/10.0.20348.0/x86/signtool.exe' sign /sm /tr http://timestamp.sectigo.com /td sha256 /fd sha256 /n "Nicola Murino" /d "SFTPGo" .\sftpgo.exe
  139. & 'C:/Program Files (x86)/Windows Kits/10/bin/10.0.20348.0/x86/signtool.exe' sign /sm /tr http://timestamp.sectigo.com /td sha256 /fd sha256 /n "Nicola Murino" /d "SFTPGo" .\arm64\sftpgo.exe
  140. & 'C:/Program Files (x86)/Windows Kits/10/bin/10.0.20348.0/x86/signtool.exe' sign /sm /tr http://timestamp.sectigo.com /td sha256 /fd sha256 /n "Nicola Murino" /d "SFTPGo" .\x86\sftpgo.exe
  141. $INNO_S='/Ssigntool=$qC:/Program Files (x86)/Windows Kits/10/bin/10.0.20348.0/x86/signtool.exe$q sign /sm /tr http://timestamp.sectigo.com /td sha256 /fd sha256 /n $qNicola Murino$q /d $qSFTPGo$q $f'
  142. iscc "$INNO_S" .\windows-installer\sftpgo.iss
  143. rm .\output\sftpgo.exe
  144. rm .\output\sftpgo.db
  145. copy .\arm64\sftpgo.exe .\output
  146. (Get-Content .\output\sftpgo.json).replace('"sqlite"', '"bolt"') | Set-Content .\output\sftpgo.json
  147. $Env:SFTPGO_DATA_PROVIDER__DRIVER='bolt'
  148. $Env:SFTPGO_DATA_PROVIDER__NAME='.\output\sftpgo.db'
  149. .\sftpgo.exe initprovider
  150. Remove-Item Env:\SFTPGO_DATA_PROVIDER__DRIVER
  151. Remove-Item Env:\SFTPGO_DATA_PROVIDER__NAME
  152. $Env:SFTPGO_ISS_ARCH='arm64'
  153. iscc "$INNO_S" .\windows-installer\sftpgo.iss
  154. rm .\output\sftpgo.exe
  155. copy .\x86\sftpgo.exe .\output
  156. $Env:SFTPGO_ISS_ARCH='x86'
  157. iscc "$INNO_S" .\windows-installer\sftpgo.iss
  158. certutil -delstore MY "Nicola Murino"
  159. env:
  160. CERT_DATA: ${{ secrets.CERT_DATA }}
  161. CERT_PASS: ${{ secrets.CERT_PASS }}
  162. - name: Upload Windows installer x86_64 artifact
  163. if: ${{ startsWith(matrix.os, 'windows-') && github.event_name != 'pull_request' }}
  164. uses: actions/upload-artifact@v3
  165. with:
  166. name: sftpgo_windows_installer_x86_64
  167. path: ./sftpgo_windows_x86_64.exe
  168. - name: Upload Windows installer arm64 artifact
  169. if: ${{ startsWith(matrix.os, 'windows-') && github.event_name != 'pull_request' }}
  170. uses: actions/upload-artifact@v3
  171. with:
  172. name: sftpgo_windows_installer_arm64
  173. path: ./sftpgo_windows_arm64.exe
  174. - name: Upload Windows installer x86 artifact
  175. if: ${{ startsWith(matrix.os, 'windows-') && github.event_name != 'pull_request' }}
  176. uses: actions/upload-artifact@v3
  177. with:
  178. name: sftpgo_windows_installer_x86
  179. path: ./sftpgo_windows_x86.exe
  180. - name: Prepare build artifact for Windows
  181. if: startsWith(matrix.os, 'windows-')
  182. run: |
  183. Remove-Item -LiteralPath "output" -Force -Recurse -ErrorAction Ignore
  184. mkdir output
  185. copy .\sftpgo.exe .\output
  186. mkdir output\arm64
  187. copy .\arm64\sftpgo.exe .\output\arm64
  188. mkdir output\x86
  189. copy .\x86\sftpgo.exe .\output\x86
  190. copy .\sftpgo.json .\output
  191. (Get-Content .\output\sftpgo.json).replace('"sqlite"', '"bolt"') | Set-Content .\output\sftpgo.json
  192. mkdir output\templates
  193. xcopy .\templates .\output\templates\ /E
  194. mkdir output\static
  195. xcopy .\static .\output\static\ /E
  196. mkdir output\openapi
  197. xcopy .\openapi .\output\openapi\ /E
  198. - name: Upload build artifact
  199. if: startsWith(matrix.os, 'ubuntu-') != true
  200. uses: actions/upload-artifact@v3
  201. with:
  202. name: sftpgo-${{ matrix.os }}-go-${{ matrix.go }}
  203. path: output
  204. test-build-flags:
  205. name: Test build flags
  206. runs-on: ubuntu-latest
  207. steps:
  208. - uses: actions/checkout@v3
  209. - name: Set up Go
  210. uses: actions/setup-go@v4
  211. with:
  212. go-version: '1.20'
  213. - name: Build
  214. run: |
  215. go build -trimpath -tags nopgxregisterdefaulttypes,nogcs,nos3,noportable,nobolt,nomysql,nopgsql,nosqlite,nometrics,noazblob,unixcrypt -ldflags "-s -w -X github.com/drakkan/sftpgo/v2/internal/internal/version.commit=`git describe --always --abbrev=8 --dirty` -X github.com/drakkan/sftpgo/v2/internal/version.date=`date -u +%FT%TZ`" -o sftpgo
  216. ./sftpgo -v
  217. cp -r openapi static templates internal/bundle/
  218. go build -trimpath -tags nopgxregisterdefaulttypes,bundle -ldflags "-s -w -X github.com/drakkan/sftpgo/v2/internal/version.commit=`git describe --always --abbrev=8 --dirty` -X github.com/drakkan/sftpgo/v2/internal/version.date=`date -u +%FT%TZ`" -o sftpgo
  219. ./sftpgo -v
  220. test-postgresql-mysql-crdb:
  221. name: Test with PgSQL/MySQL/Cockroach
  222. runs-on: ubuntu-latest
  223. services:
  224. postgres:
  225. image: postgres:latest
  226. env:
  227. POSTGRES_PASSWORD: postgres
  228. POSTGRES_DB: sftpgo
  229. options: >-
  230. --health-cmd pg_isready
  231. --health-interval 10s
  232. --health-timeout 5s
  233. --health-retries 5
  234. ports:
  235. - 5432:5432
  236. mariadb:
  237. image: mariadb:latest
  238. env:
  239. MYSQL_ROOT_PASSWORD: mysql
  240. MYSQL_DATABASE: sftpgo
  241. MYSQL_USER: sftpgo
  242. MYSQL_PASSWORD: sftpgo
  243. options: >-
  244. --health-cmd "mariadb-admin status -h 127.0.0.1 -P 3306 -u root -p$MYSQL_ROOT_PASSWORD"
  245. --health-interval 10s
  246. --health-timeout 5s
  247. --health-retries 6
  248. ports:
  249. - 3307:3306
  250. mysql:
  251. image: mysql:latest
  252. env:
  253. MYSQL_ROOT_PASSWORD: mysql
  254. MYSQL_DATABASE: sftpgo
  255. MYSQL_USER: sftpgo
  256. MYSQL_PASSWORD: sftpgo
  257. options: >-
  258. --health-cmd "mysqladmin status -h 127.0.0.1 -P 3306 -u root -p$MYSQL_ROOT_PASSWORD"
  259. --health-interval 10s
  260. --health-timeout 5s
  261. --health-retries 6
  262. ports:
  263. - 3308:3306
  264. steps:
  265. - uses: actions/checkout@v3
  266. - name: Set up Go
  267. uses: actions/setup-go@v4
  268. with:
  269. go-version: '1.20'
  270. - name: Build
  271. run: |
  272. go build -trimpath -tags nopgxregisterdefaulttypes -ldflags "-s -w -X github.com/drakkan/sftpgo/v2/internal/version.commit=`git describe --always --abbrev=8 --dirty` -X github.com/drakkan/sftpgo/v2/internal/version.date=`date -u +%FT%TZ`" -o sftpgo
  273. cd tests/eventsearcher
  274. go build -trimpath -ldflags "-s -w" -o eventsearcher
  275. cd -
  276. cd tests/ipfilter
  277. go build -trimpath -ldflags "-s -w" -o ipfilter
  278. cd -
  279. - name: Run tests using MySQL provider
  280. run: |
  281. ./sftpgo initprovider
  282. ./sftpgo resetprovider --force
  283. go test -v -tags nopgxregisterdefaulttypes -p 1 -timeout 15m ./... -covermode=atomic
  284. env:
  285. SFTPGO_DATA_PROVIDER__DRIVER: mysql
  286. SFTPGO_DATA_PROVIDER__NAME: sftpgo
  287. SFTPGO_DATA_PROVIDER__HOST: localhost
  288. SFTPGO_DATA_PROVIDER__PORT: 3308
  289. SFTPGO_DATA_PROVIDER__USERNAME: sftpgo
  290. SFTPGO_DATA_PROVIDER__PASSWORD: sftpgo
  291. - name: Run tests using PostgreSQL provider
  292. run: |
  293. ./sftpgo initprovider
  294. ./sftpgo resetprovider --force
  295. go test -v -tags nopgxregisterdefaulttypes -p 1 -timeout 15m ./... -covermode=atomic
  296. env:
  297. SFTPGO_DATA_PROVIDER__DRIVER: postgresql
  298. SFTPGO_DATA_PROVIDER__NAME: sftpgo
  299. SFTPGO_DATA_PROVIDER__HOST: localhost
  300. SFTPGO_DATA_PROVIDER__PORT: 5432
  301. SFTPGO_DATA_PROVIDER__USERNAME: postgres
  302. SFTPGO_DATA_PROVIDER__PASSWORD: postgres
  303. - name: Run tests using MariaDB provider
  304. run: |
  305. ./sftpgo initprovider
  306. ./sftpgo resetprovider --force
  307. go test -v -tags nopgxregisterdefaulttypes -p 1 -timeout 15m ./... -covermode=atomic
  308. env:
  309. SFTPGO_DATA_PROVIDER__DRIVER: mysql
  310. SFTPGO_DATA_PROVIDER__NAME: sftpgo
  311. SFTPGO_DATA_PROVIDER__HOST: localhost
  312. SFTPGO_DATA_PROVIDER__PORT: 3307
  313. SFTPGO_DATA_PROVIDER__USERNAME: sftpgo
  314. SFTPGO_DATA_PROVIDER__PASSWORD: sftpgo
  315. SFTPGO_DATA_PROVIDER__SQL_TABLES_PREFIX: prefix_
  316. - name: Run tests using CockroachDB provider
  317. run: |
  318. docker run --rm --name crdb --health-cmd "curl -I http://127.0.0.1:8080" --health-interval 10s --health-timeout 5s --health-retries 6 -p 26257:26257 -d cockroachdb/cockroach:latest start-single-node --insecure --listen-addr :26257
  319. sleep 10
  320. docker exec crdb cockroach sql --insecure -e 'create database "sftpgo"'
  321. ./sftpgo initprovider
  322. ./sftpgo resetprovider --force
  323. go test -v -tags nopgxregisterdefaulttypes -p 1 -timeout 15m ./... -covermode=atomic
  324. docker stop crdb
  325. env:
  326. SFTPGO_DATA_PROVIDER__DRIVER: cockroachdb
  327. SFTPGO_DATA_PROVIDER__NAME: sftpgo
  328. SFTPGO_DATA_PROVIDER__HOST: localhost
  329. SFTPGO_DATA_PROVIDER__PORT: 26257
  330. SFTPGO_DATA_PROVIDER__USERNAME: root
  331. SFTPGO_DATA_PROVIDER__PASSWORD:
  332. SFTPGO_DATA_PROVIDER__TARGET_SESSION_ATTRS: any
  333. SFTPGO_DATA_PROVIDER__SQL_TABLES_PREFIX: prefix_
  334. build-linux-packages:
  335. name: Build Linux packages
  336. runs-on: ubuntu-latest
  337. strategy:
  338. matrix:
  339. include:
  340. - arch: amd64
  341. distro: ubuntu:18.04
  342. go: latest
  343. go-arch: amd64
  344. - arch: aarch64
  345. distro: ubuntu18.04
  346. go: latest
  347. go-arch: arm64
  348. - arch: ppc64le
  349. distro: ubuntu18.04
  350. go: latest
  351. go-arch: ppc64le
  352. - arch: armv7
  353. distro: ubuntu18.04
  354. go: latest
  355. go-arch: arm7
  356. steps:
  357. - uses: actions/checkout@v3
  358. with:
  359. fetch-depth: 0
  360. - name: Get commit SHA
  361. id: get_commit
  362. run: echo "COMMIT=${GITHUB_SHA::8}" >> $GITHUB_OUTPUT
  363. shell: bash
  364. - name: Build on amd64
  365. if: ${{ matrix.arch == 'amd64' }}
  366. run: |
  367. echo '#!/bin/bash' > build.sh
  368. echo '' >> build.sh
  369. echo 'set -e' >> build.sh
  370. echo 'apt-get update -q -y' >> build.sh
  371. echo 'apt-get install -q -y curl gcc' >> build.sh
  372. if [ ${{ matrix.go }} == 'latest' ]
  373. then
  374. echo 'GO_VERSION=$(curl -L https://go.dev/VERSION?m=text)' >> build.sh
  375. else
  376. echo 'GO_VERSION=${{ matrix.go }}' >> build.sh
  377. fi
  378. echo 'GO_DOWNLOAD_ARCH=${{ matrix.go-arch }}' >> build.sh
  379. echo 'curl --retry 5 --retry-delay 2 --connect-timeout 10 -o go.tar.gz -L https://go.dev/dl/${GO_VERSION}.linux-${GO_DOWNLOAD_ARCH}.tar.gz' >> build.sh
  380. echo 'tar -C /usr/local -xzf go.tar.gz' >> build.sh
  381. echo 'export PATH=$PATH:/usr/local/go/bin' >> build.sh
  382. echo 'go version' >> build.sh
  383. echo 'cd /usr/local/src' >> build.sh
  384. echo 'go build -buildvcs=false -trimpath -tags nopgxregisterdefaulttypes -ldflags "-s -w -X github.com/drakkan/sftpgo/v2/internal/version.commit=${{ steps.get_commit.outputs.COMMIT }} -X github.com/drakkan/sftpgo/v2/internal/version.date=`date -u +%FT%TZ`" -o sftpgo' >> build.sh
  385. chmod 755 build.sh
  386. docker run --rm --name ubuntu-build --mount type=bind,source=`pwd`,target=/usr/local/src ${{ matrix.distro }} /usr/local/src/build.sh
  387. mkdir -p output/{init,bash_completion,zsh_completion}
  388. cp sftpgo.json output/
  389. cp -r templates output/
  390. cp -r static output/
  391. cp -r openapi output/
  392. cp init/sftpgo.service output/init/
  393. ./sftpgo gen completion bash > output/bash_completion/sftpgo
  394. ./sftpgo gen completion zsh > output/zsh_completion/_sftpgo
  395. ./sftpgo gen man -d output/man/man1
  396. gzip output/man/man1/*
  397. cp sftpgo output/
  398. - uses: uraimo/run-on-arch-action@v2
  399. if: ${{ matrix.arch != 'amd64' }}
  400. name: Build for ${{ matrix.arch }}
  401. id: build
  402. with:
  403. arch: ${{ matrix.arch }}
  404. distro: ${{ matrix.distro }}
  405. setup: |
  406. mkdir -p "${PWD}/output"
  407. dockerRunArgs: |
  408. --volume "${PWD}/output:/output"
  409. shell: /bin/bash
  410. install: |
  411. apt-get update -q -y
  412. apt-get install -q -y curl gcc
  413. if [ ${{ matrix.go }} == 'latest' ]
  414. then
  415. GO_VERSION=$(curl -L https://go.dev/VERSION?m=text)
  416. else
  417. GO_VERSION=${{ matrix.go }}
  418. fi
  419. GO_DOWNLOAD_ARCH=${{ matrix.go-arch }}
  420. if [ ${{ matrix.arch}} == 'armv7' ]
  421. then
  422. GO_DOWNLOAD_ARCH=armv6l
  423. fi
  424. curl --retry 5 --retry-delay 2 --connect-timeout 10 -o go.tar.gz -L https://go.dev/dl/${GO_VERSION}.linux-${GO_DOWNLOAD_ARCH}.tar.gz
  425. tar -C /usr/local -xzf go.tar.gz
  426. run: |
  427. export PATH=$PATH:/usr/local/go/bin
  428. go version
  429. if [ ${{ matrix.arch}} == 'armv7' ]
  430. then
  431. export GOARM=7
  432. fi
  433. go build -buildvcs=false -trimpath -tags nopgxregisterdefaulttypes -ldflags "-s -w -X github.com/drakkan/sftpgo/v2/internal/version.commit=${{ steps.get_commit.outputs.COMMIT }} -X github.com/drakkan/sftpgo/v2/internal/version.date=`date -u +%FT%TZ`" -o sftpgo
  434. mkdir -p output/{init,bash_completion,zsh_completion}
  435. cp sftpgo.json output/
  436. cp -r templates output/
  437. cp -r static output/
  438. cp -r openapi output/
  439. cp init/sftpgo.service output/init/
  440. ./sftpgo gen completion bash > output/bash_completion/sftpgo
  441. ./sftpgo gen completion zsh > output/zsh_completion/_sftpgo
  442. ./sftpgo gen man -d output/man/man1
  443. gzip output/man/man1/*
  444. cp sftpgo output/
  445. - name: Upload build artifact
  446. uses: actions/upload-artifact@v3
  447. with:
  448. name: sftpgo-linux-${{ matrix.arch }}-go-${{ matrix.go }}
  449. path: output
  450. - name: Build Packages
  451. id: build_linux_pkgs
  452. run: |
  453. export NFPM_ARCH=${{ matrix.go-arch }}
  454. cd pkgs
  455. ./build.sh
  456. PKG_VERSION=$(cat dist/version)
  457. echo "pkg-version=${PKG_VERSION}" >> $GITHUB_OUTPUT
  458. - name: Upload Debian Package
  459. uses: actions/upload-artifact@v3
  460. with:
  461. name: sftpgo-${{ steps.build_linux_pkgs.outputs.pkg-version }}-${{ matrix.go-arch }}-deb
  462. path: pkgs/dist/deb/*
  463. - name: Upload RPM Package
  464. uses: actions/upload-artifact@v3
  465. with:
  466. name: sftpgo-${{ steps.build_linux_pkgs.outputs.pkg-version }}-${{ matrix.go-arch }}-rpm
  467. path: pkgs/dist/rpm/*
  468. golangci-lint:
  469. name: golangci-lint
  470. runs-on: ubuntu-latest
  471. steps:
  472. - name: Set up Go
  473. uses: actions/setup-go@v4
  474. with:
  475. go-version: '1.20'
  476. - uses: actions/checkout@v3
  477. - name: Run golangci-lint
  478. uses: golangci/golangci-lint-action@v3
  479. with:
  480. version: latest