Skip to content

Commit 03aac93

Browse files
committed
ci - upload built packages to github release
1 parent 3064dc5 commit 03aac93

File tree

3 files changed

+112
-0
lines changed

3 files changed

+112
-0
lines changed

.github/workflows/packages.yml

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,29 @@ jobs:
4848
# Checkout repository --------------------------------------------------------------------
4949
- uses: actions/checkout@v2
5050

51+
# Fix repository permissions
52+
- name: Fix repository permissions
53+
run: git config --global --add safe.directory "$PWD"
54+
55+
# Install GitHub CLI
56+
- name: Install GitHub CLI
57+
run: .github/workflows/scripts/install-gh-cli.sh
58+
59+
# Checkout release tag (if on release branch)
60+
- name: Checkout release tag (if on release branch)
61+
if: github.ref == 'refs/heads/ci-release'
62+
env:
63+
GH_TOKEN: ${{ github.token }}
64+
IMAGE_NAME: ${{ matrix.image }}
65+
run: |
66+
git fetch --tags
67+
latest_tag="$(git tag | grep 'v[0-9]*\.[0-9]*\.[0-9]*' | sort -rn | head -n1)"
68+
if [ -z "$latest_tag" ]; then
69+
echo "could not find latest tag"
70+
exit 1
71+
fi
72+
git checkout "$latest_tag"
73+
5174
# Build LIBFDS DEB package ---------------------------------------------------------------
5275
- name: Checkout libfds library
5376
run: git clone https://github.com/CESNET/libfds.git build/libfds_repo
@@ -82,6 +105,29 @@ jobs:
82105
build/pkg/deb/debbuild/*.tar.gz
83106
build/pkg/deb/debbuild/*.dsc
84107
108+
- name: Publish DEB packages to GitHub releases (latest)
109+
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/ci-publish-packages-to-releases'
110+
env:
111+
GH_TOKEN: ${{ github.token }}
112+
IMAGE_NAME: ${{ matrix.image }}
113+
run: |
114+
git tag -f ci-latest HEAD && git push -f origin tag ci-latest
115+
TAG_NAME="ci-latest" ./.github/workflows/scripts/upload-packages.sh
116+
117+
- name: Publish DEB packages to GitHub releases (stable)
118+
if: github.ref == 'refs/heads/ci-release'
119+
env:
120+
GH_TOKEN: ${{ github.token }}
121+
IMAGE_NAME: ${{ matrix.image }}
122+
run: |
123+
latest_tag="$(git describe --exact-match --tags)"
124+
if ! gh release view "$latest_tag"; then
125+
echo "could not find release for tag $latest_tag"
126+
exit 1
127+
fi
128+
git checkout ci-release
129+
TAG_NAME="$latest_tag" ./.github/workflows/scripts/upload-packages.sh
130+
85131
rpm:
86132
# Try to build RPM packages
87133
runs-on: ubuntu-latest
@@ -155,6 +201,29 @@ jobs:
155201
# Checkout repository --------------------------------------------------------------------
156202
- uses: actions/checkout@v2
157203

204+
# Fix repository permissions
205+
- name: Fix repository permissions
206+
run: git config --global --add safe.directory "$PWD"
207+
208+
# Install GitHub CLI
209+
- name: Install GitHub CLI
210+
run: .github/workflows/scripts/install-gh-cli.sh
211+
212+
# Checkout release tag (if on release branch)
213+
- name: Checkout release tag (if on release branch)
214+
if: github.ref == 'refs/heads/ci-release'
215+
env:
216+
GH_TOKEN: ${{ github.token }}
217+
IMAGE_NAME: ${{ matrix.image }}
218+
run: |
219+
git fetch --tags
220+
latest_tag="$(git tag | grep 'v[0-9]*\.[0-9]*\.[0-9]*' | sort -rn | head -n1)"
221+
if [ -z "$latest_tag" ]; then
222+
echo "could not find latest tag"
223+
exit 1
224+
fi
225+
git checkout "$latest_tag"
226+
158227
# Build LIBFDS RPM package ---------------------------------------------------------------
159228
- name: Checkout libfds library
160229
run: git clone --branch master https://github.com/CESNET/libfds.git build/libfds_repo
@@ -201,3 +270,26 @@ jobs:
201270
path: |
202271
build/pkg/rpm/rpmbuild/RPMS/
203272
build/pkg/rpm/rpmbuild/SRPMS/
273+
274+
- name: Publish RPM packages to GitHub releases (latest)
275+
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/ci-publish-packages-to-releases'
276+
env:
277+
GH_TOKEN: ${{ github.token }}
278+
IMAGE_NAME: ${{ matrix.image }}
279+
run: |
280+
git tag -f ci-latest HEAD && git push -f origin tag ci-latest
281+
TAG_NAME="ci-latest" ./.github/workflows/scripts/upload-packages.sh
282+
283+
- name: Publish RPM packages to GitHub releases (stable)
284+
if: github.ref == 'refs/heads/ci-release'
285+
env:
286+
GH_TOKEN: ${{ github.token }}
287+
IMAGE_NAME: ${{ matrix.image }}
288+
run: |
289+
latest_tag="$(git describe --exact-match --tags)"
290+
if ! gh release view "$latest_tag"; then
291+
echo "could not find release for tag $latest_tag"
292+
exit 1
293+
fi
294+
git checkout ci-release
295+
TAG_NAME="$latest_tag" ./.github/workflows/scripts/upload-packages.sh
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
set -eu
3+
cd "$(mktemp -d)"
4+
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
5+
tar xzf gh.tar.gz
6+
find gh*/ -name gh -exec mv {} /usr/local/bin/ \;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
set -eu
3+
IFS=$'\n'
4+
set +e; assets="$(gh release view "$TAG_NAME" | grep '^asset:' | cut -f2 | grep -F "${IMAGE_NAME//:/.}")"; set -e
5+
files="$(find build/ \( -iname '*.rpm' -or -iname '*.deb' \) )"
6+
for f in $files; do
7+
newf="$IMAGE_NAME-$(basename "$f")"
8+
mv "$f" "$newf"
9+
gh release upload --clobber "$TAG_NAME" "$newf"
10+
set +e; assets="$(grep -vF "${newf//:/.}" <<<"$assets")"; set -e
11+
done
12+
for asset in $assets; do
13+
gh release delete-asset "$TAG_NAME" "$asset"
14+
done

0 commit comments

Comments
 (0)