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.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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@v2
  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@v1
  55. with:
  56. submodules: true
  57. - name: Setup Java 8
  58. uses: actions/setup-java@v1
  59. with:
  60. java-version: 8
  61. - name: Report Java version
  62. run: |
  63. java -version
  64. javac -version
  65. - name: Build GO with Ant
  66. run: ant buildGO
  67. - name: Save built Gitblit package
  68. if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/develop' }}
  69. uses: actions/upload-artifact@v2
  70. with:
  71. name: gitblit-nightly
  72. path: build/target/gitblit-*-SNAPSHOT.tar.gz
  73. # This is a gating job, which checks if the secrets necessary for pushing an image
  74. # to the docker hub are present in the repository. This way this workflow can be
  75. # present in repos which cannot upload to the docker hub.
  76. secret-gate:
  77. name: Gate job checking for docker hub secret
  78. runs-on: ubuntu-latest
  79. needs: build
  80. outputs:
  81. build_docker: ${{steps.check-dh-login.outputs.secrets_present}}
  82. steps:
  83. - name: Check if we have the necessary data for docker
  84. id: check-dh-login
  85. run: |
  86. if [[ -n "${{secrets.DOCKERHUB_GB_TOKEN}}" && -n "${{secrets.DOCKERHUB_GB_USER}}" ]] ; then
  87. echo "::set-output name=secrets_present::true"
  88. fi
  89. # Only if the gating job signals success will this job run and build and push the docker image
  90. # built for the current snapshot version of Gitblit.
  91. docker:
  92. name: Build and push nightly docker image
  93. runs-on: ubuntu-latest
  94. if: ${{needs.secret-gate.outputs.build_docker == 'true'}} && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/develop')
  95. needs: secret-gate
  96. env:
  97. GH_ORG: gitblit
  98. GITBLIT_VERSION: SNAPSHOT
  99. steps:
  100. - name: Checkout gitblit-docker
  101. uses: actions/checkout@v1
  102. with:
  103. repository: ${{ env.GH_ORG }}/gitblit-docker
  104. ref: master
  105. fetch-depth: 2
  106. - name: Download Gitblit nightly build
  107. uses: actions/download-artifact@v2
  108. id: get-gb
  109. with:
  110. name: gitblit-nightly
  111. path: ../gitblit-docker
  112. # Delete the artifact unless this is the official Gitblit repo
  113. - uses: geekyeggo/delete-artifact@v1
  114. if: ${{ github.repository != 'gitblit/gitblit' }}
  115. with:
  116. name: gitblit-nightly
  117. failOnError: false
  118. - name: Extract snapshot version
  119. id: gb-version
  120. working-directory: ../gitblit-docker
  121. run: |
  122. for file in $(ls -1 ${{steps.get-gb.outputs.download-path}}) ; do
  123. if [[ "$file" = gitblit-*.gz ]] ; then gbver=$file ; fi
  124. done
  125. gbver=${gbver%.tar.gz}
  126. gbver=${gbver##*gitblit-}
  127. echo "Version detected: $gbver"
  128. echo "GITBLIT_VERSION=$gbver" >> "${GITHUB_ENV}"
  129. echo "::set-output name=gb-version::$gbver"
  130. - name: Generate Dockerfile for snapshot image
  131. working-directory: ../gitblit-docker
  132. run: |
  133. generate/generate_dockerfile.sh -v ${{ steps.gb-version.outputs.gb-version }} > generate/Dockerfile
  134. echo "BUILD_DATE=$(date +%Y-%m-%dT%H:%M:%S)" >> "${GITHUB_ENV}"
  135. - name: Login to Docker Hub
  136. uses: docker/login-action@v1
  137. with:
  138. username: ${{ secrets.DOCKERHUB_GB_USER }}
  139. password: ${{ secrets.DOCKERHUB_GB_TOKEN }}
  140. - name: Build snapshot docker image
  141. uses: docker/build-push-action@v2
  142. with:
  143. file: ../gitblit-docker/generate/Dockerfile
  144. context: ../gitblit-docker
  145. load: true
  146. tags: gitblit/gitblit:nightly
  147. labels: |
  148. org.label-schema.vcs-ref=${{github.sha}}
  149. org.label-schema.build-date=${{env.BUILD_DATE}}
  150. org.opencontainers.image.revision=${{ env.GITBLIT_GIT_SHA }}
  151. org.opencontainers.image.created=${{ env.BUILD_DATE }}
  152. - name: Install Goss for testing the docker image
  153. uses: e1himself/goss-installation-action@v1.0.4
  154. with:
  155. version: 'v0.3.16'
  156. - name: Test docker container - normal mode
  157. working-directory: ../gitblit-docker
  158. env:
  159. GOSS_WAIT_OPTS: "-r 15s -s 5s > /dev/null"
  160. run: |
  161. dgoss run -p 8080:8080 -p 8443:8443 gitblit/gitblit:nightly
  162. - name: Test docker container - bind mount
  163. working-directory: ../gitblit-docker
  164. env:
  165. GOSS_WAIT_OPTS: "-r 15s -s 5s > /dev/null"
  166. run: |
  167. mkdir gitblit-data
  168. mkdir gitblit-data/etc
  169. echo "This should not be overwritten" > gitblit-data/etc/gitblit.properties
  170. echo "include = gitblit-docker.properties" >> gitblit-data/etc/gitblit.properties
  171. sed -e '/mode: / d' -e '/group: / d' goss.yaml > gitblit-data/goss.yaml
  172. cp goss_wait.yaml gitblit-data/
  173. GOSS_FILES_PATH=gitblit-data dgoss run -p 8080:8080 -p 8443:8443 -v "$PWD/gitblit-data":/var/opt/gitblit gitblit/gitblit:nightly
  174. [ -d gitblit-data/srv/git ] || exit 1
  175. [ -f gitblit-data/etc/defaults.properties ] || exit 1
  176. grep --quiet "This should not be overwritten" gitblit-data/etc/gitblit.properties || exit 1
  177. sudo rm -rf gitblit-data
  178. - name: Test docker container - tmpfs
  179. working-directory: ../gitblit-docker
  180. env:
  181. GOSS_WAIT_OPTS: "-r 15s -s 5s > /dev/null"
  182. run: |
  183. dgoss run -p 8080:8080 -p 8443:8443 --tmpfs /var/opt/gitblit/temp gitblit/gitblit:nightly
  184. - name: Push docker image to registry
  185. uses: docker/build-push-action@v2
  186. with:
  187. file: ../gitblit-docker/generate/Dockerfile
  188. context: ../gitblit-docker
  189. push: true
  190. tags: gitblit/gitblit:nightly
  191. labels: |
  192. org.label-schema.vcs-ref=${{github.sha}}
  193. org.label-schema.build-date=${{env.BUILD_DATE}}