|
| 1 | +name: Add built assets to latest release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + |
| 6 | +permissions: |
| 7 | + contents: write |
| 8 | + |
| 9 | +jobs: |
| 10 | + get_tag: |
| 11 | + # get the latest tag (separate job as Windows doesn't support this method) |
| 12 | + # straightforward because in this repository tags are used only for releases, but we could do a regex match if not |
| 13 | + runs-on: ubuntu-latest |
| 14 | + outputs: |
| 15 | + output: ${{ steps.latest_tag.outputs.tag }} |
| 16 | + |
| 17 | + steps: |
| 18 | + - uses: actions/checkout@v4 |
| 19 | + - id: latest_tag |
| 20 | + run: | |
| 21 | + git fetch -a |
| 22 | + echo "tag=$(git tag --sort -committerdate | head -n 1)" >> $GITHUB_OUTPUT |
| 23 | +
|
| 24 | + build: |
| 25 | + needs: get_tag |
| 26 | + |
| 27 | + runs-on: ${{ matrix.os }} |
| 28 | + strategy: |
| 29 | + fail-fast: false |
| 30 | + matrix: |
| 31 | + os: [macos-latest, windows-latest] |
| 32 | + |
| 33 | + steps: |
| 34 | + - uses: actions/checkout@v4 |
| 35 | + - uses: actions/setup-python@v5 |
| 36 | + with: |
| 37 | + python-version: '3.x' |
| 38 | + |
| 39 | + # install requirements |
| 40 | + # - note: `imageio` is required here to convert our PNG icon to a format nuitka can handle (nuitka itself is a separate action) |
| 41 | + # - note: `certifi` is required here because pyinstaller no longer bundles certificates (pyinstaller #7229) |
| 42 | + # - note: `boto3`, `requests`, `google-auth` and corresponding pyinstaller hidden imports / nuitka included |
| 43 | + # packages are so that advanced proxy features work in pre-built binaries |
| 44 | + # - note: `--hidden-import timeago.locales.en_short` is required for GUI mode until `timeago` #40 is fixed |
| 45 | + - run: | |
| 46 | + python -m pip install --upgrade pip |
| 47 | + python -m pip install wheel |
| 48 | + python -m pip install pyinstaller imageio |
| 49 | + python -m pip install -r requirements-core.txt -r requirements-gui.txt |
| 50 | + python -m pip install certifi |
| 51 | + python -m pip install boto3 requests google-auth |
| 52 | +
|
| 53 | + # build the pyinstaller version (same method for both macOS and Windows), outputting to the folder `dist` |
| 54 | + - run: python -m PyInstaller --clean --noconsole --onefile --hidden-import prompt_toolkit --hidden-import timeago.locales.en_short --hidden-import certifi --hidden-import boto3 --hidden-import requests --hidden-import google --hidden-import jwt --icon icon.png --distpath dist/ emailproxy.py |
| 55 | + |
| 56 | + # add license, documentation, configuration file sample and disclaimer |
| 57 | + # - note: `move [...] alias move=mv [...]` is to support using the same commands on all platforms |
| 58 | + - run: | |
| 59 | + move LICENSE . 2> nul || { shopt -s expand_aliases; alias move=mv; } |
| 60 | + move LICENSE dist/ |
| 61 | + move README.md dist/ |
| 62 | + move emailproxy.config dist/ |
| 63 | + echo 'This binary distribution is automatically created for each Email OAuth 2.0 Proxy release, ' >> _.txt |
| 64 | + echo 'but is not tested, and is not officially supported. Using the main emailproxy.py script ' >> _.txt |
| 65 | + echo 'directly is recommended for best results: https://github.com/simonrob/email-oauth2-proxy/' >> _.txt |
| 66 | + move _.txt dist/GettingStarted.txt |
| 67 | +
|
| 68 | + # on macOS pyinstaller `--onefile` creates bundle *and* binary; we don't need both (and the .app also contains the binary) |
| 69 | + - if: runner.os == 'macOS' |
| 70 | + run: rm dist/emailproxy |
| 71 | + |
| 72 | + # zip the built pyinstaller output, naming according to tag and OS |
| 73 | + - uses: thedoctor0/[email protected] |
| 74 | + with: |
| 75 | + type: zip |
| 76 | + directory: dist/ |
| 77 | + filename: emailproxy-${{ needs.get_tag.outputs.output }}_pyinstaller-${{ runner.os }}.zip |
| 78 | + |
| 79 | + # append the pyinstaller zip to the latest release |
| 80 | + - uses: xresloader/[email protected] |
| 81 | + with: |
| 82 | + file: dist/*.zip |
| 83 | + update_latest_release: true |
| 84 | + |
| 85 | + # clean up pyinstaller assets and add platform-specific nuitka configuration options (`move` alias usage as above) |
| 86 | + - run: | |
| 87 | + rm dist/emailproxy-${{ needs.get_tag.outputs.output }}_pyinstaller-${{ runner.os }}.zip |
| 88 | + move emailproxy.py . 2> nul || { shopt -s expand_aliases; alias move=mv; } |
| 89 | + move emailproxy.py _.py |
| 90 | + echo '# nuitka-project-if: {OS} in ("Windows"):' >> _.txt |
| 91 | + echo '# nuitka-project: --windows-icon-from-ico=icon.png' >> _.txt |
| 92 | + echo '# nuitka-project-if: {OS} == "Darwin":' >> _.txt |
| 93 | + echo '# nuitka-project: --macos-app-icon=icon.png' >> _.txt |
| 94 | + move _.txt emailproxy.py |
| 95 | + cat _.py >> emailproxy.py |
| 96 | +
|
| 97 | + # build the nuitka version - by default, this uses the options `--mode=app --assume-yes-for-downloads --output-dir=build` (see: https://github.com/Nuitka/Nuitka-Action/blob/main/action.yml) |
| 98 | + - uses: Nuitka/Nuitka-Action@main |
| 99 | + with: |
| 100 | + nuitka-version: main |
| 101 | + script-name: emailproxy.py |
| 102 | + include-package: | |
| 103 | + prompt_toolkit |
| 104 | + timeago.locales.en_short |
| 105 | + certifi |
| 106 | + boto3 |
| 107 | + requests |
| 108 | + google |
| 109 | + jwt |
| 110 | + nofollow-import-to: '*.tests' |
| 111 | + |
| 112 | + # replace previous build files (-f vs. -fo behaviour differences mean we can't combine); add macOS quarantine tips |
| 113 | + - if: runner.os == 'macOS' |
| 114 | + run: | |
| 115 | + rm -rf dist/emailproxy.app/ |
| 116 | + echo "\nIf macOS says the app is damaged, run `xattr -dr com.apple.quarantine emailproxy.app`" >> dist/GettingStarted.txt |
| 117 | + echo 'If you still have problems, try no-GUI mode: `emailproxy.app/Contents/MacOS/emailproxy --no-gui`' >> dist/GettingStarted.txt |
| 118 | + mv build/emailproxy.app/ dist/ |
| 119 | +
|
| 120 | + - if: runner.os == 'Windows' |
| 121 | + run: | |
| 122 | + rm dist/emailproxy.exe |
| 123 | + move build/emailproxy.exe dist/ |
| 124 | +
|
| 125 | + # zip the built nuitka output, naming according to tag and OS |
| 126 | + - uses: thedoctor0/[email protected] |
| 127 | + with: |
| 128 | + type: zip |
| 129 | + directory: dist/ |
| 130 | + filename: emailproxy-${{ needs.get_tag.outputs.output }}_nuitka-${{ runner.os }}.zip |
| 131 | + |
| 132 | + # append the nuitka zip to the latest release |
| 133 | + - uses: xresloader/[email protected] |
| 134 | + with: |
| 135 | + file: dist/*.zip |
| 136 | + update_latest_release: true |
0 commit comments