mirror of
https://github.com/pavel-odintsov/fastnetmon
synced 2026-09-08 05:14:12 +02:00
342 lines
9.5 KiB
YAML
342 lines
9.5 KiB
YAML
name: Buld snap package
|
|
|
|
on:
|
|
pull_request:
|
|
push:
|
|
branches:
|
|
- "**"
|
|
tags:
|
|
- "v*"
|
|
workflow_dispatch:
|
|
|
|
|
|
permissions:
|
|
contents: read
|
|
actions: write
|
|
|
|
jobs:
|
|
prepare_metadata:
|
|
name: Prepare package metadata
|
|
runs-on: ubuntu-24.04
|
|
outputs:
|
|
fnm_version: ${{ steps.meta.outputs.fnm_version }}
|
|
fnm_grade: ${{ steps.meta.outputs.fnm_grade }}
|
|
fnm_channel: ${{ steps.meta.outputs.fnm_channel }}
|
|
fnm_publishable: ${{ steps.meta.outputs.fnm_publishable }}
|
|
steps:
|
|
- name: Calculate package metadata
|
|
id: meta
|
|
env:
|
|
REF_TYPE: ${{ github.ref_type }}
|
|
REF_NAME: ${{ github.ref_name }}
|
|
FULL_REF: ${{ github.ref }}
|
|
SHA: ${{ github.sha }}
|
|
run: |
|
|
set -eux
|
|
|
|
SHORT_SHA="${SHA:0:7}"
|
|
BASE_VERSION="1.2.9"
|
|
|
|
if [ "$REF_TYPE" = "tag" ] &&
|
|
echo "$REF_NAME" | grep -Eq '^v[0-9]'; then
|
|
FNM_VERSION="${REF_NAME#v}"
|
|
FNM_GRADE="stable"
|
|
FNM_CHANNEL="candidate"
|
|
FNM_PUBLISHABLE="true"
|
|
elif [ "$FULL_REF" = "refs/heads/master" ]; then
|
|
FNM_VERSION="${BASE_VERSION}-dev.${SHORT_SHA}"
|
|
FNM_GRADE="devel"
|
|
FNM_CHANNEL="edge"
|
|
FNM_PUBLISHABLE="true"
|
|
else
|
|
FNM_VERSION="${BASE_VERSION}-dev.${SHORT_SHA}"
|
|
FNM_GRADE="devel"
|
|
FNM_CHANNEL=""
|
|
FNM_PUBLISHABLE="false"
|
|
fi
|
|
|
|
echo "Version: $FNM_VERSION"
|
|
echo "Grade: $FNM_GRADE"
|
|
echo "Channel: $FNM_CHANNEL"
|
|
echo "Publishable: $FNM_PUBLISHABLE"
|
|
|
|
echo "fnm_version=$FNM_VERSION" >> "$GITHUB_OUTPUT"
|
|
echo "fnm_grade=$FNM_GRADE" >> "$GITHUB_OUTPUT"
|
|
echo "fnm_channel=$FNM_CHANNEL" >> "$GITHUB_OUTPUT"
|
|
echo "fnm_publishable=$FNM_PUBLISHABLE" >> "$GITHUB_OUTPUT"
|
|
|
|
|
|
build_snap:
|
|
name: Build snap ${{ matrix.architecture }}
|
|
needs:
|
|
- prepare_metadata
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
include:
|
|
- architecture: amd64
|
|
runner: ubuntu-24.04
|
|
- architecture: arm64
|
|
runner: ubuntu-24.04-arm
|
|
runs-on: ${{ matrix.runner}}
|
|
defaults:
|
|
run:
|
|
working-directory: ./src
|
|
steps:
|
|
- name: Checkout source
|
|
uses: actions/checkout@v6
|
|
|
|
- name: Install build tools
|
|
run: |
|
|
sudo snap install yq
|
|
sudo snap install snapcraft --classic
|
|
snapcraft version
|
|
yq --version
|
|
dpkg --print-architecture
|
|
# Not needed, since switched to snapcraft pack with --destructive-mode flag
|
|
# sudo snap install lxd
|
|
# sudo lxd init --auto
|
|
# sudo usermod -aG lxd "$USER"
|
|
# snapcraft don't like our src/packaging path
|
|
- name: Create symlink to snap
|
|
run: ln -s packaging/snap snap
|
|
- name: Prepare snapcraft.yaml
|
|
id: meta
|
|
env:
|
|
FNM_VERSION: ${{ needs.prepare_metadata.outputs.fnm_version }}
|
|
FNM_GRADE: ${{ needs.prepare_metadata.outputs.fnm_grade }}
|
|
run: |
|
|
set -eux
|
|
|
|
SNAPCRAFT_FILE="snap/snapcraft.yaml"
|
|
export FNM_VERSION
|
|
export FNM_GRADE
|
|
|
|
echo "Update $SNAPCRAFT_FILE"
|
|
yq -i '
|
|
.version = strenv(FNM_VERSION) |
|
|
.grade = strenv(FNM_GRADE)
|
|
' "$SNAPCRAFT_FILE"
|
|
|
|
echo "Check new version and grade in $SNAPCRAFT_FILE"
|
|
test "$(yq -r '.version' "$SNAPCRAFT_FILE")" = "$FNM_VERSION"
|
|
test "$(yq -r '.grade' "$SNAPCRAFT_FILE")" = "$FNM_GRADE"
|
|
|
|
echo "\n\n OUR $SNAPCRAFT_FILE:"
|
|
cat "$SNAPCRAFT_FILE"
|
|
|
|
- name: Build snap
|
|
env:
|
|
FNM_ARCHITECTURE: ${{ matrix.architecture }}
|
|
run: |
|
|
set -eux
|
|
|
|
#sg lxd -c 'snapcraft pack'
|
|
sudo snapcraft pack --destructive-mode --platform "$FNM_ARCHITECTURE"
|
|
|
|
FNM_SNAP_PATH="$(
|
|
find "$PWD" \
|
|
-maxdepth 1 \
|
|
-type f \
|
|
-name "fastnetmon-community_*_${FNM_ARCHITECTURE}.snap" \
|
|
-print \
|
|
-quit
|
|
)"
|
|
|
|
test -n "$FNM_SNAP_PATH"
|
|
test -f "$FNM_SNAP_PATH"
|
|
|
|
sudo chown "$USER:$USER" "$FNM_SNAP_PATH"
|
|
|
|
echo "FNM_SNAP_PATH=$FNM_SNAP_PATH" >> "$GITHUB_ENV"
|
|
|
|
ls -lah "$FNM_SNAP_PATH"
|
|
|
|
- name: Upload temporary snap artifact
|
|
id: upload
|
|
uses: actions/upload-artifact@v6
|
|
with:
|
|
name: fastnetmon-community-snap-${{ matrix.architecture }}
|
|
path: ${{ env.FNM_SNAP_PATH }}
|
|
if-no-files-found: error
|
|
retention-days: 1
|
|
|
|
test_snap:
|
|
name: Test snap ${{ matrix.architecture }}
|
|
needs:
|
|
- prepare_metadata
|
|
- build_snap
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
include:
|
|
- architecture: amd64
|
|
runner: ubuntu-24.04
|
|
- architecture: arm64
|
|
runner: ubuntu-24.04-arm
|
|
runs-on: ${{ matrix.runner }}
|
|
steps:
|
|
- name: Download snap artifact
|
|
uses: actions/download-artifact@v6
|
|
with:
|
|
name: fastnetmon-community-snap-${{ matrix.architecture }}
|
|
path: ./artifact
|
|
|
|
- name: Locate downloaded snap
|
|
env:
|
|
FNM_ARCHITECTURE: ${{ matrix.architecture }}
|
|
run: |
|
|
set -eux
|
|
|
|
FNM_SNAP_PATH="$(
|
|
find "$PWD/artifact" \
|
|
-maxdepth 1 \
|
|
-type f \
|
|
-name "fastnetmon-community_*_${FNM_ARCHITECTURE}.snap" \
|
|
-print \
|
|
-quit
|
|
)"
|
|
|
|
test -n "$FNM_SNAP_PATH"
|
|
test -f "$FNM_SNAP_PATH"
|
|
|
|
echo "FNM_SNAP_PATH=$FNM_SNAP_PATH" >> "$GITHUB_ENV"
|
|
|
|
ls -lah "$FNM_SNAP_PATH"
|
|
|
|
- name: Install tools
|
|
run: |
|
|
sudo snap install snapcraft --classic
|
|
- name: Install local snap
|
|
run: |
|
|
sudo snap install "$FNM_SNAP_PATH" --dangerous
|
|
|
|
- name: Smoke test
|
|
run: |
|
|
echo "snap list fastnetmon-community"
|
|
snap list fastnetmon-community
|
|
echo -e "\nsnap info fastnetmon-community"
|
|
snap info fastnetmon-community
|
|
|
|
echo -e "\n\nfastnetmon --version"
|
|
fastnetmon-community.fastnetmon --version
|
|
echo -e "fastnetmon --configuration_check"
|
|
sudo fastnetmon-community.fastnetmon \
|
|
--configuration_check \
|
|
--configuration_file /var/snap/fastnetmon-community/common/etc/fastnetmon.conf \
|
|
--log_to_console
|
|
|
|
echo -e "\n\nfastnetmon-client --help"
|
|
fastnetmon-community.fastnetmon-client --help || true
|
|
echo -e "fastnetmon-api-client --help"
|
|
fastnetmon-community.fastnetmon-api-client --help || true
|
|
|
|
echo -e "\n\nsnap services fastnetmon-community"
|
|
snap services fastnetmon-community
|
|
|
|
- name: Check runtime libraries
|
|
run: |
|
|
set -eux
|
|
|
|
sudo snap run --shell fastnetmon-community.fastnetmon -c '
|
|
set -eu
|
|
|
|
ldd "$SNAP/usr/sbin/fastnetmon" | tee /tmp/ldd-fastnetmon.txt
|
|
|
|
if grep "not found" /tmp/ldd-fastnetmon.txt; then
|
|
echo "Some runtime libraries for fastnetmon are missing" >&2
|
|
exit 1
|
|
fi
|
|
|
|
ldd "$SNAP/usr/bin/fastnetmon_client" | tee /tmp/ldd-fastnetmon_client.txt
|
|
|
|
if grep "not found" /tmp/ldd-fastnetmon_client.txt; then
|
|
echo "Some runtime libraries for fastnetmon_client are missing" >&2
|
|
exit 1
|
|
fi
|
|
'
|
|
|
|
publish_snap:
|
|
name: Publish snaps
|
|
needs:
|
|
- prepare_metadata
|
|
- build_snap
|
|
- test_snap
|
|
|
|
if: needs.prepare_metadata.outputs.fnm_publishable == 'true'
|
|
runs-on: ubuntu-24.04
|
|
steps:
|
|
- name: Download all snap artifacts
|
|
uses: actions/download-artifact@v6
|
|
with:
|
|
pattern: fastnetmon-community-snap-*
|
|
path: ./artifacts
|
|
merge-multiple: true
|
|
|
|
- name: Check downloaded snaps
|
|
run: |
|
|
set -eux
|
|
|
|
AMD64_SNAP="$(
|
|
find "$PWD/artifacts" \
|
|
-maxdepth 1 \
|
|
-type f \
|
|
-name 'fastnetmon-community_*_amd64.snap' \
|
|
-print \
|
|
-quit
|
|
)"
|
|
|
|
ARM64_SNAP="$(
|
|
find "$PWD/artifacts" \
|
|
-maxdepth 1 \
|
|
-type f \
|
|
-name 'fastnetmon-community_*_arm64.snap' \
|
|
-print \
|
|
-quit
|
|
)"
|
|
|
|
test -n "$AMD64_SNAP"
|
|
test -f "$AMD64_SNAP"
|
|
|
|
test -n "$ARM64_SNAP"
|
|
test -f "$ARM64_SNAP"
|
|
|
|
find "$PWD/artifacts" \
|
|
-maxdepth 1 \
|
|
-type f \
|
|
-name 'fastnetmon-community_*.snap' \
|
|
-exec ls -lah {} \;
|
|
|
|
- name: Install snapcraft
|
|
run: |
|
|
set -eux
|
|
|
|
sudo snap install snapcraft --classic
|
|
snapcraft version
|
|
|
|
- name: Upload snaps to Snap Store
|
|
env:
|
|
SNAPCRAFT_STORE_CREDENTIALS: ${{ secrets.SNAPCRAFT_STORE_CREDENTIALS }}
|
|
FNM_CHANNEL: ${{ needs.prepare_metadata.outputs.fnm_channel }}
|
|
run: |
|
|
set -eux
|
|
|
|
test -n "$SNAPCRAFT_STORE_CREDENTIALS"
|
|
test -n "$FNM_CHANNEL"
|
|
|
|
PACKAGE_COUNT=0
|
|
|
|
for package in "$PWD"/artifacts/fastnetmon-community_*.snap; do
|
|
test -f "$package"
|
|
|
|
echo "Uploading $package to channel $FNM_CHANNEL"
|
|
|
|
snapcraft upload \
|
|
"$package" \
|
|
--release="$FNM_CHANNEL"
|
|
|
|
PACKAGE_COUNT=$((PACKAGE_COUNT + 1))
|
|
done
|
|
|
|
test "$PACKAGE_COUNT" -eq 2
|