From d0b9339944a66558875aeedca552a6c550f4f091 Mon Sep 17 00:00:00 2001 From: David Ormrod Morley Date: Wed, 9 Oct 2024 12:09:18 +0200 Subject: [PATCH] Add a GitHub Actions workflow for automatic PyPi publishing whenever creating a new release --- .github/workflows/main.yml | 42 ---------------- .github/workflows/publish.yml | 94 +++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+), 42 deletions(-) delete mode 100644 .github/workflows/main.yml create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index 15db9dc2..00000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,42 +0,0 @@ -# This workflow tests the pip installation of plams in a variety of python versions - -name: PIP install PLAMS - -# Controls when the workflow will run -on: - # Triggers the workflow on push or pull request events but only for the "master" branch - push: - branches: [ "master" ] - pull_request: - branches: [ "master" ] - -# A workflow run is made up of one or more jobs that can run sequentially or in parallel -jobs: - # This workflow contains a single job called "build" - build: - name: Build for (${{ matrix.python-version }}, ${{ matrix.os }}) - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: ['ubuntu-latest'] - python-version: ['3.6', '3.7', '3.8', '3.9', '3.10'] - - # Steps represent a sequence of tasks that will be executed as part of the job - steps: - - uses: actions/checkout@v2 - - name: Setup conda - uses: s-weigand/setup-conda@v1 - with: - update-conda: false - python-version: ${{ matrix.python-version }} - conda-channels: anaconda, conda-forge - - run: conda --version - - run: python --version - - run: conda install python=${{ matrix.python-version }} "certifi=2021.5.30" - - name: Build - run: | - python -m pip install --prefer-binary . - - name: Test - run: | - python -c 'from scm.plams import *' diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 00000000..f8e6dad2 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,94 @@ +name: Publish to PyPi + +on: + release: + types: [published] + +jobs: + build-package: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.x' + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install setuptools wheel twine + + - name: Build package + run: python setup.py sdist bdist_wheel + + - name: Upload package artifact + uses: actions/upload-artifact@v4 + with: + name: package + path: dist + + test-package: + needs: build-package + + strategy: + matrix: + os: [ ubuntu-latest, macos-latest, windows-latest ] + python-version: [ "3.8", "3.9", "3.10", "3.11" ] + + runs-on: ${{ matrix.os }} + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set Up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + + - name: Download package artifact + uses: actions/download-artifact@v4 + with: + name: package + path: dist + + - name: Install package and dependencies + run: | + python -m pip install --upgrade pip + pip install dist/plams-*.whl + pip install ".[chem_tools,results]" + pip install pytest + + - name: Run Unit Tests + run: | + pytest unit_tests + + publish-package: + runs-on: ubuntu-latest + + needs: test-package + + environment: release + + permissions: + id-token: write + + steps: + - uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.x' + + - name: Download package artifact + uses: actions/download-artifact@v4 + with: + name: package + path: dist + + - name: Publish package + uses: pypa/gh-action-pypi-publish@release/v1 \ No newline at end of file