development.yml 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  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.19]
  13. os: [ubuntu-latest, macos-latest]
  14. upload-coverage: [true]
  15. include:
  16. - go: 1.19
  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@v3
  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 -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 -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-bundle:
  205. name: Build in bundle mode
  206. runs-on: ubuntu-latest
  207. steps:
  208. - uses: actions/checkout@v3
  209. - name: Set up Go
  210. uses: actions/setup-go@v3
  211. with:
  212. go-version: 1.19
  213. - name: Build
  214. run: |
  215. cp -r openapi static templates internal/bundle/
  216. 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
  217. ./sftpgo -v
  218. test-goarch-386:
  219. name: Run test cases on 32-bit arch
  220. runs-on: ubuntu-latest
  221. steps:
  222. - uses: actions/checkout@v3
  223. - name: Set up Go
  224. uses: actions/setup-go@v3
  225. with:
  226. go-version: 1.19
  227. - name: Build
  228. run: |
  229. cd tests/eventsearcher
  230. go build -trimpath -ldflags "-s -w" -o eventsearcher
  231. cd -
  232. cd tests/ipfilter
  233. go build -trimpath -ldflags "-s -w" -o ipfilter
  234. cd -
  235. env:
  236. GOARCH: 386
  237. - name: Run test cases
  238. run: go test -v -tags nopgxregisterdefaulttypes -p 1 -timeout 15m ./... -covermode=atomic
  239. env:
  240. SFTPGO_DATA_PROVIDER__DRIVER: memory
  241. SFTPGO_DATA_PROVIDER__NAME: ''
  242. GOARCH: 386
  243. test-postgresql-mysql-crdb:
  244. name: Test with PgSQL/MySQL/Cockroach
  245. runs-on: ubuntu-latest
  246. services:
  247. postgres:
  248. image: postgres:latest
  249. env:
  250. POSTGRES_PASSWORD: postgres
  251. POSTGRES_DB: sftpgo
  252. options: >-
  253. --health-cmd pg_isready
  254. --health-interval 10s
  255. --health-timeout 5s
  256. --health-retries 5
  257. ports:
  258. - 5432:5432
  259. mariadb:
  260. image: mariadb:latest
  261. env:
  262. MYSQL_ROOT_PASSWORD: mysql
  263. MYSQL_DATABASE: sftpgo
  264. MYSQL_USER: sftpgo
  265. MYSQL_PASSWORD: sftpgo
  266. options: >-
  267. --health-cmd "mysqladmin status -h 127.0.0.1 -P 3306 -u root -p$MYSQL_ROOT_PASSWORD"
  268. --health-interval 10s
  269. --health-timeout 5s
  270. --health-retries 6
  271. ports:
  272. - 3307:3306
  273. mysql:
  274. image: mysql:latest
  275. env:
  276. MYSQL_ROOT_PASSWORD: mysql
  277. MYSQL_DATABASE: sftpgo
  278. MYSQL_USER: sftpgo
  279. MYSQL_PASSWORD: sftpgo
  280. options: >-
  281. --health-cmd "mysqladmin status -h 127.0.0.1 -P 3306 -u root -p$MYSQL_ROOT_PASSWORD"
  282. --health-interval 10s
  283. --health-timeout 5s
  284. --health-retries 6
  285. ports:
  286. - 3308:3306
  287. steps:
  288. - uses: actions/checkout@v3
  289. - name: Set up Go
  290. uses: actions/setup-go@v3
  291. with:
  292. go-version: 1.19
  293. - name: Build
  294. run: |
  295. 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
  296. cd tests/eventsearcher
  297. go build -trimpath -ldflags "-s -w" -o eventsearcher
  298. cd -
  299. cd tests/ipfilter
  300. go build -trimpath -ldflags "-s -w" -o ipfilter
  301. cd -
  302. - name: Run tests using PostgreSQL provider
  303. run: |
  304. ./sftpgo initprovider
  305. ./sftpgo resetprovider --force
  306. go test -v -tags nopgxregisterdefaulttypes -p 1 -timeout 15m ./... -covermode=atomic
  307. env:
  308. SFTPGO_DATA_PROVIDER__DRIVER: postgresql
  309. SFTPGO_DATA_PROVIDER__NAME: sftpgo
  310. SFTPGO_DATA_PROVIDER__HOST: localhost
  311. SFTPGO_DATA_PROVIDER__PORT: 5432
  312. SFTPGO_DATA_PROVIDER__USERNAME: postgres
  313. SFTPGO_DATA_PROVIDER__PASSWORD: postgres
  314. - name: Run tests using MySQL provider
  315. run: |
  316. ./sftpgo initprovider
  317. ./sftpgo resetprovider --force
  318. go test -v -tags nopgxregisterdefaulttypes -p 1 -timeout 15m ./... -covermode=atomic
  319. env:
  320. SFTPGO_DATA_PROVIDER__DRIVER: mysql
  321. SFTPGO_DATA_PROVIDER__NAME: sftpgo
  322. SFTPGO_DATA_PROVIDER__HOST: localhost
  323. SFTPGO_DATA_PROVIDER__PORT: 3308
  324. SFTPGO_DATA_PROVIDER__USERNAME: sftpgo
  325. SFTPGO_DATA_PROVIDER__PASSWORD: sftpgo
  326. - name: Run tests using MariaDB provider
  327. run: |
  328. ./sftpgo initprovider
  329. ./sftpgo resetprovider --force
  330. go test -v -tags nopgxregisterdefaulttypes -p 1 -timeout 15m ./... -covermode=atomic
  331. env:
  332. SFTPGO_DATA_PROVIDER__DRIVER: mysql
  333. SFTPGO_DATA_PROVIDER__NAME: sftpgo
  334. SFTPGO_DATA_PROVIDER__HOST: localhost
  335. SFTPGO_DATA_PROVIDER__PORT: 3307
  336. SFTPGO_DATA_PROVIDER__USERNAME: sftpgo
  337. SFTPGO_DATA_PROVIDER__PASSWORD: sftpgo
  338. SFTPGO_DATA_PROVIDER__SQL_TABLES_PREFIX: prefix_
  339. - name: Run tests using CockroachDB provider
  340. run: |
  341. 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
  342. sleep 10
  343. docker exec crdb cockroach sql --insecure -e 'create database "sftpgo"'
  344. ./sftpgo initprovider
  345. ./sftpgo resetprovider --force
  346. go test -v -tags nopgxregisterdefaulttypes -p 1 -timeout 15m ./... -covermode=atomic
  347. docker stop crdb
  348. env:
  349. SFTPGO_DATA_PROVIDER__DRIVER: cockroachdb
  350. SFTPGO_DATA_PROVIDER__NAME: sftpgo
  351. SFTPGO_DATA_PROVIDER__HOST: localhost
  352. SFTPGO_DATA_PROVIDER__PORT: 26257
  353. SFTPGO_DATA_PROVIDER__USERNAME: root
  354. SFTPGO_DATA_PROVIDER__PASSWORD:
  355. SFTPGO_DATA_PROVIDER__SQL_TABLES_PREFIX: prefix_
  356. build-linux-packages:
  357. name: Build Linux packages
  358. runs-on: ubuntu-latest
  359. strategy:
  360. matrix:
  361. include:
  362. - arch: amd64
  363. distro: ubuntu:18.04
  364. go: latest
  365. go-arch: amd64
  366. - arch: aarch64
  367. distro: ubuntu18.04
  368. go: latest
  369. go-arch: arm64
  370. - arch: ppc64le
  371. distro: ubuntu18.04
  372. go: latest
  373. go-arch: ppc64le
  374. - arch: armv7
  375. distro: ubuntu18.04
  376. go: latest
  377. go-arch: arm7
  378. steps:
  379. - uses: actions/checkout@v3
  380. with:
  381. fetch-depth: 0
  382. - name: Get commit SHA
  383. id: get_commit
  384. run: echo "COMMIT=${GITHUB_SHA::8}" >> $GITHUB_OUTPUT
  385. shell: bash
  386. - name: Build on amd64
  387. if: ${{ matrix.arch == 'amd64' }}
  388. run: |
  389. echo '#!/bin/bash' > build.sh
  390. echo '' >> build.sh
  391. echo 'set -e' >> build.sh
  392. echo 'apt-get update -q -y' >> build.sh
  393. echo 'apt-get install -q -y curl gcc' >> build.sh
  394. if [ ${{ matrix.go }} == 'latest' ]
  395. then
  396. echo 'GO_VERSION=$(curl -L https://go.dev/VERSION?m=text)' >> build.sh
  397. else
  398. echo 'GO_VERSION=${{ matrix.go }}' >> build.sh
  399. fi
  400. echo 'GO_DOWNLOAD_ARCH=${{ matrix.go-arch }}' >> build.sh
  401. 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
  402. echo 'tar -C /usr/local -xzf go.tar.gz' >> build.sh
  403. echo 'export PATH=$PATH:/usr/local/go/bin' >> build.sh
  404. echo 'go version' >> build.sh
  405. echo 'cd /usr/local/src' >> build.sh
  406. 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
  407. chmod 755 build.sh
  408. docker run --rm --name ubuntu-build --mount type=bind,source=`pwd`,target=/usr/local/src ${{ matrix.distro }} /usr/local/src/build.sh
  409. mkdir -p output/{init,bash_completion,zsh_completion}
  410. cp sftpgo.json output/
  411. cp -r templates output/
  412. cp -r static output/
  413. cp -r openapi output/
  414. cp init/sftpgo.service output/init/
  415. ./sftpgo gen completion bash > output/bash_completion/sftpgo
  416. ./sftpgo gen completion zsh > output/zsh_completion/_sftpgo
  417. ./sftpgo gen man -d output/man/man1
  418. gzip output/man/man1/*
  419. cp sftpgo output/
  420. - uses: uraimo/run-on-arch-action@v2
  421. if: ${{ matrix.arch != 'amd64' }}
  422. name: Build for ${{ matrix.arch }}
  423. id: build
  424. with:
  425. arch: ${{ matrix.arch }}
  426. distro: ${{ matrix.distro }}
  427. setup: |
  428. mkdir -p "${PWD}/output"
  429. dockerRunArgs: |
  430. --volume "${PWD}/output:/output"
  431. shell: /bin/bash
  432. install: |
  433. apt-get update -q -y
  434. apt-get install -q -y curl gcc
  435. if [ ${{ matrix.go }} == 'latest' ]
  436. then
  437. GO_VERSION=$(curl -L https://go.dev/VERSION?m=text)
  438. else
  439. GO_VERSION=${{ matrix.go }}
  440. fi
  441. GO_DOWNLOAD_ARCH=${{ matrix.go-arch }}
  442. if [ ${{ matrix.arch}} == 'armv7' ]
  443. then
  444. GO_DOWNLOAD_ARCH=armv6l
  445. fi
  446. 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
  447. tar -C /usr/local -xzf go.tar.gz
  448. run: |
  449. export PATH=$PATH:/usr/local/go/bin
  450. go version
  451. if [ ${{ matrix.arch}} == 'armv7' ]
  452. then
  453. export GOARM=7
  454. fi
  455. 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
  456. mkdir -p output/{init,bash_completion,zsh_completion}
  457. cp sftpgo.json output/
  458. cp -r templates output/
  459. cp -r static output/
  460. cp -r openapi output/
  461. cp init/sftpgo.service output/init/
  462. ./sftpgo gen completion bash > output/bash_completion/sftpgo
  463. ./sftpgo gen completion zsh > output/zsh_completion/_sftpgo
  464. ./sftpgo gen man -d output/man/man1
  465. gzip output/man/man1/*
  466. cp sftpgo output/
  467. - name: Upload build artifact
  468. uses: actions/upload-artifact@v3
  469. with:
  470. name: sftpgo-linux-${{ matrix.arch }}-go-${{ matrix.go }}
  471. path: output
  472. - name: Build Packages
  473. id: build_linux_pkgs
  474. run: |
  475. export NFPM_ARCH=${{ matrix.go-arch }}
  476. cd pkgs
  477. ./build.sh
  478. PKG_VERSION=$(cat dist/version)
  479. echo "pkg-version=${PKG_VERSION}" >> $GITHUB_OUTPUT
  480. - name: Upload Debian Package
  481. uses: actions/upload-artifact@v3
  482. with:
  483. name: sftpgo-${{ steps.build_linux_pkgs.outputs.pkg-version }}-${{ matrix.go-arch }}-deb
  484. path: pkgs/dist/deb/*
  485. - name: Upload RPM Package
  486. uses: actions/upload-artifact@v3
  487. with:
  488. name: sftpgo-${{ steps.build_linux_pkgs.outputs.pkg-version }}-${{ matrix.go-arch }}-rpm
  489. path: pkgs/dist/rpm/*
  490. golangci-lint:
  491. name: golangci-lint
  492. runs-on: ubuntu-latest
  493. steps:
  494. - name: Set up Go
  495. uses: actions/setup-go@v3
  496. with:
  497. go-version: 1.19
  498. - uses: actions/checkout@v3
  499. - name: Run golangci-lint
  500. uses: golangci/golangci-lint-action@v3
  501. with:
  502. version: latest