Skip to content

Update to v1.4.0

Update to v1.4.0 #12

name: Build/Pub Release
on:
push:
tags:
- '*'
permissions:
contents: write
packages: write
jobs:
linux-build:
name: Build (Linux)
runs-on: ubuntu-latest
container: ${{ matrix.container && fromJSON(format('{{"image":"{0}","options":"--user root"}}', matrix.container)) }}
strategy:
matrix:
include:
- build: linux-64-gnu
target: x86_64-unknown-linux-gnu
container: debian:buster
package-deb: yes
- build: linux-aarch64-gnu
target: aarch64-unknown-linux-gnu
container: debian:buster
package-deb: yes
- build: linux-i686-gnu
target: i686-unknown-linux-gnu
container: debian:buster
package-deb: yes
- build: linux-armv7-gnueabihf
target: armv7-unknown-linux-gnueabihf
container: debian:buster
package-deb: yes
- build: linux-64-musl
target: x86_64-unknown-linux-musl
container: ghcr.io/rust-cross/rust-musl-cross:x86_64-musl
package-deb: no
- build: linux-i686-musl
target: i686-unknown-linux-musl
container: ghcr.io/rust-cross/rust-musl-cross:i686-musl
package-deb: no
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Fix apt sources (for EOL Debian)
if: matrix.container == 'debian:buster'
run: |
sed -i 's|deb.debian.org|archive.debian.org|g' /etc/apt/sources.list
sed -i 's|security.debian.org|archive.debian.org|g' /etc/apt/sources.list
echo 'Acquire::Check-Valid-Until "false";' > /etc/apt/apt.conf.d/99no-check-valid
- name: Install system dependencies
run: |
apt-get update
apt-get install -y curl ca-certificates build-essential pkg-config libssl-dev git
- name: Install Rust
if : matrix.build != 'linux-64-musl' && matrix.build != 'linux-i686-musl'
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Install linux needed deps
shell: bash
run: |
if [ "${{ matrix.build }}" = "linux-aarch64-gnu" ]; then
apt-get install -y gcc-aarch64-linux-gnu
elif [ "${{ matrix.build }}" = "linux-i686-gnu" ]; then
apt-get install -y gcc-multilib
elif [ "${{ matrix.build }}" = "linux-armv7-gnueabihf" ]; then
apt-get install -y gcc-arm-linux-gnueabihf
fi
- name: Running cargo build
shell: bash
run: |
if [ "${{ matrix.package-deb }}" = "yes" ]; then
cargo install cargo-deb
cargo deb -v --output=target/debian/librespeed-rs-${{ matrix.target }}.deb --target=${{ matrix.target }}
else
cargo build --release --target ${{ matrix.target }}
fi
- name: Make artifact folder
shell: bash
run: |
binary_name="librespeed-rs"
dirname="$binary_name-${{ matrix.target }}"
mkdir "$dirname"
mv "target/${{ matrix.target }}/release/$binary_name" "$dirname"
if [ "${{ matrix.package-deb }}" = "yes" ]; then
deb_dirname="deb-$dirname"
mkdir "$deb_dirname"
mv "target/debian/librespeed-rs-${{ matrix.target }}.deb" "$deb_dirname"
fi
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
overwrite: true
name: librespeed-rs-${{ matrix.target }}
path: librespeed-rs-${{ matrix.target }}
- name: Upload deb artifacts
if: matrix.package-deb == 'yes'
uses: actions/upload-artifact@v4
with:
overwrite: true
name: deb-librespeed-rs-${{ matrix.target }}
path: deb-librespeed-rs-${{ matrix.target }}
other-build:
name: Build (Windows + macOS)
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: windows-latest
target: i686-pc-windows-msvc
- os: windows-latest
target: x86_64-pc-windows-msvc
- os: macos-latest
target: x86_64-apple-darwin
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- run: cargo build --release --target ${{ matrix.target }}
- name: Make artifact
shell: bash
run: |
name="librespeed-rs"
dir="${name}-${{ matrix.target }}"
mkdir "$dir"
if [ "${{ matrix.os }}" = "windows-latest" ]; then
mv "target/${{ matrix.target }}/release/$name.exe" "$dir/"
else
mv "target/${{ matrix.target }}/release/$name" "$dir/"
fi
- uses: actions/upload-artifact@v4
with:
overwrite: true
name: librespeed-rs-${{ matrix.target }}
path: librespeed-rs-${{ matrix.target }}
container-build-push:
name: Build and push Container image
runs-on: ubuntu-latest
needs: [linux-build, other-build]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Download artifacts
uses: actions/download-artifact@v4
- name: Create the Containerfile
run: |
# Create a Containerfile dynamically to ensure all elements are correctly included
cat <<EOF > Containerfile
FROM debian:12-slim
WORKDIR /usr/local/bin
# Use the Docker TARGETPLATFORM to pass in the platform being built
ARG TARGETPLATFORM
RUN mkdir -p binary
COPY configs.toml configs.toml
COPY assets assets
COPY librespeed-rs-x86_64-unknown-linux-gnu binary/librespeed-rs-x86_64-unknown-linux-gnu
COPY librespeed-rs-aarch64-unknown-linux-gnu binary/librespeed-rs-aarch64-unknown-linux-gnu
COPY librespeed-rs-armv7-unknown-linux-gnueabihf binary/librespeed-rs-armv7-unknown-linux-gnueabihf
# Match the correct binary based on the platform
RUN if [ "\$TARGETPLATFORM" = "linux/amd64" ]; then \
cp binary/librespeed-rs-x86_64-unknown-linux-gnu/librespeed-rs librespeed-rs; \
elif [ "\$TARGETPLATFORM" = "linux/arm64" ]; then \
cp binary/librespeed-rs-aarch64-unknown-linux-gnu/librespeed-rs librespeed-rs; \
elif [ "\$TARGETPLATFORM" = "linux/arm/v7" ]; then \
cp binary/librespeed-rs-armv7-unknown-linux-gnueabihf/librespeed-rs librespeed-rs; \
else \
echo "Unsupported platform: \$TARGETPLATFORM" && exit 1; \
fi
RUN rm -rf binary/; chmod +x librespeed-rs;
EXPOSE 8080
ENTRYPOINT ["librespeed-rs"]
EOF
- name: Build container image
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ghcr.io/${{ github.repository }}:latest,ghcr.io/${{ github.repository }}:${{ github.ref_name }}
file: ./Containerfile
platforms: linux/amd64,linux/arm64,linux/arm/v7
release:
needs: [linux-build, other-build]
name: Publish release
runs-on: ubuntu-latest
steps:
- name: Download changelog file(s)
uses: actions/checkout@v4
with:
sparse-checkout: .
- name: Download artifacts
uses: actions/download-artifact@v4
- name: Move deb files & clear deb folders
shell: bash
run: |
for dir in */; do
if [[ "$dir" == deb-* ]]; then
mv "$dir"* .
rm -rf "$dir"
fi
done
- name: Copy files & build archives
shell: bash
run: |
for dir in */; do
if [ -d "$dir" ]; then
dir_name="${dir%/}"
cp "configs.toml" "LICENSE.txt" "country_asn.mmdb" "$dir_name"
tar -cJf "${dir_name}.tar.xz" -C "$dir_name" .
echo "Compressed ${dir_name}.tar.xz"
fi
done
- name: Generate checksums
shell: bash
run: |
md5sum_file() {
local file=$1
local checksum=$(md5sum "$file" | awk '{print $1}')
local filename=$(basename "$file")
echo "$checksum : $filename" >> checksums.txt
}
rm -f checksums.txt
find . -type f -name '*.xz' -or -name '*.zip' -or -name '*.deb' | while read file; do
md5sum_file "$file"
done
- name: Extract release notes
run: |
awk -v ver="${{ github.ref_name }}" '/^## Version / { if (p) { exit }; if ($3 == ver) { p=1; next } } p && NF' "CHANGELOG.md" > RELEASE_NOTE.txt
- name: Release
uses: softprops/action-gh-release@v2
with:
name: Release ${{ github.ref_name }}
body_path: RELEASE_NOTE.txt
files: |
*.zip
*.xz
*.deb
checksums.txt