Skip to content

Commit 41658ac

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

File tree

3 files changed

+110
-0
lines changed

3 files changed

+110
-0
lines changed

.github/workflows/packages.yml

Lines changed: 90 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,28 @@ 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+
TAG_NAME="$latest_tag" ./.github/workflows/scripts/upload-packages.sh
129+
85130
rpm:
86131
# Try to build RPM packages
87132
runs-on: ubuntu-latest
@@ -155,6 +200,29 @@ jobs:
155200
# Checkout repository --------------------------------------------------------------------
156201
- uses: actions/checkout@v2
157202

203+
# Fix repository permissions
204+
- name: Fix repository permissions
205+
run: git config --global --add safe.directory "$PWD"
206+
207+
# Install GitHub CLI
208+
- name: Install GitHub CLI
209+
run: .github/workflows/scripts/install-gh-cli.sh
210+
211+
# Checkout release tag (if on release branch)
212+
- name: Checkout release tag (if on release branch)
213+
if: github.ref == 'refs/heads/ci-release'
214+
env:
215+
GH_TOKEN: ${{ github.token }}
216+
IMAGE_NAME: ${{ matrix.image }}
217+
run: |
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+
158226
# Build LIBFDS RPM package ---------------------------------------------------------------
159227
- name: Checkout libfds library
160228
run: git clone --branch master https://github.com/CESNET/libfds.git build/libfds_repo
@@ -201,3 +269,25 @@ jobs:
201269
path: |
202270
build/pkg/rpm/rpmbuild/RPMS/
203271
build/pkg/rpm/rpmbuild/SRPMS/
272+
273+
- name: Publish RPM packages to GitHub releases (latest)
274+
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/ci-publish-packages-to-releases'
275+
env:
276+
GH_TOKEN: ${{ github.token }}
277+
IMAGE_NAME: ${{ matrix.image }}
278+
run: |
279+
git tag -f ci-latest HEAD && git push -f origin tag ci-latest
280+
TAG_NAME="ci-latest" ./.github/workflows/scripts/upload-packages.sh
281+
282+
- name: Publish RPM packages to GitHub releases (stable)
283+
if: github.ref == 'refs/heads/ci-release'
284+
env:
285+
GH_TOKEN: ${{ github.token }}
286+
IMAGE_NAME: ${{ matrix.image }}
287+
run: |
288+
latest_tag="$(git describe --exact-match --tags)"
289+
if ! gh release view "$latest_tag"; then
290+
echo "could not find release for tag $latest_tag"
291+
exit 1
292+
fi
293+
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 ci-latest "$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)