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

182 lines
6.7 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
runs-on: ubuntu-latest
needs: create_gh_release
permissions:
contents: write
strategy:
fail-fast: false
matrix:
include:
- arch: amd64
target: x86_64-unknown-linux-gnu
- arch: arm64
target: aarch64-unknown-linux-gnu
- arch: armhf
target: armv7-unknown-linux-gnueabihf
steps:
- uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Install cargo-binstall
run: curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash
- name: Install cross via cargo-binstall
run: cargo binstall --no-confirm cross
- name: Install Debian packaging tools
run: |
sudo apt-get update
sudo apt-get install -y debhelper dpkg-dev
# Install cross-compilation tools for all architectures
sudo apt-get install -y binutils-aarch64-linux-gnu binutils-arm-linux-gnueabihf
- name: Build Debian Package for ${{ matrix.arch }}
run: |
mkdir -p package-build
rsync -a --exclude=package-build --exclude=target . package-build/
cd package-build
USE_CROSS=1 CARGO_BUILD_TARGET=${{ matrix.target }} dpkg-buildpackage -b -uc -us -d -a${{ matrix.arch }}
- name: Upload Debian package to release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG_NAME: ${{ needs.create_gh_release.outputs.tag_name }}
run: |
# Find the .deb file in the workspace root (parent of package-build)
DEB_PATH=$(find . -maxdepth 1 -name "*_${{ matrix.arch }}.deb" -print -quit)
if [ -z "$DEB_PATH" ]; then
echo "::error::Could not find .deb package for ${{ matrix.arch }}"
ls -l
exit 1
fi
echo "Found deb package: $DEB_PATH"
gh release upload ${{ env.TAG_NAME }} "$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