Skip to content

Commit

Permalink
Merge pull request #2 from ericpre/add_github_action
Browse files Browse the repository at this point in the history
Add GitHub action
  • Loading branch information
ericpre authored Aug 26, 2023
2 parents f48a036 + 8c33a8f commit 79a8db8
Show file tree
Hide file tree
Showing 10 changed files with 244 additions and 262 deletions.
69 changes: 69 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Build

on: [push, pull_request]

jobs:
build:
name: Build
runs-on: ubuntu-latest
env:
PYTHON_VERSION: '3.11'
steps:
- uses: actions/checkout@v3

- uses: actions/setup-python@v4
name: Install Python
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Display version
run: |
python --version
pip --version
- name: Install pypa/build
run: |
pip install build
- name: Build a binary wheel and a source tarball
run: |
python -m build
- name: Display content dist folder
run: |
ls -l dist/
- uses: actions/upload-artifact@v3
with:
path: ./dist/*
name: dist

test:
name: Test Packaging
needs: build
runs-on: ubuntu-latest
env:
PYTHON_VERSION: '3.11'
steps:
- uses: actions/setup-python@v4
name: Install Python
with:
python-version: ${{ env.PYTHON_VERSION }}

- uses: actions/download-artifact@v3

- name: Display content working folder
run: |
ls -R
- name: Install HyperSpy (dev)
run: |
pip install https://github.com/hyperspy/hyperspy/archive/refs/heads/RELEASE_next_major.zip
- name: Install distribution
run: |
pip install --pre --find-links dist holospy[tests]
- name: Test distribution
run: |
pytest --pyargs holospy
85 changes: 85 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: Release

# This workflow builds the wheels "on tag".
# If run from the hyperspy/hyperspy repository, the wheels will be uploaded to pypi ;
# otherwise, the wheels will be available as a github artifact.
on:
push:
# Sequence of patterns matched against refs/tags
tags:
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10

jobs:
build_wheels:
name: Build wheels
runs-on: ubuntu-latest
env:
CIBW_TEST_COMMAND: "pytest --pyargs holospy"
CIBW_TEST_EXTRAS: "tests"

steps:
- uses: actions/checkout@v3

- name: Build wheels
uses: pypa/[email protected]

- uses: actions/upload-artifact@v3
with:
name: wheels
path: ./wheelhouse/*.whl
if-no-files-found: error

make_sdist:
name: Make SDist
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Build SDist
run: pipx run build --sdist

- uses: actions/upload-artifact@v3
with:
path: dist/*.tar.gz

upload_to_pypi:
needs: [build_wheels, make_sdist]
runs-on: ubuntu-latest
permissions:
# IMPORTANT: this permission is mandatory for trusted publishing
id-token: write
steps:
- name: Download dist
uses: actions/download-artifact@v3
with:
name: artifact
path: dist

- name: Download wheels
uses: actions/download-artifact@v3
with:
name: wheels
path: dist

- name: Display structure of downloaded files
run: ls -R
working-directory: dist

- uses: pypa/gh-action-pypi-publish@release/v1
if: github.repository_owner == 'hyperspy'
# See https://docs.pypi.org/trusted-publishers/using-a-publisher/

create_release:
# TODO: once we are happy with the workflow
# setup zenodo to create a DOI automatically
needs: upload_to_pypi
permissions:
contents: write
name: Create Release
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Create Release
id: create_release
uses: softprops/action-gh-release@de2c0eb89ae2a093876385947365aca7b0e5f844
57 changes: 57 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Tests

on: [push, pull_request]

jobs:
run_test_site:
name: ${{ matrix.os }}-py${{ matrix.PYTHON_VERSION }}${{ matrix.LABEL }}
runs-on: ${{ matrix.os }}-latest
timeout-minutes: 30
env:
MPLBACKEND: agg
strategy:
fail-fast: false
matrix:
os: [ubuntu, windows, macos]
PYTHON_VERSION: ['3.9', '3.10']
LABEL: ['']
include:
- os: ubuntu
PYTHON_VERSION: '3.8'
- os: ubuntu
PYTHON_VERSION: '3.11'

steps:
- uses: actions/checkout@v3

- uses: actions/setup-python@v4
name: Install Python
with:
python-version: ${{ matrix.PYTHON_VERSION }}

- name: Display version
run: |
python --version
pip --version
- name: Install (HyperSpy dev)
# Need to install hyperspy dev until hyperspy 2.0 is released
run: |
pip install https://github.com/hyperspy/hyperspy/archive/refs/heads/RELEASE_next_major.zip
- name: Install
shell: bash
run: |
pip install -e .[tests]
- name: Pip list
run: |
pip list
- name: Run test suite
run: |
pytest --pyargs holospy
- name: Upload coverage to Codecov
if: ${{ always() }}
uses: codecov/codecov-action@v3
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/docs/_build/*
/build/*
/dist/*
/holospy.egg-info/*
*__pycache__*
*pyd
.spyproject/*
.idea
22 changes: 22 additions & 0 deletions holospy/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
# Copyright 2007-2023 The HyperSpy developers
#
# This file is part of HyperSpy.
#
# HyperSpy is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# HyperSpy is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with HyperSpy. If not, see <https://www.gnu.org/licenses/#GPL>.

import matplotlib

def pytest_configure(config):
matplotlib.use('agg')
Loading

0 comments on commit 79a8db8

Please sign in to comment.