Skip to content

Commit

Permalink
new-feature: create binaries with GitHub Actions (#142)
Browse files Browse the repository at this point in the history
Co-authored-by: Renaud <[email protected]>
Co-authored-by: renaudjester <[email protected]>
  • Loading branch information
3 people authored Sep 25, 2024
1 parent 4c633fe commit 839a9a3
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 0 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/binaries.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Create Binaries

on:
push:
branches:
- main
- 'pre-releases/**'

jobs:
build:
strategy:
fail-fast: false
matrix:
os: [windows-latest, macos-latest, ubuntu-latest, macos-13]
runs-on: ${{ matrix.os }}
timeout-minutes: 20

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Install dependencies
id: set-version
run: |
make build-and-prepare-for-binary
- name: Build with PyInstaller
run: |
make run-using-pyinstaller-${{ matrix.os }}
- name: Upload binaries to windows
env:
GH_TOKEN: ${{ github.token }}
if: matrix.os == 'windows-latest'
run: |
$WIN_VERSION = poetry version --short
gh release upload v$WIN_VERSION dist/copernicusmarine.exe#copernicusmarine-binary-windows-for-v$WIN_VERSION
- name: Upload binaries to macos or ubuntu
env:
GH_TOKEN: ${{ github.token }}
if: matrix.os != 'windows-latest'
run: |
if [ "${{ matrix.os }}" == "macos-latest" ]; then
ARCH="macos-arm64"
elif [ "${{ matrix.os }}" == "macos-13" ]; then
ARCH="macos-x86_64"
elif [ "${{ matrix.os }}" == "ubuntu-latest" ]; then
ARCH="linux"
fi
gh release upload v${{steps.set-version.outputs.VERSION}} dist/copernicusmarine_${ARCH}.cli#copernicusmarine-binary-${ARCH}-for-v${{steps.set-version.outputs.VERSION}}
20 changes: 20 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@ run-tests-dependencie-versions:
${ACTIVATE_ENVIRONMENT}
tox run

run-using-pyinstaller-windows-latest:
python -m PyInstaller --copy-metadata xarray --name copernicusmarine.exe --add-data "c:\hostedtoolcache\windows\python\3.12.6\x64\lib\site-packages\distributed\distributed.yaml;.\distributed" copernicusmarine/command_line_interface/copernicus_marine.py --onefile

run-using-pyinstaller-macos-latest:
python -m PyInstaller --name copernicusmarine_macos-arm64.cli copernicusmarine/command_line_interface/copernicus_marine.py --onefile --target-architecture=arm64

run-using-pyinstaller-macos-13:
python -m PyInstaller --name copernicusmarine_macos-x86_64.cli copernicusmarine/command_line_interface/copernicus_marine.py --onefile --target-architecture=x86_64

run-using-pyinstaller-ubuntu-latest:
python3 -m PyInstaller --name copernicusmarine_linux.cli --add-data="/opt/hostedtoolcache/Python/3.12.6/x64/lib/python3.12/site-packages/distributed/distributed.yaml:./distributed" copernicusmarine/command_line_interface/copernicus_marine.py --onefile --path /opt/hostedtoolcache/Python/3.12.6/x64/lib/python3.12/site-packages --copy-metadata xarray
chmod +rwx ./dist/copernicusmarine_linux.cli

release: SELECTED_ENVIRONMENT_NAME = ${ENVIRONMENT_NAME}
release:
${ACTIVATE_ENVIRONMENT}
Expand Down Expand Up @@ -91,6 +104,13 @@ build-and-publish-dockerhub-image:
docker push copernicusmarine/copernicusmarine:$${VERSION}
docker push copernicusmarine/copernicusmarine:latest

build-and-prepare-for-binary:
python -m pip install --upgrade pip
pip install pyinstaller
pip install -e .
pip install poetry
pip install distributed
echo "VERSION=$$(poetry version --short)" >> ${GITHUB_OUTPUT}

update-snapshots-tests:
pytest --snapshot-update tests/test_command_line_interface.py::TestCommandLineInterface::test_describe_including_datasets
71 changes: 71 additions & 0 deletions doc/usage/installation.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
===================================================
Installing Copernicus Marine Toolbox
===================================================

There are several ways to install or use the Copernicus Marine Toolbox:

* via pip `pypi`_
* via conda `conda-forge`_
* via docker `dockerhub`_

Alternatively, you can use a binary.

Via pip
**************

.. code-block:: bash
pip install copernicusmarine
.. note:: Requires Python 3.9 or higher.

Via conda (conda-forge channel)
******************************************

.. code-block:: bash
conda install -c conda-forge copernicusmarine
Via docker
**************

.. code-block:: bash
docker run -it copernicusmarine/copernicusmarine
Create an account on Copernicus Marine website
***********************************************

To be able to use the Copernicus Marine Toolbox, you need to have an account on the Copernicus Marine website. You can create an account here `copernicusmarine-register`_.

.. _pypi: https://pypi.org/project/copernicusmarine/
.. _conda-forge: https://anaconda.org/conda-forge/copernicusmarine
.. _dockerhub: https://hub.docker.com/r/copernicusmarine/copernicusmarine
.. _copernicusmarine-register: https://data.marine.copernicus.eu/register

Use the CopernicusMarine Toolbox binaries
***********************************************

In the `release page <https://github.com/mercator-ocean/copernicus-marine-toolbox/releases>`_ you can access the binaries of the latest releases. Once downloaded for the specific platform, you can use the toolbox by running the binary as follows:

In mac-os or linux:

.. code-block:: bash
./copernicusmarine_macos-latest.cli describe
(``describe`` or any other command)

You might have to update the permissions of the binary to be able to execute it with linux:

.. code-block:: bash
chmod +rwx cmt_ubuntu-latest.cli
And from a Windows os (cmd):

.. code-block:: bash
copernicusmarine_windows-latest.exe describe
(``describe`` or any other command)

0 comments on commit 839a9a3

Please sign in to comment.