Build Multi-Platform Executables (Using Private Data Repo) #17
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build Multi-Platform Executables (Using Private Data Repo) | |
| on: | |
| push: | |
| branches: [ main ] | |
| paths: | |
| - 'requirements.txt' | |
| - '.github/workflows/build.yml' | |
| workflow_dispatch: | |
| # 添加权限声明 | |
| permissions: | |
| contents: write | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| build: | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| max-parallel: 3 | |
| matrix: | |
| include: | |
| - os: ubuntu-latest | |
| python-version: '3.8' | |
| artifact-name: evaluate-linux | |
| build-name: evaluate-linux | |
| - os: macos-latest | |
| python-version: '3.8' | |
| artifact-name: evaluate-macos | |
| build-name: evaluate-macos | |
| - os: windows-latest | |
| python-version: '3.8' | |
| artifact-name: evaluate-win | |
| build-name: evaluate-win.exe | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python ${{ matrix.python-version }} | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Install requests library | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install requests | |
| - name: Create evaluate.py from Secret | |
| env: | |
| EVALUATE_CODE: ${{ secrets.EVALUATE_PY_CODE }} | |
| run: | | |
| echo "$EVALUATE_CODE" > evaluate.py | |
| echo "[SUCCESS] Created evaluate.py from Secret" | |
| shell: bash | |
| - name: Download test.csv from private data repository | |
| env: | |
| DATA_REPO_TOKEN: ${{ secrets.DATA_REPO_TOKEN }} | |
| DATA_REPO_OWNER: ${{ secrets.DATA_REPO_OWNER }} | |
| DATA_REPO_NAME: ${{ secrets.DATA_REPO_NAME }} | |
| run: | | |
| python3 << 'EOF' | |
| import requests | |
| import base64 | |
| import os | |
| import sys | |
| token = os.environ.get('DATA_REPO_TOKEN', '').strip() | |
| owner = os.environ.get('DATA_REPO_OWNER', '').strip() | |
| repo = os.environ.get('DATA_REPO_NAME', '').strip() | |
| if not token or not owner or not repo: | |
| print('[ERROR] Missing configuration') | |
| if not token: | |
| print(' - DATA_REPO_TOKEN is not set') | |
| if not owner: | |
| print(' - DATA_REPO_OWNER is not set') | |
| if not repo: | |
| print(' - DATA_REPO_NAME is not set') | |
| sys.exit(1) | |
| print(f'Downloading from: {owner}/{repo}') | |
| url = f'https://api.github.com/repos/{owner}/{repo}/contents/test.csv' | |
| headers = { | |
| 'Accept': 'application/vnd.github.raw', | |
| 'Authorization': f'token {token}', | |
| 'X-GitHub-Api-Version': '2022-11-28' | |
| } | |
| print('Sending request to GitHub API...') | |
| try: | |
| response = requests.get(url, headers=headers, timeout=30) | |
| if response.status_code == 200: | |
| # 直接写入原始内容 | |
| with open('test.csv', 'wb') as f: | |
| f.write(response.content) | |
| # 验证文件 | |
| file_size = os.path.getsize('test.csv') | |
| print(f'[SUCCESS] Downloaded test.csv ({file_size} bytes)') | |
| with open('test.csv', 'r') as f: | |
| lines = f.readlines()[:3] | |
| print(f'[INFO] File preview ({len(lines)} lines):') | |
| for line in lines: | |
| print(f' {line.strip()[:80]}...') | |
| else: | |
| print(f'[ERROR] Failed to download test.csv') | |
| sys.exit(1) | |
| except Exception as e: | |
| print(f'[ERROR] Exception occurred: {str(e)}') | |
| sys.exit(1) | |
| EOF | |
| shell: bash | |
| - name: Verify files created (Unix) | |
| if: runner.os != 'Windows' | |
| run: | | |
| echo "Files in root directory:" | |
| ls -lh evaluate.py test.csv | |
| echo "" | |
| echo "File line counts:" | |
| wc -l evaluate.py test.csv | |
| - name: Verify files created (Windows) | |
| if: runner.os == 'Windows' | |
| run: | | |
| echo "Files in root directory:" | |
| dir evaluate.py, test.csv | |
| echo "" | |
| echo "Files exist check:" | |
| Test-Path evaluate.py | |
| Test-Path test.csv | |
| shell: pwsh | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install pyinstaller | |
| pip install -r requirements.txt | |
| - name: Build with PyInstaller (Linux) | |
| if: runner.os == 'Linux' | |
| run: | | |
| pyinstaller --onefile \ | |
| --name evaluate-linux \ | |
| --add-data "test.csv:." \ | |
| --hidden-import pandas \ | |
| --hidden-import numpy \ | |
| --hidden-import requests \ | |
| evaluate.py | |
| - name: Build with PyInstaller (macOS) | |
| if: runner.os == 'macOS' | |
| run: | | |
| pyinstaller --onefile \ | |
| --name evaluate-macos \ | |
| --add-data "test.csv:." \ | |
| --hidden-import pandas \ | |
| --hidden-import numpy \ | |
| --hidden-import requests \ | |
| evaluate.py | |
| - name: Build with PyInstaller (Windows) | |
| if: runner.os == 'Windows' | |
| run: | | |
| pyinstaller --onefile ` | |
| --name evaluate-win ` | |
| --add-data "test.csv;." ` | |
| --hidden-import pandas ` | |
| --hidden-import numpy ` | |
| --hidden-import requests ` | |
| evaluate.py | |
| - name: Cleanup source files | |
| if: always() | |
| run: | | |
| rm -f evaluate.py test.csv || true | |
| echo "✓ Cleaned up temporary files" | |
| shell: bash | |
| - name: Upload artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ matrix.artifact-name }} | |
| path: dist/${{ matrix.build-name }} | |
| release: | |
| needs: build | |
| runs-on: ubuntu-latest | |
| if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' | |
| steps: | |
| - name: Download all artifacts | |
| uses: actions/download-artifact@v4 | |
| - name: Display structure | |
| run: ls -R | |
| - name: Create Release | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| tag_name: v${{ github.run_number }} | |
| name: Release v${{ github.run_number }} | |
| draft: false | |
| prerelease: false | |
| files: | | |
| evaluate-linux/evaluate-linux | |
| evaluate-macos/evaluate-macos | |
| evaluate-win/evaluate-win.exe | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |