|
| 1 | +name: Build and Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + paths: |
| 6 | + - '**' |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: write |
| 11 | + |
| 12 | +jobs: |
| 13 | + create-tag: |
| 14 | + runs-on: ubuntu-latest |
| 15 | + outputs: |
| 16 | + new_tag: ${{ steps.tag_version.outputs.new_tag }} |
| 17 | + steps: |
| 18 | + - name: Checkout code |
| 19 | + uses: actions/checkout@v4 |
| 20 | + with: |
| 21 | + fetch-depth: 0 |
| 22 | + |
| 23 | + - name: Calculate new version |
| 24 | + id: tag_version |
| 25 | + run: | |
| 26 | + # Fetch all tags |
| 27 | + git fetch --tags |
| 28 | + |
| 29 | + # Get the latest tag, default to v1.0.0 if none |
| 30 | + # We silence stderr to avoid confusion if no tags exist |
| 31 | + latest_tag=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0") |
| 32 | + echo "Current version: $latest_tag" |
| 33 | + |
| 34 | + # Remove 'v' prefix |
| 35 | + version=${latest_tag#v} |
| 36 | + |
| 37 | + # Split into array by dot |
| 38 | + IFS='.' read -r -a parts <<< "$version" |
| 39 | + |
| 40 | + # Ensure major.minor.patch structure |
| 41 | + if [ ${#parts[@]} -lt 3 ]; then |
| 42 | + parts=(1 0 0) |
| 43 | + fi |
| 44 | + |
| 45 | + major=${parts[0]} |
| 46 | + minor=${parts[1]} |
| 47 | + patch=${parts[2]} |
| 48 | + |
| 49 | + # Increment patch version |
| 50 | + new_patch=$((patch + 1)) |
| 51 | + |
| 52 | + new_tag="v$major.$minor.$new_patch" |
| 53 | + echo "New version: $new_tag" |
| 54 | + echo "new_tag=$new_tag" >> $GITHUB_OUTPUT |
| 55 | +
|
| 56 | + - name: Push new tag |
| 57 | + env: |
| 58 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 59 | + run: | |
| 60 | + git config user.name "github-actions[bot]" |
| 61 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 62 | + git tag ${{ steps.tag_version.outputs.new_tag }} |
| 63 | + git push origin ${{ steps.tag_version.outputs.new_tag }} |
| 64 | +
|
| 65 | + - name: Create Release |
| 66 | + uses: softprops/action-gh-release@v1 |
| 67 | + with: |
| 68 | + tag_name: ${{ steps.tag_version.outputs.new_tag }} |
| 69 | + name: Release ${{ steps.tag_version.outputs.new_tag }} |
| 70 | + draft: false |
| 71 | + prerelease: false |
| 72 | + |
| 73 | + build: |
| 74 | + needs: create-tag |
| 75 | + name: Build for ${{ matrix.os }} |
| 76 | + runs-on: ${{ matrix.os }} |
| 77 | + strategy: |
| 78 | + matrix: |
| 79 | + include: |
| 80 | + - os: windows-latest |
| 81 | + TARGET: windows |
| 82 | + - os: ubuntu-latest |
| 83 | + TARGET: linux |
| 84 | + - os: macos-latest |
| 85 | + TARGET: macos |
| 86 | + |
| 87 | + steps: |
| 88 | + - name: Checkout code |
| 89 | + uses: actions/checkout@v4 |
| 90 | + with: |
| 91 | + ref: ${{ needs.create-tag.outputs.new_tag }} |
| 92 | + |
| 93 | + - name: Set up Python |
| 94 | + uses: actions/setup-python@v4 |
| 95 | + with: |
| 96 | + python-version: '3.10' |
| 97 | + |
| 98 | + - name: Install dependencies |
| 99 | + run: | |
| 100 | + python -m pip install --upgrade pip |
| 101 | + pip install -r requirements.txt |
| 102 | + pip install pyinstaller |
| 103 | +
|
| 104 | + # --- Windows Build --- |
| 105 | + - name: Build Windows |
| 106 | + if: matrix.os == 'windows-latest' |
| 107 | + run: | |
| 108 | + pyinstaller --name "KnowEmail" --onefile --windowed --icon "favicon.ico" --add-data "src;src" --add-data "lib;lib" main.py |
| 109 | + mv dist/KnowEmail.exe dist/KnowEmail-${{ needs.create-tag.outputs.new_tag }}-windows.exe |
| 110 | +
|
| 111 | + # --- Linux Build --- |
| 112 | + - name: Build Linux |
| 113 | + if: matrix.os == 'ubuntu-latest' |
| 114 | + run: | |
| 115 | + # Use colon for separator on Linux |
| 116 | + pyinstaller --name "KnowEmail" --onefile --windowed --icon "favicon.ico" --add-data "src:src" --add-data "lib:lib" main.py |
| 117 | +
|
| 118 | + - name: Package Linux (AppImage & Deb) |
| 119 | + if: matrix.os == 'ubuntu-latest' |
| 120 | + run: | |
| 121 | + TAG_NAME="${{ needs.create-tag.outputs.new_tag }}" |
| 122 | + # Remove 'v' for deb version |
| 123 | + VERSION_NUM=${TAG_NAME#v} |
| 124 | + |
| 125 | + # Create AppDir structure for AppImage and Deb |
| 126 | + mkdir -p AppDir/usr/bin |
| 127 | + mkdir -p AppDir/usr/share/applications |
| 128 | + mkdir -p AppDir/usr/share/icons/hicolor/256x256/apps |
| 129 | + |
| 130 | + # Copy binary |
| 131 | + cp dist/KnowEmail AppDir/usr/bin/knowemail |
| 132 | + chmod +x AppDir/usr/bin/knowemail |
| 133 | + |
| 134 | + # Copy icon |
| 135 | + cp favicon.ico AppDir/knowemail.png |
| 136 | + cp favicon.ico AppDir/usr/share/icons/hicolor/256x256/apps/knowemail.png |
| 137 | + |
| 138 | + # Create Desktop file |
| 139 | + cat > AppDir/usr/share/applications/knowemail.desktop <<EOF |
| 140 | + [Desktop Entry] |
| 141 | + Type=Application |
| 142 | + Name=KnowEmail |
| 143 | + Exec=knowemail |
| 144 | + Icon=knowemail |
| 145 | + Categories=Utility; |
| 146 | + EOF |
| 147 | + |
| 148 | + # Copy desktop file to root of AppDir for AppImage |
| 149 | + cp AppDir/usr/share/applications/knowemail.desktop AppDir/knowemail.desktop |
| 150 | + cp AppDir/knowemail.png AppDir/.DirIcon |
| 151 | +
|
| 152 | + # --- AppImage --- |
| 153 | + wget -q https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage |
| 154 | + chmod +x linuxdeploy-x86_64.AppImage |
| 155 | + |
| 156 | + # Run linuxdeploy |
| 157 | + ./linuxdeploy-x86_64.AppImage --appdir AppDir --output appimage |
| 158 | + |
| 159 | + # Move and Rename AppImage |
| 160 | + mv KnowEmail-*.AppImage dist/KnowEmail-${TAG_NAME}-linux.AppImage |
| 161 | +
|
| 162 | + # --- Deb --- |
| 163 | + # Install fpm |
| 164 | + sudo apt-get update |
| 165 | + sudo apt-get install -y ruby ruby-dev rubygems build-essential |
| 166 | + sudo gem install --no-document fpm |
| 167 | + |
| 168 | + fpm -s dir -t deb \ |
| 169 | + -n knowemail \ |
| 170 | + -v ${VERSION_NUM} \ |
| 171 | + -p dist/KnowEmail-${TAG_NAME}-linux.deb \ |
| 172 | + --prefix / \ |
| 173 | + -C AppDir |
| 174 | +
|
| 175 | + # --- macOS Build --- |
| 176 | + - name: Build macOS |
| 177 | + if: matrix.os == 'macos-latest' |
| 178 | + run: | |
| 179 | + # Use colon for separator on macOS |
| 180 | + pyinstaller --name "KnowEmail" --windowed --icon "favicon.ico" --add-data "src:src" --add-data "lib:lib" main.py |
| 181 | + |
| 182 | + # Check dist content |
| 183 | + ls -R dist/ |
| 184 | +
|
| 185 | + # Prepare Version Name |
| 186 | + TAG_NAME="${{ needs.create-tag.outputs.new_tag }}" |
| 187 | + |
| 188 | + # Zip the .app for release |
| 189 | + cd dist |
| 190 | + zip -r KnowEmail-${TAG_NAME}-macos.app.zip KnowEmail.app |
| 191 | + cd .. |
| 192 | +
|
| 193 | + # Create DMG |
| 194 | + npm install -g create-dmg |
| 195 | + create-dmg dist/KnowEmail.app dist || true |
| 196 | + |
| 197 | + # Rename DMG if needed, create-dmg usually names it 'KnowEmail 1.0.0.dmg' or similar based on plist |
| 198 | + # We force a rename to match our convention |
| 199 | + mv dist/*.dmg dist/KnowEmail-${TAG_NAME}-macos.dmg |
| 200 | +
|
| 201 | + - name: Upload Assets |
| 202 | + uses: softprops/action-gh-release@v1 |
| 203 | + with: |
| 204 | + tag_name: ${{ needs.create-tag.outputs.new_tag }} |
| 205 | + files: | |
| 206 | + dist/KnowEmail-*-windows.exe |
| 207 | + dist/KnowEmail-*-linux.AppImage |
| 208 | + dist/KnowEmail-*-linux.deb |
| 209 | + dist/KnowEmail-*-macos.dmg |
| 210 | + dist/KnowEmail-*-macos.app.zip |
0 commit comments