Skip to content

Build and Release

Build and Release #14

Workflow file for this run

name: Build and Release
on:
release:
types: [created]
workflow_dispatch:
permissions:
contents: write
env:
CARGO_TERM_COLOR: always
jobs:
native-build:
runs-on: ${{ matrix.os }}
env:
TARGET: x86_64-unknown-linux-musl
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Rust
run: |
rustup update --no-self-update stable
rustup target add ${{ env.TARGET }}
rustup default stable
- name: Install Dependencies
run: |
sudo apt-get update
sudo apt-get install musl-tools -y
- name: Setup Cache
uses: Swatinem/rust-cache@v2
env:
cache-name: cache-cargo-${{ env.TARGET }}
with:
prefix-key: "prevanced-backend-v1"
shared-key: ${{ runner.os }}-cargo-
key: ${{ runner.os }}-cargo-${{ env.TARGET }}-
cache-directories: |
C:\Users\runneradmin\.cargo
/Users/runner/.cargo
- name: Build
run: cargo build --release --target ${{ env.TARGET }}
- name: Upload binaries to release
if: ${{ github.event_name == 'release' }}
run: |
mv target/${{ env.TARGET }}/release/prevanced-backend target/${{ env.TARGET }}/release/prevanced-backend-${{ github.ref_name }}
gh release upload ${{ github.ref_name }} target/${{ env.TARGET }}/release/prevanced-backend-${{ github.ref_name }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
publish:
runs-on: ubuntu-latest
needs: native-build
if: github.event_name == 'release'
steps:
- name: Publish server
run: |
git config --global user.email "[email protected]"
git config --global user.name "PreVanced"
git clone https://prevanced:${{ secrets.HF_TOKEN }}@huggingface.co/spaces/prevanced/backend
cd backend
sed -E 's/v[0-9]+\.[0-9]+\.[0-9]+/${{ github.ref_name }}/g' Dockerfile > temp_Dockerfile
mv temp_Dockerfile Dockerfile
git add Dockerfile
git commit -m "Update prevanced-backend to ${{ github.ref_name }}"
git push origin main