侧边栏壁纸
博主头像
996 Worker's Blog博主等级

祇園精舎の鐘の聲, 諸行無常の響き有り。

  • 累计撰写 215 篇文章
  • 累计创建 55 个标签
  • 累计收到 25 条评论

目 录CONTENT

文章目录

使用Github Action结合Pyinstaller把Python自动打包成exe应用

996Worker
2022-08-02 / 0 评论 / 0 点赞 / 602 阅读 / 2433 字

Github action script

name: PyInstaller Windows

# Controls when the workflow will run
on:
  # Triggers the workflow on push or pull request events but only for the "main" branch
  push:
    branches: [ "main" ]
    
  pull_request:
    branches: [ "main" ]

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

jobs:
  build-windows:
    runs-on: windows-2019
    steps:
      - name: Checkout
        uses: actions/checkout@v1
      - name: Install Python
        uses: actions/setup-python@v1
        with:
          python-version: '3.8'
          architecture: 'x64'
      - name: Install requirements and installer
        run: |
          pip install -r requirements.txt
          pip install pyinstaller
      - name: Run pyinstaller
        run: |
          python -m PyInstaller app.spec
      - uses: actions/upload-artifact@v2
        with:
          name: app
          path: dist/app
      
      - name: create release
        id: create_release
        uses: actions/create-release@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          tag_name: ${{ github.run_number }}
          release_name: Release ${{ github.run_number }}
          body: |
            Test Release
          draft: false
          prerelease: false
          
      # Since we have a directory, create a zip
      - name: zip the artifect dir into a zip
        run: |
          powershell Compress-Archive D:\a\SWEN90013-Data-Platform-for-Biomaterial-Testing\SWEN90013-Data-Platform-for-Biomaterial-Testing\dist\app D:\a\SWEN90013-Data-Platform-for-Biomaterial-Testing\SWEN90013-Data-Platform-for-Biomaterial-Testing\dist\app.zip
      
      - name: Upload release asset
        id: 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: dist/app.zip
           asset_name: app.zip
           asset_content_type: application/zip

Known problem

Due to uses: actions/upload-artifact@v2 item, the source code.zip in the Release will be assets that generated by pyinstaller, rather than source code. Be aware of that please.

0

评论区