subconverter 0.2.34

A more powerful utility to convert between proxy subscription format
Documentation
name: Build and Release

on:
  push:
    tags:
      - 'v[0-9]+.[0-9]+.[0-9]+'
      - 'v[0-9]+.[0-9]+.[0-9]+-pre.*'
      - 'v[0-9]+.[0-9]+.[0-9]+-rc.*'
  workflow_dispatch:
  repository_dispatch:
    types: [trigger-native-release]

concurrency: 
  group: ${{ github.ref }}-${{ github.workflow }}
  cancel-in-progress: true

jobs:
  linux_build:
    strategy:
      matrix:
        include:
          - arch: x86
            artifact: subconverter-linux-x86
            os: ubuntu-latest
            target: i686-unknown-linux-gnu
          - arch: amd64
            artifact: subconverter-linux-amd64
            os: ubuntu-latest
            target: x86_64-unknown-linux-gnu
          - arch: armv7
            artifact: subconverter-linux-armv7
            os: ubuntu-latest
            target: armv7-unknown-linux-musleabihf
          - arch: aarch64
            artifact: subconverter-linux-aarch64
            os: ubuntu-latest
            target: aarch64-unknown-linux-musl
    runs-on: ${{ matrix.os }}
    name: Linux ${{ matrix.arch }} Build
    steps:
    - name: Checkout repository
      uses: actions/checkout@v4
      
    - name: Determine Version
      id: get_version
      run: |
        VERSION=""
        if [[ "${{ github.event_name }}" == "push" && "${{ startsWith(github.ref, 'refs/tags/') }}" == "true" ]]; then
          VERSION=${GITHUB_REF#refs/tags/v}
        elif [[ "${{ github.event_name }}" == "repository_dispatch" && "${{ github.event.action }}" == "trigger-native-release" ]]; then
          VERSION=${{ github.event.client_payload.version }}
        elif [[ "${{ github.event_name }}" == "push" && "${{ !startsWith(github.ref, 'refs/tags/') }}" == "true" ]]; then
          SHA=$(git rev-parse --short HEAD)
          CARGO_VERSION=$(grep '^version' Cargo.toml | sed 's/.*"\\(.*\\)".*/\\1/')
          VERSION="$CARGO_VERSION-$SHA"
        else
          # Fallback or handle workflow_dispatch if needed
          VERSION=$(grep '^version' Cargo.toml | sed 's/.*"\\(.*\\)".*/\\1/')-manual
        fi
        echo "RELEASE_VERSION=$VERSION" >> $GITHUB_ENV
        echo "Determined version: $VERSION"

    - name: Update version in Cargo.toml for branch builds
      # Only add commit hash for non-tag, non-dispatch builds
      if: ${{ github.event_name == 'push' && !startsWith(github.ref, 'refs/tags/') }}
      run: |
        CURRENT_VERSION=$(grep '^version' Cargo.toml | sed 's/.*"\\(.*\\)".*/\\1/')
        # Ensure the version in Cargo.toml reflects the branch build version
        sed -i "s/^version = \"$CURRENT_VERSION\"/version = \"${{ env.RELEASE_VERSION }}\"/" Cargo.toml
        echo "Updated Cargo.toml version for branch build to ${{ env.RELEASE_VERSION }}"
    
    - name: Setup Rust
      uses: dtolnay/rust-toolchain@stable
      with:
        targets: ${{ matrix.target }}
    
    - name: Install dependencies
      run: |
        sudo apt-get update
        sudo apt-get install -y pkg-config libssl-dev
    
    - name: Install cross
      run: cargo install cross
      
    - name: Build with cross
      run: cross build --release --features=web-api${{ matrix.arch == 'amd64' && ',js-runtime' || '' }} --target ${{ matrix.target }}
      
    - name: Prepare artifact
      run: |
        mkdir -p subconverter/
        cp target/${{ matrix.target }}/release/subconverter subconverter/
        cp -r base/* subconverter/
        
    - name: Upload artifact
      uses: actions/upload-artifact@v4
      with:
        name: ${{ matrix.artifact }}-${{ env.RELEASE_VERSION }} # Append version to artifact name for clarity
        path: subconverter/
        
    - name: Package Release
      # Run for tags or trigger-native-release event
      if: startsWith(github.ref, 'refs/tags/') || (github.event_name == 'repository_dispatch' && github.event.action == 'trigger-native-release')
      run: tar czf ${{ matrix.artifact }}-${{ env.RELEASE_VERSION }}.tar.gz subconverter
      
    - name: Draft Release
      # Run for tags or trigger-native-release event
      if: startsWith(github.ref, 'refs/tags/') || (github.event_name == 'repository_dispatch' && github.event.action == 'trigger-native-release')
      uses: softprops/action-gh-release@v2
      with:
        files: ${{ matrix.artifact }}-${{ env.RELEASE_VERSION }}.tar.gz
        # Explicitly set tag_name for dispatch events, otherwise it defaults to github.ref (which is correct for tag pushes)
        tag_name: ${{ github.event_name == 'repository_dispatch' && format('v{0}', env.RELEASE_VERSION) || '' }}
        draft: true

  macos_build:
    strategy:
      matrix:
        include:
          - arch: x86_64
            artifact: subconverter-macos-x86_64
            os: macos-13
            target: x86_64-apple-darwin
          - arch: aarch64
            artifact: subconverter-macos-aarch64
            os: macos-14
            target: aarch64-apple-darwin
    runs-on: ${{ matrix.os }}
    name: macOS ${{ matrix.arch }} Build
    steps:
    - name: Checkout repository
      uses: actions/checkout@v4
      
    - name: Determine Version
      id: get_version
      run: |
        VERSION=""
        if [[ "${{ github.event_name }}" == "push" && "${{ startsWith(github.ref, 'refs/tags/') }}" == "true" ]]; then
          VERSION=${GITHUB_REF#refs/tags/v}
        elif [[ "${{ github.event_name }}" == "repository_dispatch" && "${{ github.event.action }}" == "trigger-native-release" ]]; then
          VERSION=${{ github.event.client_payload.version }}
        elif [[ "${{ github.event_name }}" == "push" && "${{ !startsWith(github.ref, 'refs/tags/') }}" == "true" ]]; then
          SHA=$(git rev-parse --short HEAD)
          CARGO_VERSION=$(grep '^version' Cargo.toml | sed 's/.*"\\(.*\\)".*/\\1/')
          VERSION="$CARGO_VERSION-$SHA"
        else
          VERSION=$(grep '^version' Cargo.toml | sed 's/.*"\\(.*\\)".*/\\1/')-manual
        fi
        echo "RELEASE_VERSION=$VERSION" >> $GITHUB_ENV
        echo "Determined version: $VERSION"
        
    - name: Setup Rust
      uses: dtolnay/rust-toolchain@stable
      with:
        targets: ${{ matrix.target }}
        
    - name: Update version in Cargo.toml for branch builds
      # Only add commit hash for non-tag, non-dispatch builds
      if: ${{ github.event_name == 'push' && !startsWith(github.ref, 'refs/tags/') }}
      run: |
        CURRENT_VERSION=$(grep '^version' Cargo.toml | sed 's/.*"\\(.*\\)".*/\\1/')
        sed -i -e "s/^version = \"$CURRENT_VERSION\"/version = \"${{ env.RELEASE_VERSION }}\"/" Cargo.toml
        echo "Updated Cargo.toml version for branch build to ${{ env.RELEASE_VERSION }}"
        
    - name: Build
      run: cargo build --release --features=web-api,js-runtime --target ${{ matrix.target }}
      
    - name: Prepare artifact
      run: |
        mkdir -p subconverter/
        cp target/${{ matrix.target }}/release/subconverter subconverter/
        cp -r base/* subconverter/
        
    - name: Upload artifact
      uses: actions/upload-artifact@v4
      with:
        name: ${{ matrix.artifact }}-${{ env.RELEASE_VERSION }} # Append version to artifact name
        path: subconverter/
        
    - name: Package Release
      if: startsWith(github.ref, 'refs/tags/') || (github.event_name == 'repository_dispatch' && github.event.action == 'trigger-native-release')
      run: tar czf ${{ matrix.artifact }}-${{ env.RELEASE_VERSION }}.tar.gz subconverter
      
    - name: Draft Release
      if: startsWith(github.ref, 'refs/tags/') || (github.event_name == 'repository_dispatch' && github.event.action == 'trigger-native-release')
      uses: softprops/action-gh-release@v2
      with:
        files: ${{ matrix.artifact }}-${{ env.RELEASE_VERSION }}.tar.gz
        tag_name: ${{ github.event_name == 'repository_dispatch' && format('v{0}', env.RELEASE_VERSION) || '' }}
        draft: true
  
  windows_build:
    strategy:
      matrix:
        include:
          - arch: x86
            artifact: subconverter-windows-x86
            target: i686-pc-windows-msvc
          - arch: amd64
            artifact: subconverter-windows-amd64
            target: x86_64-pc-windows-msvc
    runs-on: windows-latest
    name: Windows ${{ matrix.arch }} Build
    steps:
    - name: Checkout repository
      uses: actions/checkout@v4
      
    - name: Determine Version
      id: get_version
      shell: bash
      run: |
        VERSION=""
        if [[ "${{ github.event_name }}" == "push" && "${{ startsWith(github.ref, 'refs/tags/') }}" == "true" ]]; then
          VERSION=${GITHUB_REF#refs/tags/v}
        elif [[ "${{ github.event_name }}" == "repository_dispatch" && "${{ github.event.action }}" == "trigger-native-release" ]]; then
          VERSION=${{ github.event.client_payload.version }}
        elif [[ "${{ github.event_name }}" == "push" && "${{ !startsWith(github.ref, 'refs/tags/') }}" == "true" ]]; then
          SHA=$(git rev-parse --short HEAD)
          CARGO_VERSION=$(grep '^version' Cargo.toml | sed 's/.*"\\(.*\\)".*/\\1/')
          VERSION="$CARGO_VERSION-$SHA"
        else
          VERSION=$(grep '^version' Cargo.toml | sed 's/.*"\\(.*\\)".*/\\1/')-manual
        fi
        echo "RELEASE_VERSION=$VERSION" >> $GITHUB_ENV
        echo "Determined version: $VERSION"

    - name: Setup Rust
      uses: dtolnay/rust-toolchain@stable
      with:
        targets: ${{ matrix.target }}
        
    - name: Update version in Cargo.toml for branch builds
      # Only add commit hash for non-tag, non-dispatch builds
      if: ${{ github.event_name == 'push' && !startsWith(github.ref, 'refs/tags/') }}
      shell: bash
      run: |
        CURRENT_VERSION=$(grep '^version' Cargo.toml | sed 's/.*"\\(.*\\)".*/\\1/')
        sed -i "s/^version = \"$CURRENT_VERSION\"/version = \"${{ env.RELEASE_VERSION }}\"/" Cargo.toml
        echo "Updated Cargo.toml version for branch build to ${{ env.RELEASE_VERSION }}"
        
    - name: Build
      run: |
        cargo install --force --locked bindgen-cli
        cargo build --release --features=web-api${{ matrix.arch == 'amd64' && ',js-runtime' || '' }} --target ${{ matrix.target }}
      
    - name: Prepare artifact
      shell: bash
      run: |
        mkdir -p subconverter/
        cp target/${{ matrix.target }}/release/subconverter.exe subconverter/
        cp -r base/* subconverter/
        
    - name: Upload artifact
      uses: actions/upload-artifact@v4
      with:
        name: ${{ matrix.artifact }}-${{ env.RELEASE_VERSION }} # Append version to artifact name
        path: subconverter/
        
    - name: Package Release
      if: startsWith(github.ref, 'refs/tags/') || (github.event_name == 'repository_dispatch' && github.event.action == 'trigger-native-release')
      run: 7z a ${{ matrix.artifact }}-${{ env.RELEASE_VERSION }}.7z subconverter/
      
    - name: Draft Release
      if: startsWith(github.ref, 'refs/tags/') || (github.event_name == 'repository_dispatch' && github.event.action == 'trigger-native-release')
      uses: softprops/action-gh-release@v2
      with:
        files: ${{ matrix.artifact }}-${{ env.RELEASE_VERSION }}.7z
        tag_name: ${{ github.event_name == 'repository_dispatch' && format('v{0}', env.RELEASE_VERSION) || '' }}
        draft: true