fix: 打包流程修改 #173
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: Publish VS Code Extension | |
| on: | |
| push: | |
| branches: [ "main" ] # 主分支推送时触发 | |
| workflow_dispatch: # 允许手动触发 | |
| jobs: | |
| build-python-exe: | |
| runs-on: windows-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 2 # Fetch previous commit for hash comparison | |
| # Calculate SHA256 and check if build is needed | |
| - name: Check if build is needed | |
| id: sha256 | |
| run: | | |
| $sha256 = (Get-FileHash -Path src/python/rag.py -Algorithm SHA256).Hash | |
| echo "Current SHA256: $sha256" | |
| $previous_sha256 = "${{ github.event.before }}" | |
| if ($previous_sha256) { | |
| $previous_content = git show $previous_sha256:src/python/rag.py 2>$null | |
| if ($?) { | |
| echo $previous_content | Out-File temp_rag.py | |
| $previous_hash = (Get-FileHash -Path temp_rag.py -Algorithm SHA256).Hash | |
| if ($previous_hash -eq $sha256) { | |
| echo "No changes detected in rag.py, skipping build and release." | |
| exit 0 | |
| } | |
| } | |
| } | |
| echo "Building new rag.exe due to changes or no previous commit." | |
| # Set up Python | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.10' | |
| # Install PyInstaller | |
| - name: Install PyInstaller | |
| run: pip install pyinstaller | |
| # Install Python dependencies | |
| - name: Install Python dependencies | |
| run: pip install -r src/python/requirements.txt | |
| # Build EXE to a temporary directory | |
| - name: Build EXE | |
| run: | | |
| mkdir temp_dist | |
| pyinstaller --onefile --clean --distpath temp_dist src/python/rag.py | |
| if ($LASTEXITCODE -ne 0) { throw "PyInstaller build failed" } | |
| # Compress EXE with UPX | |
| - name: Compress EXE with UPX | |
| uses: crazy-max/ghaction-upx@v3 | |
| with: | |
| version: latest | |
| files: | | |
| temp_dist/rag.exe | |
| args: -fq --best | |
| # Create GitHub Release | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| files: | | |
| temp_dist/rag.exe | |
| tag_name: v${{ github.run_number }} | |
| name: Release v${{ github.run_number }} | |
| draft: false | |
| prerelease: false | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| # Delete old releases | |
| - name: Delete old releases | |
| uses: dev-drprasad/[email protected] | |
| with: | |
| keep_latest: 5 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| # Clean up temporary directory | |
| - name: Clean up temporary directory | |
| if: always() | |
| run: Remove-Item -Path temp_dist -Recurse -Force -ErrorAction SilentlyContinue | |
| build-and-publish: | |
| runs-on: ubuntu-latest | |
| needs: build-python-exe | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Download EXE artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: rag.exe | |
| path: dist # 下载到 dist 目录 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| cache: 'npm' | |
| - name: Install Dependencies | |
| run: npm install | |
| - name: Install standard-version | |
| run: npm install --save-dev standard-version | |
| - name: Install vsce | |
| run: npm install -g @vscode/vsce | |
| - name: Set Git user name and email | |
| run: | | |
| git config --global user.name "GitHub Actions" | |
| git config --global user.email "[email protected]" | |
| - name: Run standard-version | |
| run: npx standard-version # 自动更新版本号 | |
| - name: Push changes and tags | |
| run: | | |
| git push --follow-tags | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Get metadata from package.json | |
| id: metadata | |
| run: | | |
| NAME=$(node -p "require('./package.json').name") | |
| VERSION=$(node -p "require('./package.json').version") | |
| echo "NAME=$NAME" >> $GITHUB_ENV | |
| echo "VERSION=$VERSION" >> $GITHUB_ENV | |
| - name: Package Extension | |
| run: vsce package # 使用默认文件名 CodeReDesign-<version>.vsix | |
| - name: Create GitHub Release | |
| id: create_release | |
| uses: actions/create-release@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| tag_name: v${{ env.VERSION }} | |
| release_name: Release v${{ env.VERSION }} | |
| draft: false | |
| prerelease: false | |
| body: | | |
| Auto-generated release for version ${{ env.VERSION }}. | |
| Download the VSIX file below to install the extension. | |
| - name: Upload VSIX to Release | |
| uses: actions/upload-release-asset@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| upload_url: ${{ steps.create_release.outputs.upload_url }} | |
| asset_path: ${{ env.NAME }}-${{ env.VERSION }}.vsix | |
| asset_name: ${{ env.NAME }}-${{ env.VERSION }}.vsix | |
| asset_content_type: application/zip | |
| - name: Publish to Marketplace | |
| uses: HaaLeo/[email protected] # 第三方 Action 简化发布 | |
| with: | |
| pat: ${{ secrets.SHELLING }} # 引用 GitHub Secret | |
| registryUrl: https://marketplace.visualstudio.com | |
| skipDuplicate: true # 忽略重复版本错误 |