Skip to content

Commit

Permalink
chore: Merge non-code changes into main (#69)
Browse files Browse the repository at this point in the history
build: update to create a standalone executable (#66)

* ci: add executable to release workflow

* ci: modify semantic-release pr requests to choose between release and chore

* docs: update readme to show standalone version is available

* ci: create reusable testing workflow

---------

Signed-off-by: David Hart <[email protected]>
Co-authored-by: David Hart <[email protected]>
  • Loading branch information
github-actions[bot] and dbhart authored Oct 23, 2024
1 parent 951ebbd commit b24e801
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 33 deletions.
109 changes: 86 additions & 23 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
name: Build and publish Python 🐍 distribution 📦 to PyPI
name: Build - Publish - Release

on:
push:
branches:
- 'main'
- 'executable'
paths-ignore:
- '.github/**'
- '!.github/workflows/release.yml'
Expand All @@ -16,52 +17,98 @@ permissions:
contents: read

jobs:
build_executable:
name: Build standalone executable for Windows
runs-on: [windows-latest]
continue-on-error: true
env:
sansmic_version: 0.0.0+local
sha_short: unreal

steps:
- name: Setup | Install python
uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3 # v5.2.0
with:
python-version: '3.12'

- name: Setup | Checkout Code
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1

- name: Setup | Install Dependencies
run: |
pip install -r requirements.txt -r requirements-exe.txt
pip install .
python setup.py build_ext -i
- name: Setup | Get the sansmic version number
id: vars
run: |
python -c "import sansmic; print('sansmic_version='+sansmic.__version__)" >> $Env:GITHUB_ENV
echo "sha_short=$(git rev-parse --short HEAD)" >> $Env:GITHUB_ENV
- name: Action | Run PyInstaller
run: |
pyinstaller --collect-all sansmic --collect-all click --hidden-import sansmic --hidden-import click --hidden-import pandas --hidden-import pybind11 --hidden-import numpy --hidden-import h5py --hidden-import pyyaml --hidden-import lasio -n sansmic --add-binary src/python/sansmic/libsansmic.cp312-win_amd64.pyd:sansmic src/python/sansmic/app.py
- name: Action | Create examples
run: |
mkdir dist/sansmic/examples
sansmic-convert tests/baseline.dat dist/sansmic/examples/baseline.toml
- name: Action | Upload Artifacts
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
with:
name: "sansmic-${{ env.sansmic_version }}-standalone-win_amd64"
path: ./dist/sansmic

build_wheels:
name: Build distribution 📦 on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
if: ${{ startsWith(github.ref, 'refs/tags/') && github.repository == 'sandialabs/sansmic' }} # only publish to PyPI on tag pushes
strategy:
matrix:
# macos-13 is an intel runner, macos-14 is apple silicon
os: [ubuntu-latest, windows-latest, macos-13, macos-14]

steps:
- name: Harden Runner
- name: Setup | Harden Runner
uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1
with:
egress-policy: audit

- uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
- name: Setup | Checkout Code
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1

- uses: pypa/cibuildwheel@7940a4c0e76eb2030e473a5f864f291f63ee879b # v2.21.0
# ...
# with:
# package-dir: .
# output-dir: wheelhouse
# config-file: "{package}/pyproject.toml"
- name: Action | Build Wheels
uses: pypa/cibuildwheel@7940a4c0e76eb2030e473a5f864f291f63ee879b # v2.21.0

- uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
- name: Action | Upload Artifacts
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
with:
name: cibw-wheels-${{ matrix.os }}-${{ strategy.job-index }}
path: ./wheelhouse/*.whl

make_sdist:
name: Make SDist artifact 📦
runs-on: ubuntu-latest
if: ${{ startsWith(github.ref, 'refs/tags/') && github.repository == 'sandialabs/sansmic' }} # only publish to PyPI on tag pushes
steps:
- name: Harden Runner
- name: Setup | Harden Runner
uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1
with:
egress-policy: audit

- uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
- name: Setup | Checkout Code
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
with:
fetch-depth: 0 # Optional, use if you use setuptools_scm
submodules: true # Optional, use if you have submodules

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

- uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
- name: Action | Upload Artifacts
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
with:
name: cibw-sdist
path: dist/*.tar.gz
Expand All @@ -80,13 +127,14 @@ jobs:
id-token: write # IMPORTANT: mandatory for trusted publishing

steps:
- name: Download all the dists
- name: Setup | Download all the dists
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
with:
pattern: cibw-*
path: dist
merge-multiple: true
- name: Publish distribution 📦 to TestPyPI

- name: Action | Publish distribution 📦 to TestPyPI
uses: pypa/gh-action-pypi-publish@f7600683efdcb7656dec5b29656edb7bc586e597 # release/v1
with:
skip-existing: true
Expand All @@ -106,19 +154,21 @@ jobs:
permissions:
id-token: write
runs-on: ubuntu-latest

steps:
- name: Harden Runner
- name: Setup | Harden Runner
uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1
with:
egress-policy: audit

- name: Download all the dists
- name: Setup | Download all the dists
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
with:
pattern: cibw-*
path: dist
merge-multiple: true
- name: Publish distribution 📦 to PyPI

- name: Setup | Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@f7600683efdcb7656dec5b29656edb7bc586e597 # release/v1
with:
attestations: true
Expand All @@ -131,33 +181,46 @@ jobs:
needs:
- publish-to-pypi
runs-on: ubuntu-latest
if: ${{ startsWith(github.ref, 'refs/tags/') && github.repository == 'sandialabs/sansmic' }} # only publish to PyPI on tag pushes

permissions:
contents: write # IMPORTANT: mandatory for making GitHub Releases
id-token: write # IMPORTANT: mandatory for sigstore

steps:
- name: Download all the dists
- name: Setup | Download all the dists
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
with:
pattern: cibw-*
path: dist
merge-multiple: true
- name: Sign the dists with Sigstore

- name: Setup | Download the standalone executable
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
with:
pattern: sansmic-*-standalone-win_amd64
path: dist
merge-multiple: true

- name: Action | Sign the dists with Sigstore
uses: sigstore/gh-action-sigstore-python@f514d46b907ebcd5bedc05145c03b69c1edd8b46 # v3.0.0
with:
inputs: >-
./dist/*.zip
./dist/*.tar.gz
./dist/*.whl
- name: Create GitHub Release
- name: Action | Create GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
run: >-
gh release create
'${{ github.ref_name }}'
--repo '${{ github.repository }}'
--notes ""
- name: Upload artifact signatures to GitHub Release
- name: Action | Upload artifact signatures to GitHub Release
if: success() || failure()
env:
GITHUB_TOKEN: ${{ github.token }}
# Upload to GitHub Release using the `gh` CLI.
Expand Down
35 changes: 26 additions & 9 deletions .github/workflows/semantic-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ jobs:
release:
runs-on: ubuntu-latest
concurrency: release
if: ${{ github.repository == 'sandialabs/sansmic' }} # do not run everywhere

permissions:
id-token: write
Expand All @@ -34,10 +35,25 @@ jobs:
run: |
git checkout -B ${{ github.ref_name }} ${{ github.sha }}
- name: Action | Semantic Version Release
- name: Action | Check if release is needed
id: release
# Adjust tag with desired version if applicable.
uses: python-semantic-release/python-semantic-release@c1bcfdbb994243ac7cf419365d5894d6bfb2950e # v9.12.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
git_committer_name: "github-actions"
git_committer_email: "[email protected]"
build: false
changelog: false
commit: false
push: false
tag: false
vcs_release: false

- name: Action | Semantic Release - Update version
if: steps.release.outputs.released == 'true'
# Adjust tag with desired version if applicable.
uses: python-semantic-release/python-semantic-release@c1bcfdbb994243ac7cf419365d5894d6bfb2950e # v9.12.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
git_committer_name: "github-actions"
Expand All @@ -49,15 +65,16 @@ jobs:
tag: false
vcs_release: false

- name: create pull request
- name: Action | Create Pull Request - Release
if: steps.release.outputs.released == 'true'
run: |
gh pr create -B main -H staging --title 'Merge staging into main' --body 'Created by Github action: semantic-release.yml'
gh pr create -B main -H staging --title "release: Merge into main and create tag as v${{ steps.release.outputs.version }}" --body 'Created by Github action: semantic-release.yml'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

#- name: Publish | Upload to GitHub Release Assets
# uses: python-semantic-release/publish-action@3dccc469c6577f385b5e844ed29677fb1f4cb4b6 # v9.10.1
# if: steps.release.outputs.released == 'true'
# with:
# github_token: ${{ secrets.GITHUB_TOKEN }}
# tag: ${{ steps.release.outputs.tag }}
- name: Action | Create Pull Request - Chore
if: steps.release.outputs.released == 'false'
run: |
gh pr create -B main -H staging --title 'chore: Merge non-code changes into main' --body 'Created by Github action: semantic-release.yml'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ numpy and pandas packages.
Installation can be accomplished most easily by using the PyPI.
It can also be installed by downloading a wheel from the [releases]
in this repository, or by cloning this repository and building it
yourself.
yourself. Finally, a standalone executable has been created that
will be added to each release for Windows users that are unable
due to install Python on their corporate computers (see the releases
on the right side of the page).


#### PyPI wheels
To install a pre-compiled version of sansmic, use the pip command
Expand Down
6 changes: 6 additions & 0 deletions requirements-exe.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
h5py==3.12.1
openpyxl==3.1.5
tabulate==0.9.0
lasio==0.31
pyinstaller==6.11.0
pyyaml==6.0.2
4 changes: 4 additions & 0 deletions src/python/sansmic/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,3 +492,7 @@ def convert(dat_file, out_file=None, full=False):
logger.critical(str(e))
raise e
logger.debug("Successfully wrote scenario to {}".format(out_file))


if __name__ == "__main__":
run()

0 comments on commit b24e801

Please sign in to comment.