From d71a277af7074cd37479ea0be57973ea00bf23fc Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Sun, 12 Feb 2023 22:11:32 +0100 Subject: [PATCH 1/5] Change order of macos build, and add more output --- .github/workflows/build.yml | 4 +- setup/macos/build.sh | 77 ++++++++++++++++++++++++------------- 2 files changed, 52 insertions(+), 29 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 57581b02..88b16ebc 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -65,11 +65,11 @@ jobs: with: name: novelWriter-${{ env.VERSION }}-macos.app.zip path: dist_macos/novelWriter-${{ env.VERSION }}.app.zip - # retention-days: 1 + retention-days: 1 - name: Upload DMG uses: actions/upload-artifact@v3 with: name: novelWriter-${{ env.VERSION }}-macos.dmg path: dist_macos/novelWriter-${{ env.VERSION }}.dmg - # retention-days: 1 + retention-days: 1 diff --git a/setup/macos/build.sh b/setup/macos/build.sh index e3e8e2ff..ae7ff30f 100755 --- a/setup/macos/build.sh +++ b/setup/macos/build.sh @@ -1,6 +1,6 @@ #! /bin/bash -# use RAM disk if possible +# Use RAM disk if possible if [ -d /dev/shm ]; then TEMP_BASE=/dev/shm else @@ -8,11 +8,8 @@ else fi BUILD_DIR=$(mktemp -d "$TEMP_BASE/novelWriter-build-XXXXXX") - SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) - SRC_DIR="$SCRIPT_DIR/../.." - RLS_DIR="$SRC_DIR/dist_macos" echo "Script Dir: $SCRIPT_DIR" @@ -22,17 +19,18 @@ cleanup () { rm -rf "$BUILD_DIR" fi } - trap cleanup EXIT echo "Building in: $BUILD_DIR" OLD_CWD="$(pwd)" - VERSION="$(awk '/^__version__/{print substr($NF,2,length($NF)-2)}' $SRC_DIR/novelwriter/__init__.py)" pushd "$SRC_DIR" || exit 1 +# --- Prepare Files ----------------------------------------------------------------------------- # + +echo "Generating Info.plist" python3 setup.py gen-plist if [ -f $SRC_DIR/setup/macos/Info.plist ]; then echo "Found: setup/macos/Info.plist" @@ -40,8 +38,10 @@ else echo "Missing: setup/macos/Info.plist" exit 1 fi +echo "" # Check that other assets are present +echo "Checking assets" if [ -f $SRC_DIR/novelwriter/assets/sample.zip ]; then echo "Found: novelwriter/assets/sample.zip" else @@ -60,40 +60,51 @@ else echo "Missing: novelwriter/assets/i18n/nw_en_US.qm" exit 1 fi +echo "" +echo "Content of current dir:" ls -lah . +echo "" popd || exit 1 - pushd "$BUILD_DIR"/ || exit 1 -echo "Downloading Miniconda ..." +# --- Create Miniconda Env ---------------------------------------------------------------------- # + # install Miniconda, a self-contained Python distribution +echo "Downloading Miniconda ..." curl -LO https://repo.continuum.io/miniconda/Miniconda3-latest-MacOSX-x86_64.sh bash Miniconda3-latest-MacOSX-x86_64.sh -b -p ~/miniconda -f rm Miniconda3-latest-MacOSX-x86_64.sh export PATH="$HOME/miniconda/bin:$PATH" +echo "" echo "Creating conda env ..." # create conda env conda create -n novelWriter -c conda-forge python=3.10 --yes source activate novelWriter +echo "" echo "installing dictionaries ..." conda install -c conda-forge enchant hunspell-en --yes +echo "" -echo "installing python deps ..." -# install dependencies +# Install dependencies +echo "installing python dependencies ..." pip install -r "$SRC_DIR/requirements.txt" -# leave conda env +# Leave conda env conda deactivate +echo "" + +# --- Build App --------------------------------------------------------------------------------- # echo "Building app bundle ..." # create .app Framework mkdir -p novelWriter.app/Contents/ mkdir novelWriter.app/Contents/MacOS novelWriter.app/Contents/Resources novelWriter.app/Contents/Resources/novelWriter cp $SRC_DIR/setup/macos/Info.plist novelWriter.app/Contents/Info.plist +echo "" echo "Copying miniconda env to bundle ..." cp -R ~/miniconda/envs/novelWriter/* novelWriter.app/Contents/Resources/ @@ -111,24 +122,29 @@ for file in "${FILES_COPY[@]}"; do done cp $SRC_DIR/setup/macos/novelwriter.icns novelWriter.app/Contents/Resources/ +echo "" -# create entry script +# Create entry script +echo "Creating entry script ..." cat > novelWriter.app/Contents/MacOS/novelWriter <<\EOF #!/bin/bash DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" $DIR/../Resources/bin/python -sE $DIR/../Resources/novelWriter/novelWriter.py $@ EOF -# make executable +# Make it executable chmod a+x novelWriter.app/Contents/MacOS/novelWriter +echo "" -#do codesigning -#echo "Signing bundle ..." -#sudo codesign --sign - --deep --force --entitlements "$SCRIPT_DIR/../macos/App.entitlements" --options runtime "novelWriter.app/Contents/MacOS/novelWriter" +# Do codesigning +# echo "Signing bundle ..." +# sudo codesign --sign - --deep --force --entitlements "$SCRIPT_DIR/../macos/App.entitlements" --options runtime "novelWriter.app/Contents/MacOS/novelWriter" -# remove bloat +# Remove bloat pushd novelWriter.app/Contents/Resources || exit 1 +# --- Cleanup ----------------------------------------------------------------------------------- # + echo "Cleaning unused files from bundle ..." # cleanup commands HERE find . -type d -iname '__pycache__' -print0 | xargs -0 rm -r @@ -151,21 +167,28 @@ rm lib/python3.*/site-packages/PyQt5/Qt/lib/libQt5WebEngine* || true popd || exit 1 popd || exit 1 +echo "" + +# --- Create App Bundle-------------------------------------------------------------------------- # echo "Packageing App ..." - mkdir -p $RLS_DIR -# generate .dmg - -brew install create-dmg -# "--skip-jenkins" is a temporary workaround for https://github.com/create-dmg/create-dmg/issues/72 -create-dmg --volname "novelWriter $VERSION" --volicon $SRC_DIR/setup/macos/novelwriter.icns \ - --window-pos 200 120 --window-size 800 400 --icon-size 100 --icon novelWriter.app 200 190 --hide-extension novelWriter.app \ - --app-drop-link 600 185 $RLS_DIR/novelWriter-"${VERSION}".dmg "$BUILD_DIR"/ - pushd $BUILD_DIR || exit 1 zip -qr novelWriter.app.zip novelWriter.app popd || exit 1 -mv $BUILD_DIR/novelWriter.app.zip $RLS_DIR/novelWriter-"${VERSION}".app.zip +mv -v $BUILD_DIR/novelWriter.app.zip $RLS_DIR/novelWriter-"${VERSION}"-macos.app.zip +echo "" + +# --- Create DMG -------------------------------------------------------------------------------- # + +# Generate .dmg +echo "Packageing DMG ..." +brew install create-dmg + +# "--skip-jenkins" is a temporary workaround for https://github.com/create-dmg/create-dmg/issues/72 +create-dmg --volname "novelWriter $VERSION" --volicon $SRC_DIR/setup/macos/novelwriter.icns \ + --window-pos 200 120 --window-size 800 400 --icon-size 100 \ + --icon novelWriter.app 200 190 --hide-extension novelWriter.app \ + --app-drop-link 600 185 $RLS_DIR/novelWriter-"${VERSION}"-macos.dmg "$BUILD_DIR"/ From d672ec05e947b7aed94ea71963bde862e22230d8 Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Sun, 12 Feb 2023 22:33:40 +0100 Subject: [PATCH 2/5] Fix artifact names --- .github/workflows/build.yml | 4 ++-- setup/macos/build.sh | 12 ------------ 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 88b16ebc..69179670 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -64,12 +64,12 @@ jobs: uses: actions/upload-artifact@v3 with: name: novelWriter-${{ env.VERSION }}-macos.app.zip - path: dist_macos/novelWriter-${{ env.VERSION }}.app.zip + path: dist_macos/novelWriter-${{ env.VERSION }}-macos.app.zip retention-days: 1 - name: Upload DMG uses: actions/upload-artifact@v3 with: name: novelWriter-${{ env.VERSION }}-macos.dmg - path: dist_macos/novelWriter-${{ env.VERSION }}.dmg + path: dist_macos/novelWriter-${{ env.VERSION }}-macos.dmg retention-days: 1 diff --git a/setup/macos/build.sh b/setup/macos/build.sh index ae7ff30f..af92b5f5 100755 --- a/setup/macos/build.sh +++ b/setup/macos/build.sh @@ -38,7 +38,6 @@ else echo "Missing: setup/macos/Info.plist" exit 1 fi -echo "" # Check that other assets are present echo "Checking assets" @@ -60,11 +59,9 @@ else echo "Missing: novelwriter/assets/i18n/nw_en_US.qm" exit 1 fi -echo "" echo "Content of current dir:" ls -lah . -echo "" popd || exit 1 pushd "$BUILD_DIR"/ || exit 1 @@ -77,17 +74,14 @@ curl -LO https://repo.continuum.io/miniconda/Miniconda3-latest-MacOSX-x86_64.sh bash Miniconda3-latest-MacOSX-x86_64.sh -b -p ~/miniconda -f rm Miniconda3-latest-MacOSX-x86_64.sh export PATH="$HOME/miniconda/bin:$PATH" -echo "" echo "Creating conda env ..." # create conda env conda create -n novelWriter -c conda-forge python=3.10 --yes source activate novelWriter -echo "" echo "installing dictionaries ..." conda install -c conda-forge enchant hunspell-en --yes -echo "" # Install dependencies echo "installing python dependencies ..." @@ -95,7 +89,6 @@ pip install -r "$SRC_DIR/requirements.txt" # Leave conda env conda deactivate -echo "" # --- Build App --------------------------------------------------------------------------------- # @@ -104,7 +97,6 @@ echo "Building app bundle ..." mkdir -p novelWriter.app/Contents/ mkdir novelWriter.app/Contents/MacOS novelWriter.app/Contents/Resources novelWriter.app/Contents/Resources/novelWriter cp $SRC_DIR/setup/macos/Info.plist novelWriter.app/Contents/Info.plist -echo "" echo "Copying miniconda env to bundle ..." cp -R ~/miniconda/envs/novelWriter/* novelWriter.app/Contents/Resources/ @@ -122,7 +114,6 @@ for file in "${FILES_COPY[@]}"; do done cp $SRC_DIR/setup/macos/novelwriter.icns novelWriter.app/Contents/Resources/ -echo "" # Create entry script echo "Creating entry script ..." @@ -134,7 +125,6 @@ EOF # Make it executable chmod a+x novelWriter.app/Contents/MacOS/novelWriter -echo "" # Do codesigning # echo "Signing bundle ..." @@ -167,7 +157,6 @@ rm lib/python3.*/site-packages/PyQt5/Qt/lib/libQt5WebEngine* || true popd || exit 1 popd || exit 1 -echo "" # --- Create App Bundle-------------------------------------------------------------------------- # @@ -179,7 +168,6 @@ zip -qr novelWriter.app.zip novelWriter.app popd || exit 1 mv -v $BUILD_DIR/novelWriter.app.zip $RLS_DIR/novelWriter-"${VERSION}"-macos.app.zip -echo "" # --- Create DMG -------------------------------------------------------------------------------- # From 8448ec7b61ebd2902d2a364fe4de2be5dd767ab5 Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Sun, 12 Feb 2023 23:27:15 +0100 Subject: [PATCH 3/5] Add AppImage to build workflow --- .github/workflows/build.yml | 65 ++++++++++++++++++++++++++++++------- setup.py | 12 ++++--- 2 files changed, 61 insertions(+), 16 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 69179670..76035171 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -20,13 +20,13 @@ jobs: - name: Checkout Source uses: actions/checkout@v3 - - name: Run Build Commands + - name: Build Assets run: python setup.py qtlrelease sample manual - name: Upload Artifacts uses: actions/upload-artifact@v3 with: - name: nw-assets-${{ github.sha }} + name: nw-assets path: | novelwriter/assets/sample.zip novelwriter/assets/manual.pdf @@ -34,6 +34,49 @@ jobs: if-no-files-found: error retention-days: 1 + buildLinux: + needs: buildAssets + runs-on: ubuntu-latest + env: + LINUX_TAG: "manylinux_2_28_x86_64" + PY_VER: "3.10" + steps: + - name: Python Setup + uses: actions/setup-python@v4 + with: + python-version: 3 + architecture: x64 + + - name: Install Packages (pip) + run: pip install python-appimage + + - name: Checkout Source + uses: actions/checkout@v3 + + - name: Get Version + shell: bash + run: | + NW_VER=$(python setup.py version) + echo "novelWriter Version: $NW_VER" + echo "VERSION=$NW_VER" >> $GITHUB_ENV + + - name: Download Artifacts + uses: actions/download-artifact@v3 + with: + name: nw-assets + path: novelwriter/assets + + - name: Build AppImage + run: python setup.py build-appimage --linux-tag {{env.LINUX_TAG}} --python-version {{env.PY_VER}} + + - name: Upload Artifacts + uses: actions/upload-artifact@v3 + with: + name: novelWriter-{{env.VERSION}}-py{{env.PY_VER}}-{{env.LINUX_TAG}}.AppImage + path: dist_appimage/novelWriter-{{env.VERSION}}-py{{env.PY_VER}}-{{env.LINUX_TAG}}.AppImage + if-no-files-found: error + retention-days: 1 + buildMac: needs: buildAssets strategy: @@ -46,21 +89,20 @@ jobs: - name: Get Version shell: bash run: | - NW_VERSION=`awk '/^__version__/{print substr($NF,2,length($NF)-2)}' novelwriter/__init__.py` - echo "novelWriter Version: $NW_VERSION" - echo "VERSION=$NW_VERSION" >> $GITHUB_ENV + NW_VER=$(python setup.py version) + echo "novelWriter Version: $NW_VER" + echo "VERSION=$NW_VER" >> $GITHUB_ENV - - name: Download Artifact + - name: Download Artifacts uses: actions/download-artifact@v3 with: - name: nw-assets-${{ github.sha }} + name: nw-assets path: novelwriter/assets - - name: Build - run: | - ./setup/macos/build.sh + - name: Build App Bundle + run: ./setup/macos/build.sh - - name: Upload ZIP + - name: Upload App Zip uses: actions/upload-artifact@v3 with: name: novelWriter-${{ env.VERSION }}-macos.app.zip @@ -72,4 +114,5 @@ jobs: with: name: novelWriter-${{ env.VERSION }}-macos.dmg path: dist_macos/novelWriter-${{ env.VERSION }}-macos.dmg + if-no-files-found: error retention-days: 1 diff --git a/setup.py b/setup.py index b54f3797..51fa65ae 100755 --- a/setup.py +++ b/setup.py @@ -42,7 +42,7 @@ OS_DARWIN = 3 # Utilities # =============================================================================================== # -def extractVersion(): +def extractVersion(beQuiet=False): """Extract the novelWriter version number without having to import anything else from the main package. """ @@ -67,7 +67,8 @@ def extractVersion(): print("Could not read file: %s" % initFile) print(str(exc)) - print("novelWriter version: %s (%s) at %s" % (numVers, hexVers, relDate)) + if not beQuiet: + print("novelWriter version: %s (%s) at %s" % (numVers, hexVers, relDate)) return numVers, hexVers, relDate @@ -935,7 +936,7 @@ def makeForLaunchpad(doSign=False, isFirst=False, isSnapshot=False): ## def makeAppImage(sysArgs): - """Build an Appimage + """Build an Appimage. """ import glob import argparse @@ -1882,6 +1883,7 @@ if __name__ == "__main__": "", " help Print the help message.", " pip Install all package dependencies for novelWriter using pip.", + " version Print the novelWriter version.", " build-clean Will attempt to delete 'build' and 'dist' folders.", "", "Additional Builds:", @@ -1939,8 +1941,8 @@ if __name__ == "__main__": if "version" in sys.argv: sys.argv.remove("version") - print("Checking source version info ...") - extractVersion() + numVers, _, _ = extractVersion(beQuiet=True) + print(numVers, end=None) sys.exit(0) if "pip" in sys.argv: From 0ab86913a70595e896138dcf6b23b031a8a00c82 Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Sun, 12 Feb 2023 23:32:11 +0100 Subject: [PATCH 4/5] Fix AppImage and MacOS builds --- .github/workflows/build.yml | 2 +- setup.py | 7 ------- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 76035171..999f925c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -89,7 +89,7 @@ jobs: - name: Get Version shell: bash run: | - NW_VER=$(python setup.py version) + NW_VER=$(python3 setup.py version) echo "novelWriter Version: $NW_VER" echo "VERSION=$NW_VER" >> $GITHUB_ENV diff --git a/setup.py b/setup.py index 51fa65ae..2734af6f 100755 --- a/setup.py +++ b/setup.py @@ -1028,13 +1028,6 @@ def makeAppImage(sysArgs): except OSError: print("Error while deleting file : ", image) - # Build Additional Assets - # ======================= - - buildQtI18n() - buildSampleZip() - buildPdfManual() - # Copy novelWriter Source # ======================= From 1aecf19a03e207a5890228b46cc69133f81b7e4e Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Sun, 12 Feb 2023 23:49:03 +0100 Subject: [PATCH 5/5] Fix environment vars --- .github/workflows/build.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 999f925c..04b77a26 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -67,13 +67,13 @@ jobs: path: novelwriter/assets - name: Build AppImage - run: python setup.py build-appimage --linux-tag {{env.LINUX_TAG}} --python-version {{env.PY_VER}} + run: python setup.py build-appimage --linux-tag ${{ env.LINUX_TAG }} --python-version ${{ env.PY_VER }} - name: Upload Artifacts uses: actions/upload-artifact@v3 with: - name: novelWriter-{{env.VERSION}}-py{{env.PY_VER}}-{{env.LINUX_TAG}}.AppImage - path: dist_appimage/novelWriter-{{env.VERSION}}-py{{env.PY_VER}}-{{env.LINUX_TAG}}.AppImage + name: novelWriter-${{ env.VERSION }}-py${{ env.PY_VER }}-${{ env.LINUX_TAG }}.AppImage + path: dist_appimage/novelWriter-${{ env.VERSION }}-py${{ env.PY_VER }}-${{ env.LINUX_TAG }}.AppImage if-no-files-found: error retention-days: 1