You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

nightly-build.yml 7.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. # Nightly build of a snapshot version
  2. # and a docker image which is pushed
  3. # to a docker registry
  4. name: Nightly image build and push
  5. on:
  6. workflow_dispatch:
  7. inputs:
  8. forced:
  9. description: 'Force run, independent of new commits'
  10. required: false
  11. default: 'false'
  12. schedule:
  13. - cron: '33 1 * * *'
  14. jobs:
  15. # Check if new commits were added since the last time this workflow ran.
  16. # The Github cache is used for this, using the SHA as the key.
  17. check_commits:
  18. name: Check for new commits
  19. runs-on: ubuntu-latest
  20. outputs:
  21. build: ${{ steps.cache-sha.outputs.cache-hit == false }}
  22. steps:
  23. - name: Cache marker for latest commit
  24. uses: actions/cache@v3
  25. id: cache-sha
  26. with:
  27. key: sha-${{ github.sha }}
  28. path: timestamp.txt
  29. - name: Register latest commit
  30. if: ${{ steps.cache-sha.outputs.cache-hit == false }}
  31. run: |
  32. echo "Current commit $GITHUB_SHA has no cache hit."
  33. date > timestamp.txt
  34. echo "Build job should be triggered now"
  35. cat timestamp.txt
  36. - name: Stop on no new commit
  37. if: ${{ steps.cache-sha.outputs.cache-hit }}
  38. run: |
  39. echo "Current commit $GITHUB_SHA was already seen."
  40. echo "Build job should be skipped."
  41. [ -f timestamp.txt ] && cat timestamp.txt
  42. # Build Gitblit GO so that it can be packed into a docker image.
  43. # The built tarball is saved as an artefact, it can be downloaded
  44. # by interested parties.
  45. # We could even do better and check if paths of source files changed,
  46. # but that is not that easy, so we build on any commit.
  47. build:
  48. name: build GO
  49. runs-on: ubuntu-latest
  50. needs: check_commits
  51. if: ${{ needs.check_commits.outputs.build == 'true' || github.event.inputs.forced == 'true' }}
  52. steps:
  53. - name: Checkout Gitblit
  54. uses: actions/checkout@v3
  55. with:
  56. submodules: true
  57. - name: Setup Java 8
  58. uses: actions/setup-java@v3
  59. with:
  60. java-version: 8
  61. distribution: 'temurin'
  62. - name: Report Java version
  63. run: |
  64. java -version
  65. javac -version
  66. - name: Build GO with Ant
  67. run: ant buildGO
  68. - name: Save built Gitblit package
  69. if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/develop' }}
  70. uses: actions/upload-artifact@v3
  71. with:
  72. name: gitblit-nightly
  73. path: build/target/gitblit-*-SNAPSHOT.tar.gz
  74. # This is a gating job, which checks if the secrets necessary for pushing an image
  75. # to the docker hub are present in the repository. This way this workflow can be
  76. # present in repos which cannot upload to the docker hub.
  77. secret-gate:
  78. name: Gate job checking for docker hub secret
  79. runs-on: ubuntu-latest
  80. needs: build
  81. outputs:
  82. build_docker: ${{steps.check-dh-login.outputs.secrets_present}}
  83. steps:
  84. - name: Check if we have the necessary data for docker
  85. id: check-dh-login
  86. run: |
  87. if [[ -n "${{secrets.DOCKERHUB_GB_TOKEN}}" && -n "${{secrets.DOCKERHUB_GB_USER}}" ]] ; then
  88. echo "secrets_present=true" >> $GITHUB_OUTPUT
  89. else
  90. echo "No Docker Hub login data found. Skipping Docker."
  91. fi
  92. # Only if the gating job signals success will this job run and build and push the docker image
  93. # built for the current snapshot version of Gitblit.
  94. docker:
  95. name: Build and push nightly docker image
  96. runs-on: ubuntu-latest
  97. if: needs.secret-gate.outputs.build_docker == 'true' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/develop')
  98. needs: secret-gate
  99. env:
  100. GH_ORG: gitblit-org
  101. GITBLIT_VERSION: SNAPSHOT
  102. steps:
  103. - name: Checkout gitblit-docker
  104. uses: actions/checkout@v3
  105. with:
  106. repository: ${{ env.GH_ORG }}/gitblit-docker
  107. ref: master
  108. fetch-depth: 2
  109. - name: Download Gitblit nightly build
  110. uses: actions/download-artifact@v3
  111. id: get-gb
  112. with:
  113. name: gitblit-nightly
  114. - name: Extract snapshot version
  115. id: gb-version
  116. run: |
  117. for file in $(ls -1 ${{steps.get-gb.outputs.download-path}}) ; do
  118. if [[ "$file" = gitblit-*.gz ]] ; then gbver=$file ; fi
  119. done
  120. gbver=${gbver%.tar.gz}
  121. gbver=${gbver##*gitblit-}
  122. echo "Version detected: $gbver"
  123. echo "GITBLIT_VERSION=$gbver" >> "${GITHUB_ENV}"
  124. echo "gb-version=$gbver" >> $GITHUB_OUTPUT
  125. - name: Generate Dockerfile for snapshot image
  126. run: |
  127. generate/generate_dockerfile.sh -v ${{ steps.gb-version.outputs.gb-version }} > generate/Dockerfile
  128. echo "BUILD_DATE=$(date +%Y-%m-%dT%H:%M:%S)" >> "${GITHUB_ENV}"
  129. - name: Login to Docker Hub
  130. uses: docker/login-action@v2
  131. with:
  132. username: ${{ secrets.DOCKERHUB_GB_USER }}
  133. password: ${{ secrets.DOCKERHUB_GB_TOKEN }}
  134. - name: Build snapshot docker image
  135. uses: docker/build-push-action@v3
  136. with:
  137. file: generate/Dockerfile
  138. context: .
  139. load: true
  140. tags: gitblit/gitblit:nightly
  141. labels: |
  142. org.label-schema.vcs-ref=${{github.sha}}
  143. org.label-schema.build-date=${{env.BUILD_DATE}}
  144. org.opencontainers.image.revision=${{ env.GITBLIT_GIT_SHA }}
  145. org.opencontainers.image.created=${{ env.BUILD_DATE }}
  146. - name: Install Goss for testing the docker image
  147. uses: e1himself/goss-installation-action@v1.0.4
  148. with:
  149. version: 'v0.3.16'
  150. - name: Test docker container - normal mode
  151. env:
  152. GOSS_WAIT_OPTS: "-r 15s -s 5s > /dev/null"
  153. run: |
  154. dgoss run -p 8080:8080 -p 8443:8443 gitblit/gitblit:nightly
  155. - name: Test docker container - bind mount
  156. env:
  157. GOSS_WAIT_OPTS: "-r 15s -s 5s > /dev/null"
  158. run: |
  159. mkdir gitblit-data
  160. mkdir gitblit-data/etc
  161. echo "This should not be overwritten" > gitblit-data/etc/gitblit.properties
  162. echo "include = gitblit-docker.properties" >> gitblit-data/etc/gitblit.properties
  163. sed -e '/mode: / d' -e '/group: / d' goss.yaml > gitblit-data/goss.yaml
  164. cp goss_wait.yaml gitblit-data/
  165. GOSS_FILES_PATH=gitblit-data dgoss run -p 8080:8080 -p 8443:8443 -v "$PWD/gitblit-data":/var/opt/gitblit gitblit/gitblit:nightly
  166. [ -d gitblit-data/srv/git ] || exit 1
  167. [ -f gitblit-data/etc/defaults.properties ] || exit 1
  168. grep --quiet "This should not be overwritten" gitblit-data/etc/gitblit.properties || exit 1
  169. sudo rm -rf gitblit-data
  170. - name: Test docker container - tmpfs
  171. env:
  172. GOSS_WAIT_OPTS: "-r 15s -s 5s > /dev/null"
  173. run: |
  174. dgoss run -p 8080:8080 -p 8443:8443 --tmpfs /var/opt/gitblit/temp gitblit/gitblit:nightly
  175. # Delete the artifact unless this is the official Gitblit repo
  176. - uses: geekyeggo/delete-artifact@v2
  177. if: ${{ github.repository != 'gitblit-org/gitblit' }}
  178. with:
  179. name: gitblit-nightly
  180. failOnError: false
  181. - name: Push docker image to registry
  182. uses: docker/build-push-action@v3
  183. with:
  184. file: generate/Dockerfile
  185. context: .
  186. push: true
  187. tags: gitblit/gitblit:nightly
  188. labels: |
  189. org.label-schema.vcs-ref=${{github.sha}}
  190. org.label-schema.build-date=${{env.BUILD_DATE}}