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