Build and Release Electron App #51
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 and Release Electron App | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: 'Version Number (e.g., 1.0.0)' | |
| required: true | |
| default: '' | |
| prerelease: | |
| description: 'Is this a Pre-Release?' | |
| type: boolean | |
| default: false | |
| jobs: | |
| build_and_release: | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| os: [windows-latest, macos-latest, ubuntu-latest] | |
| node-version: [18] # LTS version, good for Electron | |
| steps: | |
| - name: Checkout FlashForgeUI | |
| uses: actions/checkout@v4 | |
| - name: Setup pnpm | |
| uses: pnpm/action-setup@v4 | |
| with: | |
| version: 10.23.0 | |
| - name: Setup Node.js ${{ matrix.node-version }} | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ matrix.node-version }} | |
| cache: 'pnpm' | |
| - name: Configure GitHub Packages Authentication | |
| shell: bash | |
| run: | | |
| echo "Setting up GitHub Packages authentication" | |
| echo "@ghosttypes:registry=https://npm.pkg.github.com" >> .npmrc | |
| echo "@parallel-7:registry=https://npm.pkg.github.com" >> .npmrc | |
| echo "//npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }}" >> .npmrc | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Install dependencies | |
| shell: bash | |
| run: | | |
| pnpm install --frozen-lockfile | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Download go2rtc binaries | |
| shell: bash | |
| run: | | |
| echo "Downloading go2rtc binaries for all platforms..." | |
| node scripts/download-go2rtc.cjs | |
| echo "go2rtc binaries ready for bundling" | |
| - name: Set Application Version | |
| shell: bash | |
| run: | | |
| VERSION="${{ github.event.inputs.version }}" | |
| if [[ "$VERSION" == *.* && "$VERSION" != *.*.* ]]; then | |
| VERSION="${VERSION}.0" | |
| elif [[ "$VERSION" != *.* ]]; then | |
| VERSION="${VERSION}.0.0" | |
| fi | |
| echo "Setting version to: $VERSION" | |
| pnpm version "$VERSION" --no-git-tag-version --allow-same-version | |
| - name: Build application with electron-builder | |
| shell: bash | |
| run: | | |
| # Use platform-specific build commands | |
| if [[ "$RUNNER_OS" == "Linux" ]]; then | |
| pnpm run build:ci:linux | |
| elif [[ "$RUNNER_OS" == "Windows" ]]; then | |
| pnpm run build:ci:win | |
| elif [[ "$RUNNER_OS" == "macOS" ]]; then | |
| pnpm run build:ci:mac | |
| fi | |
| - name: Upload Build Artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: FlashForgeUI-${{ matrix.os }} | |
| path: | | |
| dist/**/*.zip | |
| dist/**/*.deb | |
| dist/**/*.rpm | |
| dist/**/*Setup*.exe | |
| dist/**/FlashForgeUI*.exe | |
| dist/**/*.dmg | |
| dist/**/*.AppImage | |
| dist/**/*.nupkg | |
| dist/*.yml | |
| !dist/**/elevate.exe | |
| !dist/win-unpacked/** | |
| if-no-files-found: warn | |
| create_github_release: | |
| needs: build_and_release | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Download all build artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: artifacts | |
| - name: Display downloaded artifacts structure | |
| shell: bash | |
| run: | | |
| echo "Downloaded artifacts layout:" | |
| ls -R artifacts | |
| - name: Prepare Release Assets | |
| id: prep_assets | |
| shell: bash | |
| run: | | |
| mkdir release_assets | |
| find artifacts/ -type f \( -name "*.zip" -o -name "*.deb" -o -name "*.rpm" -o -name "*Setup*.exe" -o -name "FlashForgeUI*.exe" -o -name "*.dmg" -o -name "*.AppImage" -o -name "*.nupkg" -o -name "*.yml" \) | grep -v "elevate.exe" | while IFS= read -r file; do | |
| filename=$(basename "$file") | |
| cp "$file" "release_assets/$filename" | |
| echo "Copied $file to release_assets/$filename" | |
| done | |
| echo "Prepared assets in release_assets:" | |
| ls -l release_assets/ | |
| - name: Generate Release Notes | |
| id: generate_notes | |
| shell: bash | |
| run: | | |
| VERSION="${{ github.event.inputs.version }}" | |
| if [[ "$VERSION" == *.* && "$VERSION" != *.*.* ]]; then | |
| VERSION="${VERSION}.0" | |
| elif [[ "$VERSION" != *.* ]]; then | |
| VERSION="${VERSION}.0.0" | |
| fi | |
| IS_PRERELEASE="${{ github.event.inputs.prerelease }}" | |
| RELEASE_TYPE_BADGE="" | |
| if [[ "$IS_PRERELEASE" == "true" ]]; then | |
| RELEASE_TYPE_BADGE=" (Pre-release)" | |
| fi | |
| PRERELEASE_NOTICE="" | |
| if [[ "$IS_PRERELEASE" == "true" ]]; then | |
| PRERELEASE_NOTICE="This is an alpha pre-release build intended for testing before the next stable desktop release." | |
| fi | |
| VERSION_TAG="v${VERSION}" | |
| PREVIOUS_TAG=$(git tag -l 'v*' --sort=-version:refname | grep -vx "${VERSION_TAG}" | head -n 1) | |
| CHANGELOG_URL="https://github.com/${{ github.repository }}/blob/${VERSION_TAG}/CHANGELOG.md" | |
| README_URL="https://github.com/${{ github.repository }}" | |
| COMPARE_URL="" | |
| if [[ -n "$PREVIOUS_TAG" ]]; then | |
| COMPARE_URL="https://github.com/${{ github.repository }}/compare/${PREVIOUS_TAG}...${VERSION_TAG}" | |
| fi | |
| CHANGELOG_SECTION=$(VERSION="$VERSION" python3 <<'PY' | |
| from pathlib import Path | |
| import os | |
| import re | |
| version = os.environ["VERSION"] | |
| text = Path("CHANGELOG.md").read_text(encoding="utf-8") | |
| pattern = rf"^## \[{re.escape(version)}\] - [^\n]*\n(.*?)(?=^## \[|\Z)" | |
| match = re.search(pattern, text, re.MULTILINE | re.DOTALL) | |
| if match: | |
| print(match.group(1).strip()) | |
| PY | |
| ) | |
| if [[ -z "$(printf '%s' "$CHANGELOG_SECTION" | tr -d '[:space:]')" ]]; then | |
| CHANGELOG_SECTION="- See the [CHANGELOG](${CHANGELOG_URL}) for the detailed release notes." | |
| fi | |
| cat > RELEASE_NOTES.md << EOF | |
| # FlashForgeUI v${VERSION}${RELEASE_TYPE_BADGE} | |
| Desktop monitoring and control app for FlashForge printers. | |
| ${PRERELEASE_NOTICE} | |
| ## Changes | |
| ${CHANGELOG_SECTION} | |
| ## Downloads | |
| Download the installer or archive for your platform from the assets attached to this release. | |
| ## More Information | |
| - [README](${README_URL}) for setup and usage | |
| - [CHANGELOG](${CHANGELOG_URL}) for the full release history | |
| EOF | |
| if [[ -n "$COMPARE_URL" ]]; then | |
| cat >> RELEASE_NOTES.md << EOF | |
| - [Compare changes since ${PREVIOUS_TAG}](${COMPARE_URL}) | |
| EOF | |
| fi | |
| echo "VERSION_TAG=${VERSION_TAG}" >> $GITHUB_ENV | |
| echo "RELEASE_NAME=FlashForgeUI v${VERSION}${RELEASE_TYPE_BADGE}" >> $GITHUB_ENV | |
| echo "RELEASE_NOTES_PATH=RELEASE_NOTES.md" >> $GITHUB_ENV | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ env.VERSION_TAG }} | |
| name: ${{ env.RELEASE_NAME }} | |
| body_path: ${{ env.RELEASE_NOTES_PATH }} | |
| draft: false | |
| prerelease: ${{ github.event.inputs.prerelease }} | |
| files: | | |
| release_assets/* | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |