@@ -48,12 +48,28 @@ jobs:
4848 # Checkout repository --------------------------------------------------------------------
4949 - uses : actions/checkout@v2
5050
51+ # Checkout release tag (if on release branch)
52+ - name : Checkout release tag (if on release branch)
53+ if : github.ref == 'refs/heads/ci-release'
54+ env :
55+ GH_TOKEN : ${{ github.token }}
56+ IMAGE_NAME : ${{ matrix.image }}
57+ run : |
58+ git config --global --add safe.directory "$PWD"
59+ git fetch --tags
60+ latest_tag="$(git tag | grep 'v[0-9]*\.[0-9]*\.[0-9]*' | sort -rn | head -n1)"
61+ if [ -z "$latest_tag" ]; then
62+ echo "could not find latest tag"
63+ exit 1
64+ fi
65+ git checkout "$latest_tag"
66+
5167 # Build LIBFDS DEB package ---------------------------------------------------------------
5268 - name : Checkout libfds library - master branch
53- if : github.ref == 'refs/heads/master'
69+ if : github.ref == 'refs/heads/master' || github.ref == 'refs/heads/ci-release'
5470 run : git clone --branch master https://github.com/CESNET/libfds.git build/libfds_repo
5571 - name : Checkout libfds library - devel branch
56- if : github.ref != 'refs/heads/master'
72+ if : github.ref != 'refs/heads/master' && github.ref != 'refs/heads/ci-release'
5773 run : git clone --branch devel https://github.com/CESNET/libfds.git build/libfds_repo
5874 - name : Build DEBs of libfds library and install them
5975 working-directory : ' build/libfds_repo'
@@ -86,6 +102,44 @@ jobs:
86102 build/pkg/deb/debbuild/*.tar.gz
87103 build/pkg/deb/debbuild/*.dsc
88104
105+ - name : Publish DEB packages to GitHub releases (latest)
106+ if : github.ref == 'refs/heads/master' || github.ref == 'refs/heads/ci-publish-packages-to-releases'
107+ env :
108+ GH_TOKEN : ${{ github.token }}
109+ IMAGE_NAME : ${{ matrix.image }}
110+ run : |
111+ curl -sL "$(curl -sL "https://api.github.com/repos/cli/cli/releases" | grep _linux_amd64.tar.gz | grep https | head -n1 | cut -d'"' -f4)" -o gh.tar.gz \
112+ && tar xzf gh.tar.gz \
113+ && find gh*/ -name gh -exec mv {} /usr/local/bin/ \;
114+ git config --global --add safe.directory "$PWD" \
115+ && git tag -f ci-latest HEAD \
116+ && git push -f origin tag ci-latest
117+ find build/ -iname '*.deb' | while read -r f; do
118+ newf="$IMAGE_NAME-$(basename "$f")"
119+ mv "$f" "$newf"
120+ gh release upload --clobber ci-latest "$newf"
121+ done
122+
123+ - name : Publish DEB packages to GitHub releases (stable)
124+ if : github.ref == 'refs/heads/ci-release'
125+ env :
126+ GH_TOKEN : ${{ github.token }}
127+ IMAGE_NAME : ${{ matrix.image }}
128+ run : |
129+ curl -sL "$(curl -sL "https://api.github.com/repos/cli/cli/releases" | grep _linux_amd64.tar.gz | grep https | head -n1 | cut -d'"' -f4)" -o gh.tar.gz \
130+ && tar xzf gh.tar.gz \
131+ && find gh*/ -name gh -exec mv {} /usr/local/bin/ \;
132+ latest_tag="$(git describe --exact-match --tags)"
133+ if ! gh release view "$latest_tag"; then
134+ echo "could not find release for tag $latest_tag"
135+ exit 1
136+ fi
137+ find build/ -iname '*.deb' | while read -r f; do
138+ newf="$IMAGE_NAME-$(basename "$f")"
139+ mv "$f" "$newf"
140+ gh release upload --clobber "$latest_tag" "$newf"
141+ done
142+
89143 rpm :
90144 # Try to build RPM packages
91145 runs-on : ubuntu-latest
@@ -153,12 +207,28 @@ jobs:
153207 # Checkout repository --------------------------------------------------------------------
154208 - uses : actions/checkout@v2
155209
210+ # Checkout release tag (if on release branch)
211+ - name : Checkout release tag (if on release branch)
212+ if : github.ref == 'refs/heads/ci-release'
213+ env :
214+ GH_TOKEN : ${{ github.token }}
215+ IMAGE_NAME : ${{ matrix.image }}
216+ run : |
217+ git config --global --add safe.directory "$PWD"
218+ git fetch --tags
219+ latest_tag="$(git tag | grep 'v[0-9]*\.[0-9]*\.[0-9]*' | sort -rn | head -n1)"
220+ if [ -z "$latest_tag" ]; then
221+ echo "could not find latest tag"
222+ exit 1
223+ fi
224+ git checkout "$latest_tag"
225+
156226 # Build LIBFDS RPM package ---------------------------------------------------------------
157227 - name : Checkout libfds library - master branch
158- if : github.ref == 'refs/heads/master'
228+ if : github.ref == 'refs/heads/master' || github.ref == 'refs/heads/ci-release'
159229 run : git clone --branch master https://github.com/CESNET/libfds.git build/libfds_repo
160230 - name : Checkout libfds library - devel branch
161- if : github.ref != 'refs/heads/master'
231+ if : github.ref != 'refs/heads/master' && github.ref != 'refs/heads/ci-release'
162232 run : git clone --branch devel https://github.com/CESNET/libfds.git build/libfds_repo
163233 - name : Build RPMs of libfds library and install it
164234 working-directory : ' build/libfds_repo'
@@ -203,3 +273,41 @@ jobs:
203273 path : |
204274 build/pkg/rpm/rpmbuild/RPMS/
205275 build/pkg/rpm/rpmbuild/SRPMS/
276+
277+ - name : Publish RPM packages to GitHub releases (latest)
278+ if : github.ref == 'refs/heads/master' || github.ref == 'refs/heads/ci-publish-packages-to-releases'
279+ env :
280+ GH_TOKEN : ${{ github.token }}
281+ IMAGE_NAME : ${{ matrix.image }}
282+ run : |
283+ curl -sL "$(curl -sL "https://api.github.com/repos/cli/cli/releases" | grep _linux_amd64.tar.gz | grep https | head -n1 | cut -d'"' -f4)" -o gh.tar.gz \
284+ && tar xzf gh.tar.gz \
285+ && find gh*/ -name gh -exec mv {} /usr/local/bin/ \;
286+ git config --global --add safe.directory "$PWD" \
287+ && git tag -f ci-latest HEAD \
288+ && git push -f origin tag ci-latest
289+ find build/ -iname '*.rpm' | while read -r f; do
290+ newf="$IMAGE_NAME-$(basename "$f")"
291+ mv "$f" "$newf"
292+ gh release upload --clobber ci-latest "$newf"
293+ done
294+
295+ - name : Publish RPM packages to GitHub releases (stable)
296+ if : github.ref == 'refs/heads/ci-release'
297+ env :
298+ GH_TOKEN : ${{ github.token }}
299+ IMAGE_NAME : ${{ matrix.image }}
300+ run : |
301+ curl -sL "$(curl -sL "https://api.github.com/repos/cli/cli/releases" | grep _linux_amd64.tar.gz | grep https | head -n1 | cut -d'"' -f4)" -o gh.tar.gz \
302+ && tar xzf gh.tar.gz \
303+ && find gh*/ -name gh -exec mv {} /usr/local/bin/ \;
304+ latest_tag="$(git describe --exact-match --tags)"
305+ if ! gh release view "$latest_tag"; then
306+ echo "could not find release for tag $latest_tag"
307+ exit 1
308+ fi
309+ find build/ -iname '*.rpm' | while read -r f; do
310+ newf="$IMAGE_NAME-$(basename "$f")"
311+ mv "$f" "$newf"
312+ gh release upload --clobber "$latest_tag" "$newf"
313+ done
0 commit comments