Skip to content

Commit 4d1015c

Browse files
committed
...
1 parent 1ee75db commit 4d1015c

File tree

3 files changed

+44
-54
lines changed

3 files changed

+44
-54
lines changed

.github/workflows/packages.yml

Lines changed: 24 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,15 @@ jobs:
4646
DEBIAN_FRONTEND: noninteractive
4747

4848
# Checkout repository --------------------------------------------------------------------
49-
- uses: actions/checkout@v2
49+
- uses: actions/checkout@v4
50+
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
5058

5159
# Checkout release tag (if on release branch)
5260
- name: Checkout release tag (if on release branch)
@@ -55,7 +63,6 @@ jobs:
5563
GH_TOKEN: ${{ github.token }}
5664
IMAGE_NAME: ${{ matrix.image }}
5765
run: |
58-
git config --global --add safe.directory "$PWD"
5966
git fetch --tags
6067
latest_tag="$(git tag | grep 'v[0-9]*\.[0-9]*\.[0-9]*' | sort -rn | head -n1)"
6168
if [ -z "$latest_tag" ]; then
@@ -108,37 +115,21 @@ jobs:
108115
GH_TOKEN: ${{ github.token }}
109116
IMAGE_NAME: ${{ matrix.image }}
110117
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
118+
git tag -f ci-latest HEAD && git push -f origin tag ci-latest
119+
TAG_NAME="ci-latest" ./.github/workflows/scripts/upload-packages.sh
122120
123121
- name: Publish DEB packages to GitHub releases (stable)
124122
if: github.ref == 'refs/heads/ci-release'
125123
env:
126124
GH_TOKEN: ${{ github.token }}
127125
IMAGE_NAME: ${{ matrix.image }}
128126
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/ \;
132127
latest_tag="$(git describe --exact-match --tags)"
133128
if ! gh release view "$latest_tag"; then
134129
echo "could not find release for tag $latest_tag"
135130
exit 1
136131
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
132+
TAG_NAME="$latest_tag" ./.github/workflows/scripts/upload-packages.sh
142133
143134
rpm:
144135
# Try to build RPM packages
@@ -211,7 +202,15 @@ jobs:
211202
yum -y install rpmdevtools
212203
213204
# Checkout repository --------------------------------------------------------------------
214-
- uses: actions/checkout@v2
205+
- uses: actions/checkout@v4
206+
207+
# Fix repository permissions
208+
- name: Fix repository permissions
209+
run: git config --global --add safe.directory "$PWD"
210+
211+
# Install GitHub CLI
212+
- name: Install GitHub CLI
213+
run: .github/workflows/scripts/install-gh-cli.sh
215214

216215
# Checkout release tag (if on release branch)
217216
- name: Checkout release tag (if on release branch)
@@ -286,47 +285,18 @@ jobs:
286285
GH_TOKEN: ${{ github.token }}
287286
IMAGE_NAME: ${{ matrix.image }}
288287
run: |
289-
set -x
290-
291-
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 \
292-
&& tar xzf gh.tar.gz \
293-
&& find gh*/ -name gh -exec mv {} /usr/local/bin/ \;
294-
295-
git config --global --add safe.directory "$PWD"
296-
git tag -f ci-latest HEAD
297-
git push -f origin tag ci-latest
298-
299-
IFS=$'\n'
300-
set +e; assets="$(gh release view ci-latest | grep '^asset:' | cut -f2 | grep -F "${IMAGE_NAME//:/.}")"; set -e
301-
files="$(find build/ -iname '*.rpm')"
302-
for f in $files; do
303-
newf="$IMAGE_NAME-$(basename "$f")"
304-
mv "$f" "$newf"
305-
gh release upload --clobber ci-latest "$newf"
306-
set +e; assets="$(grep -vF "${newf//:/.}" <<<"$assets")"; set -e
307-
done
308-
309-
for asset in $assets; do
310-
gh release delete-asset ci-latest "$asset"
311-
done
288+
git tag -f ci-latest HEAD && git push -f origin tag ci-latest
289+
TAG_NAME="ci-latest" ./.github/workflows/scripts/upload-packages.sh
312290
313291
- name: Publish RPM packages to GitHub releases (stable)
314292
if: github.ref == 'refs/heads/ci-release'
315293
env:
316294
GH_TOKEN: ${{ github.token }}
317295
IMAGE_NAME: ${{ matrix.image }}
318296
run: |
319-
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 \
320-
&& tar xzf gh.tar.gz \
321-
&& find gh*/ -name gh -exec mv {} /usr/local/bin/ \;
322297
latest_tag="$(git describe --exact-match --tags)"
323298
if ! gh release view "$latest_tag"; then
324299
echo "could not find release for tag $latest_tag"
325300
exit 1
326301
fi
327-
328-
find build/ -iname '*.rpm' | while read -r f; do
329-
newf="$IMAGE_NAME-$(basename "$f")"
330-
mv "$f" "$newf"
331-
gh release upload --clobber "$latest_tag" "$newf"
332-
done
302+
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)