Files
rust-socksd/.github/workflows/release.yml
T
2025-05-30 00:29:30 +01:00

143 lines
5.4 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:
version: ${{ env.VERSION }}
tag_name: ${{ github.ref_name }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Get version from tag
id: get_version
run: echo "VERSION=${GITHUB_REF_NAME#v}" >> $GITHUB_ENV # Example: v1.0.0 -> 1.0.0
- name: Create GitHub Release
id: create_release_step
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release create ${{ github.ref_name }} \
--title "Release ${{ github.ref_name }}" \
--notes "Automated release for rusty-socks 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
env:
VERSION: ${{ needs.create_gh_release.outputs.version }}
TAG_NAME: ${{ needs.create_gh_release.outputs.tag_name }}
run: |
PROJECT_NAME=$(grep '^name *=' Cargo.toml | sed 's/name *= *"\(.*\)"/\1/')
ARCHIVE_NAME="${PROJECT_NAME}-${VERSION}.tar.gz"
# Create archive from the tagged commit, ensuring it extracts to a versioned directory
git archive --format=tar.gz --prefix="${PROJECT_NAME}-${VERSION}/" -o "${ARCHIVE_NAME}" "${TAG_NAME}"
echo "ARCHIVE_NAME=\"${ARCHIVE_NAME}\"" >> $GITHUB_ENV
echo "ARCHIVE_PATH=\"${PWD}/${ARCHIVE_NAME}\"" >> $GITHUB_ENV
echo "Created archive: ${ARCHIVE_NAME}"
ls -lh "${ARCHIVE_NAME}"
- name: Upload source archive to release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
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
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up QEMU (for arm64 builds)
if: matrix.arch == 'arm64'
uses: docker/setup-qemu-action@v3
with:
platforms: arm64
- name: Install Rust toolchain for target ${{ matrix.target }}
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Install cargo-deb
run: cargo install cargo-deb --locked
- 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 gcc-aarch64-linux-gnu
- name: Configure linker for cross-compilation (for arm64)
if: matrix.linker != '' && matrix.linker != null
run: |
mkdir -p .cargo
echo '[target.${{ matrix.target }}]' > .cargo/config.toml
echo 'linker = "${{ matrix.linker }}"' >> .cargo/config.toml
echo "Configured .cargo/config.toml for ${{ matrix.target }}:"
cat .cargo/config.toml
- name: Build Debian package for ${{ matrix.arch }}
run: cargo deb --target ${{ matrix.target }}
- name: Get package name and path
id: package_info
run: |
DEB_PATH=$(find target/debian/ target/${{ matrix.target }}/debian/ -name "rusty-socks_*_${{ matrix.arch }}.deb" -print -quit 2>/dev/null)
if [ -z "$DEB_PATH" ]; then
echo "::error::Could not find .deb package for ${{ matrix.arch }} matching 'rusty-socks_*_${{ matrix.arch }}.deb'"
echo "Listing contents of potential directories:"
ls -R target/debian || echo "target/debian does not exist or is empty"
ls -R target/${{ matrix.target }}/debian || echo "target/${{ matrix.target }}/debian does not exist or is empty"
exit 1
fi
echo "Found deb package: $DEB_PATH"
echo "DEB_PATH=\"${DEB_PATH}\"" >> $GITHUB_ENV
echo "DEB_NAME=\"\$(basename \"${DEB_PATH}\")\"" >> $GITHUB_ENV
ls -lh "$DEB_PATH"
- name: Upload Debian package to release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release upload ${{ needs.create_gh_release.outputs.tag_name }} "${{ env.DEB_PATH }}"