Files
rust-socksd/.github/workflows/release.yml
T

239 lines
9.5 KiB
YAML

name: Create Release and Publish Assets
on:
push:
tags:
- 'v*.*.*' # Trigger on version tags like v1.0.0, v1.2.3, etc.
jobs:
create_gh_release:
name: Create GitHub Release
runs-on: ubuntu-latest
permissions:
contents: write # Required to create releases and upload assets
outputs:
pkg_name: ${{ steps.get_version.outputs.pkg_name }}
version: ${{ steps.get_version.outputs.version }}
tag_name: ${{ github.ref_name }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Get version from tag
id: get_version
# Example: v1.0.0 -> 1.0.0
run: |
export PKG_NAME=$(grep -A 10 '\[package\]' Cargo.toml | grep '^name *=' | sed 's/name *= *"\(.*\)"/\1/')
echo "pkg_name=${PKG_NAME}" >> $GITHUB_OUTPUT
echo "version=${GITHUB_REF_NAME#v}" >> $GITHUB_OUTPUT
- name: Create GitHub Release
id: create_release_step
env:
PKG_NAME: ${{ steps.get_version.outputs.pkg_name }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERSION: ${{ steps.get_version.outputs.version }}
run: |
gh release create ${{ github.ref_name }} \
--title "Release ${{ github.ref_name }}" \
--notes "Automated release for ${{ env.PKG_NAME }} version ${{ env.VERSION }}.
See CHANGELOG.md for details (if available).
Assets will be uploaded by subsequent jobs." \
--draft=false \
--prerelease=false
build_and_upload_source_archive:
name: Build and Upload Source Archive
runs-on: ubuntu-latest
needs: create_gh_release
permissions:
contents: write # Required to upload assets (read permission is implicit for checkout)
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Required by git archive to correctly use the tag
- name: Create source archive
id: create_source_archive
env:
PKG_NAME: ${{ needs.create_gh_release.outputs.pkg_name }}
VERSION: ${{ needs.create_gh_release.outputs.version }}
TAG_NAME: ${{ needs.create_gh_release.outputs.tag_name }}
run: |
ARCHIVE_NAME="${{ env.PKG_NAME }}-${VERSION}.tar.gz"
# Create archive from the tagged commit, ensuring it extracts to a versioned directory
git archive --format=tar.gz --prefix="${{ env.PKG_NAME }}-${VERSION}/" -o "${ARCHIVE_NAME}" "${TAG_NAME}"
echo "archive_path=${PWD}/${ARCHIVE_NAME}" >> $GITHUB_OUTPUT
echo "Created archive: ${ARCHIVE_NAME}"
if [ -z "${PWD}/${ARCHIVE_NAME}" ]; then
echo "::error::Archive path is empty. Check if the archive was created successfully."
exit 1
fi
ls -lh "${ARCHIVE_NAME}"
exit 0
- name: Upload source archive to release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ARCHIVE_PATH: ${{ steps.create_source_archive.outputs.archive_path }}
run: |
gh release upload ${{ needs.create_gh_release.outputs.tag_name }} "${{ env.ARCHIVE_PATH }}"
build_debian_packages:
name: Build Debian Package (${{ matrix.arch }})
runs-on: ubuntu-latest
needs: create_gh_release
permissions:
contents: write # Required to upload assets (read permission is implicit for checkout)
strategy:
fail-fast: false # Allow other matrix jobs to continue if one fails
matrix:
include:
- target: x86_64-unknown-linux-gnu
arch: amd64
# No specific linker needed for amd64 on amd64 runner
- target: aarch64-unknown-linux-gnu
arch: arm64
linker: aarch64-linux-gnu-gcc
rustflags: '["-C", "target-feature=+crt-static"]'
- target: armv7-unknown-linux-gnueabihf
arch: armhf
linker: '/opt/rpi_tools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc'
rustflags: '["-C", "target-feature=+crt-static"]'
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up QEMU (for ARM builds)
if: matrix.arch == 'arm64' || matrix.arch == 'armhf'
uses: docker/setup-qemu-action@v3
with:
platforms: ${{ matrix.arch == 'arm64' && 'arm64' || matrix.arch == 'armhf' && 'arm' || '' }}
- name: Install Rust toolchain for target ${{ matrix.target }}
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Install compilation dependencies (for amd64)
if: matrix.arch == 'amd64'
run: |
sudo apt-get update -qq
sudo apt-get install -y --no-install-recommends debhelper-compat rustup
rustup -q update
- name: Install cross-compilation dependencies (for ARMhf)
if: matrix.arch == 'armhf'
run: |
sudo apt-get update -qq
sudo apt-get install -y --no-install-recommends debhelper-compat rustup gcc-arm-linux-gnueabihf libc6-dev-armhf-cross pkg-config
mkdir -p /opt
# Download and extract Raspberry Pi cross-compilation tools
git clone https://github.com/raspberrypi/tools /opt/rpi_tools
rustup target add ${{ matrix.target }}
rustup -q update
- name: Install cross-compilation dependencies (for ARM64)
if: matrix.arch == 'arm64'
run: |
sudo apt-get update -qq
sudo apt-get install -y --no-install-recommends debhelper-compat rustup gcc-aarch64-linux-gnu libc6-dev-arm64-cross pkg-config
rustup target add ${{ matrix.target }}
rustup -q update
- name: Build Debian package for ${{ matrix.arch }}
if: matrix.arch != 'armhf' && matrix.arch != 'arm64'
run: dpkg-buildpackage -b -d -uc -us --host-arch ${{ matrix.arch }}
- name: Build Debian package for armhf
if: matrix.arch == 'armhf'
env:
# Set target for cross-compilation
CARGO_BUILD_TARGET: ${{ matrix.target }}
# For armhf specifically, ensure we use the right target features
CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_LINKER: 'arm-linux-gnueabihf-gcc'
# PKG_CONFIG settings for cross-compilation
PKG_CONFIG_ALLOW_CROSS: 1
PKG_CONFIG_PATH: '/usr/lib/arm-linux-gnueabihf/pkgconfig'
run: dpkg-buildpackage -b -d -uc -us --host-arch ${{ matrix.arch }}
- name: Build Debian package for arm64
if: matrix.arch == 'arm64'
env:
# Set target for cross-compilation
CARGO_BUILD_TARGET: ${{ matrix.target }}
# For armhf specifically, ensure we use the right target features
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: 'aarch64-linux-gnu-gcc'
# PKG_CONFIG settings for cross-compilation
PKG_CONFIG_ALLOW_CROSS: 1
PKG_CONFIG_PATH: '/usr/lib/aarch64-linux-gnu/pkgconfig'
run: dpkg-buildpackage -b -d -uc -us --host-arch ${{ matrix.arch }}
- name: Get package name and path
id: package_info
env:
PKG_NAME: ${{ needs.build_and_upload_source_archive.outputs.pkg_name }}
run: |
DEB_PATH=$(find ../ -name "${{env.PKG_NAME}}_*_${{ matrix.arch }}.deb" -print -quit 2>/dev/null)
if [ -z "$DEB_PATH" ]; then
echo "::error::Could not find .deb package for ${{ matrix.arch }} matching '${{env.PKG_NAME}}_*_${{ matrix.arch }}.deb'"
echo "Listing contents of potential directories:"
ls -l ../ || echo "target/debian does not exist or is empty"
exit 1
fi
echo "Found deb package: $DEB_PATH"
echo "deb_path=${DEB_PATH}" >> $GITHUB_OUTPUT
ls -lh "$DEB_PATH"
- name: Upload Debian package to release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DEB_PATH: ${{ steps.package_info.outputs.deb_path }}
run: |
gh release upload ${{ needs.create_gh_release.outputs.tag_name }} "${{ env.DEB_PATH }}"
aur_publish:
name: "Publish Arch Linux source package to AUR"
permissions:
contents: read
needs:
- create_gh_release
- build_and_upload_source_archive
if: '!github.event.prerelease'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install dependencies
run: |
sudo apt-get update -qq
sudo apt-get install -y --no-install-recommends git gettext-base
- name: Generate PKGBUILD
env:
PKG_NAME: ${{ needs.create_gh_release.outputs.pkg_name }}
PKG_VERSION: ${{ needs.create_gh_release.outputs.version }}
TAG_NAME: ${{ needs.create_gh_release.outputs.tag_name }}
PKGBUILD_TEMPLATE_PATH: ./AUR/PKGBUILD.in
PKGBUILD_PATH: ./AUR/PKGBUILD
run: |
echo "Generating PKGBUILD at $PKGBUILD_PATH"
/usr/bin/envsubst '${PKG_NAME} ${PKG_VERSION}' < "$PKGBUILD_TEMPLATE_PATH" > "$PKGBUILD_PATH"
echo ""
cat "$PKGBUILD_PATH"
- name: Publish AUR package
uses: KSXGitHub/github-actions-deploy-aur@v4.1.1
with:
pkgname: ${{ needs.create_gh_release.outputs.pkg_name }}
pkgbuild: ./AUR/PKGBUILD
assets: |
./AUR/*.install
commit_username: ${{ secrets.AUR_USERNAME }}
commit_email: ${{ secrets.AUR_EMAIL }}
ssh_private_key: ${{ secrets.AUR_SSH_PRIVATE_KEY }}
commit_message: Update AUR package
ssh_keyscan_types: rsa,ecdsa,ed25519