github-proxy 0.1.1

github-proxy
Documentation
name: Test

permissions:
  contents: write

on: [push]

defaults:
  run:
    shell: bash --noprofile --norc -CeEuo pipefail {0}

jobs:
  test:
    strategy:
      matrix:
        os: [ubuntu-latest, windows-latest, macos-latest]
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v4
      - name: Install latest nightly
        uses: actions-rs/toolchain@v1
        with:
          toolchain: nightly
          override: true
      - name: cargo test
        run: |
          cargo test

      - name: Install github-proxy
        run: |
          cargo install --path .

      - name: Test all proxy services
        run: |
          set -e

          # Define proxy types
          PROXIES=("github" "xget" "gh-proxy" "jsdelivr" "statically")

          echo "=========================================="
          echo "Testing File Resources"
          echo "=========================================="

          for proxy in "${PROXIES[@]}"; do
            echo ""
            echo "Testing $proxy proxy (file)..."
            URL=$(github-proxy "$proxy" file easy-install easy-install main install.sh)
            echo "  Generated URL: $URL"

            OUTPUT_FILE="/tmp/test-file-${proxy}.sh"
            if curl -fsSL "$URL" -o "$OUTPUT_FILE"; then
              echo "  ✓ Download successful"
              ls -lh "$OUTPUT_FILE"
            else
              echo "  ✗ Download failed"
              exit 1
            fi
          done

          echo ""
          echo "=========================================="
          echo "Testing Release Resources"
          echo "=========================================="

          for proxy in "${PROXIES[@]}"; do
            echo ""
            echo "Testing $proxy proxy (release)..."

            # jsdelivr and statically don't support release assets
            if [ "$proxy" = "jsdelivr" ] || [ "$proxy" = "statically" ]; then
              echo "  ⊘ Skipping ($proxy doesn't support release assets)"
              if github-proxy "$proxy" release easy-install easy-install nightly ei-aarch64-apple-darwin.tar.gz 2>/dev/null; then
                echo "  ✗ Expected error but got success"
                exit 1
              else
                echo "  ✓ Correctly rejected unsupported resource type"
              fi
              continue
            fi

            URL=$(github-proxy "$proxy" release easy-install easy-install nightly ei-aarch64-apple-darwin.tar.gz)
            echo "  Generated URL: $URL"

            OUTPUT_FILE="/tmp/test-release-${proxy}.tar.gz"
            if curl -fsSL "$URL" -o "$OUTPUT_FILE"; then
              echo "  ✓ Download successful"
              ls -lh "$OUTPUT_FILE"
            else
              echo "  ✗ Download failed"
              exit 1
            fi
          done

          echo ""
          echo "=========================================="
          echo "All Tests Passed!"
          echo "=========================================="
          echo ""
          echo "File downloads:"
          ls -lh /tmp/test-file-*.sh
          echo ""
          echo "Release downloads:"
          ls -lh /tmp/test-release-*.tar.gz