Skip to content

Merge branch 'main' of https://github.com/yefansky/CodeReDesign #250

Merge branch 'main' of https://github.com/yefansky/CodeReDesign

Merge branch 'main' of https://github.com/yefansky/CodeReDesign #250

Workflow file for this run

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: check_build
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
$sourceFile = "src/python/rag.py"
$md5File = "src.md5"
# 计算当前文件的MD5
$currentMD5 = (Get-FileHash -Path $sourceFile -Algorithm MD5).Hash
echo "Current MD5: $currentMD5"
# 尝试从最新release下载src.md5
try {
$lastSrcMD5Url = "https://github.com/yefansky/CodeReDesign/releases/download/latest/src.md5"
if ($lastSrcMD5Url) {
echo "Downloading src.md5 from latest release: $lastSrcMD5Url"
Invoke-WebRequest -Uri $lastSrcMD5Url -OutFile $md5File -ErrorAction Stop
$storedMD5 = Get-Content $md5File -ErrorAction Stop
echo "Stored MD5: $storedMD5"
if ($currentMD5.ToLower() -eq $storedMD5.ToLower()) {
echo "::notice::Source file unchanged - skipping build"
echo "build_needed=false" >> $env:GITHUB_OUTPUT
exit 0
}
}
} catch {
echo "::warning::Could not retrieve stored MD5 (first build?): $($_.Exception.Message)"
}
echo "::notice::Source file changed or no previous MD5 found - proceeding with build"
echo "build_needed=true" >> $env:GITHUB_OUTPUT
# 生成新的MD5文件供后续使用
echo $currentMD5.ToLower() > $md5File
echo "Generated new MD5 file"
shell: pwsh
# Set up Python
- name: Set up Python
if: steps.check_build.outputs.build_needed == 'true'
uses: actions/setup-python@v4
with:
python-version: '3.10'
# Install PyInstaller
- name: Install PyInstaller
if: steps.check_build.outputs.build_needed == 'true'
run: pip install pyinstaller
# Install Python dependencies
- name: Install Python dependencies
if: steps.check_build.outputs.build_needed == 'true'
run: pip install -r src/python/requirements.txt
# Build EXE to a temporary directory
- name: Build EXE
if: steps.check_build.outputs.build_needed == 'true'
run: |
mkdir temp_dist
pyinstaller --onefile --clean --distpath temp_dist src/python/rag.py
if ($LASTEXITCODE -ne 0) { throw "PyInstaller build failed" }
shell: pwsh
# Compress EXE with UPX
- name: Compress EXE with UPX
if: steps.check_build.outputs.build_needed == 'true'
uses: crazy-max/ghaction-upx@v3
with:
version: latest
files: |
temp_dist/rag.exe
args: -fq --best
# Generate MD5 checksum
- name: Generate MD5 checksum
if: steps.check_build.outputs.build_needed == 'true'
run: |
$md5 = (Get-FileHash -Path temp_dist/rag.exe -Algorithm MD5).Hash
echo $md5.ToLower() > temp_dist/md5.txt
shell: pwsh
- name: Delete old Release
if: steps.check_build.outputs.build_needed == 'true'
run: |
gh release view latest --json url 2>$null
$releaseExists = ($LASTEXITCODE -eq 0)
if ($releaseExists) {
gh release delete latest --yes
} else {
Write-Host "Release 'latest' does not exist, skipping deletion."
}
exit 0
shell: pwsh
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create Release
if: steps.check_build.outputs.build_needed == 'true'
uses: softprops/action-gh-release@v2
with:
files: |
temp_dist/rag.exe
temp_dist/md5.txt
src.md5
tag_name: latest
name: Latest RAG Executable
draft: false
prerelease: false
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
Remove-Item -Path temp_rag.py -Force -ErrorAction SilentlyContinue
shell: pwsh
build-and-publish:
runs-on: ubuntu-latest
needs: build-python-exe
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download md5.txt from GitHub Release
run: |
mkdir -p dist
curl -L -o dist/md5.txt https://github.com/yefansky/CodeReDesign/releases/download/latest/md5.txt
echo "Downloaded md5.txt from release"
shell: bash
- 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 # 忽略重复版本错误