Add GitHub Actions workflow for building and releasing executable #3
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 Executable | |
| on: | |
| push: | |
| branches: [ main ] | |
| tags: | |
| - 'v*' | |
| pull_request: | |
| branches: [ main ] | |
| workflow_dispatch: | |
| jobs: | |
| build: | |
| strategy: | |
| matrix: | |
| os: [ubuntu-latest, windows-latest, macos-latest] | |
| include: | |
| - os: ubuntu-latest | |
| platform: linux | |
| - os: windows-latest | |
| platform: windows | |
| - os: macos-latest | |
| platform: macos | |
| runs-on: ${{ matrix.os }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v3 | |
| - name: Setup Conda | |
| uses: conda-incubator/setup-miniconda@v3 | |
| with: | |
| auto-update-conda: true | |
| python-version: '3.12' | |
| activate-environment: wordreorder-env | |
| - name: Install dependencies with Conda | |
| shell: bash -el {0} | |
| run: | | |
| conda install -y install python-docx pyyaml tqdm colorama | |
| conda install -y pyinstaller | |
| - name: Build with PyInstaller | |
| shell: bash -el {0} | |
| run: | | |
| pyinstaller --onefile --name "wordreorder-${{ matrix.platform }}" wordreorder.py | |
| - name: Upload executable | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: wordreorder-${{ matrix.platform }} | |
| path: | | |
| dist/wordreorder-${{ matrix.platform }}* | |
| create-release: | |
| needs: build | |
| runs-on: ubuntu-latest | |
| if: startsWith(github.ref, 'refs/tags/v') || github.event_name == 'workflow_dispatch' | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| - name: Get version | |
| id: get_version | |
| run: | | |
| if [[ $GITHUB_REF == refs/tags/v* ]]; then | |
| echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT | |
| else | |
| echo "version=$(date +'%Y.%m.%d')-dev" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Download all artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: artifacts | |
| - name: Prepare release assets | |
| run: | | |
| mkdir release_assets | |
| find artifacts -type f -not -name "*.zip" -exec cp {} release_assets/ \; | |
| chmod +x release_assets/wordreorder-linux | |
| ls -la release_assets/ | |
| - name: Create release | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| name: "WordReorder ${{ steps.get_version.outputs.version }}" | |
| tag_name: ${{ startsWith(github.ref, 'refs/tags/') && github.ref_name || format('v{0}', steps.get_version.outputs.version) }} | |
| draft: false | |
| prerelease: ${{ !startsWith(github.ref, 'refs/tags/') }} | |
| generate_release_notes: true | |
| files: | | |
| release_assets/* | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |