Update version.txt #4
This file contains 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 and Package ProjectExportTool | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
jobs: | |
build: | |
runs-on: macos-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Set up Python | |
uses: actions/setup-python@v2 | |
with: | |
python-version: '3.12' # 根据你的需要设置Python版本 | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install pyinstaller PyQt5 | |
- name: Get current version | |
id: get_version | |
run: echo "CURRENT_VERSION=$(cat version.txt)" >> $GITHUB_ENV | |
- name: Increment version | |
id: increment_version | |
run: | | |
CURRENT_VERSION=$(cat version.txt) | |
NEW_VERSION=$(echo $CURRENT_VERSION | awk -F. '{$NF = $NF + 1;} 1' | sed 's/ /./g') | |
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV | |
echo $NEW_VERSION > version.txt | |
- name: Commit new version | |
run: | | |
git config --global user.name 'github-actions' | |
git config --global user.email '[email protected]' | |
git add version.txt | |
git commit -m "Bump version to ${{ env.NEW_VERSION }}" | |
git push origin main | |
- name: Create and modify spec file | |
run: | | |
pyinstaller --name ProjectExportTool --windowed --onefile main_for_mac.py | |
# 修改.spec文件 | |
sed -i '' 's/console=True/console=False/' ProjectExportTool.spec | |
cat << 'EOF' >> ProjectExportTool.spec | |
block_cipher = None | |
a = Analysis( | |
['main_for_mac.py'], | |
pathex=[], | |
binaries=[], | |
datas=[('HarmonyOS_Sans_SC_Regular.ttf', '.')], | |
hiddenimports=['PyQt5', 'PyQt5.QtWidgets', 'PyQt5.QtGui', 'PyQt5.QtCore'], | |
hookspath=[], | |
runtime_hooks=[], | |
excludes=[], | |
win_no_prefer_redirects=False, | |
win_private_assemblies=False, | |
cipher=block_cipher, | |
) | |
pyz = PYZ(a.pure, a.zipped_data, | |
cipher=block_cipher) | |
exe = EXE(pyz, | |
a.scripts, | |
[], | |
exclude_binaries=True, | |
name='ProjectExportTool', | |
debug=False, | |
bootloader_ignore_signals=False, | |
strip=False, | |
upx=True, | |
upx_exclude=[], | |
runtime_tmpdir=None, | |
console=False) | |
coll = COLLECT(exe, | |
a.binaries, | |
a.zipfiles, | |
a.datas, | |
strip=False, | |
upx=True, | |
upx_exclude=[], | |
name='ProjectExportTool') | |
app = BUNDLE( | |
coll, | |
name='ProjectExportTool.app', | |
icon=None, | |
bundle_identifier=None | |
) | |
EOF | |
- name: Clean output directory | |
run: rm -rf /Users/runner/work/Project_Exporter/Project_Exporter/dist/ProjectExportTool.app | |
- name: Run PyInstaller | |
run: pyinstaller -y ProjectExportTool.spec | |
- name: Create DMG | |
run: | | |
mkdir ProjectExportTool_temp | |
mv dist/ProjectExportTool.app ProjectExportTool_temp/ | |
hdiutil create -volname ProjectExportTool -srcfolder ProjectExportTool_temp -ov -format UDZO ProjectExportTool.dmg | |
- name: Upload DMG as artifact | |
uses: actions/upload-artifact@v2 | |
with: | |
name: ProjectExportTool-dmg | |
path: ProjectExportTool.dmg | |
- name: Create Release | |
id: create_release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{ env.NEW_VERSION }} | |
release_name: ProjectExportTool Release ${{ env.NEW_VERSION }} | |
body: | | |
Release of ProjectExportTool version ${{ env.NEW_VERSION }}. | |
draft: false | |
prerelease: false | |
- name: Upload Release Asset | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ProjectExportTool.dmg | |
asset_name: ProjectExportTool.dmg | |
asset_content_type: application/octet-stream |