run-github-workflows #118
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: run-github-workflows | |
on: | |
push: | |
branches: [ main ] | |
pull_request: | |
branches: [ main ] | |
workflow_dispatch: | |
jobs: | |
solve-environments-and-upload-files: | |
name: run tcy, create environment, and export environment files | |
strategy: | |
fail-fast: false | |
matrix: | |
os: [ubuntu-latest,windows-latest] | |
runs-on: ${{ matrix.os }} | |
permissions: | |
contents: write | |
defaults: | |
run: | |
shell: bash -el {0} | |
steps: | |
- name: checkout repository | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.head_ref }} | |
- name: setup a python environment | |
uses: actions/setup-python@v5 | |
with: | |
python-version: 3.11 | |
- name: install pip-packages in that python environment including tcy | |
run: | | |
python -m pip install --upgrade pip | |
python -m pip install tcy | |
python -m pip install pandas | |
python -m pip install pytest | |
- name: run tcy to create a .yml file for Linux (will be skipped for windows-latest runner) | |
if: runner.os == 'Linux' | |
run: tcy linux --yml_name=${{ matrix.os }} --yml_dir=./environments --yml_file_name=${{ matrix.os }}.yml --tsv_path=./environments/packages.tsv --necessity=required | |
- name: run tcy.py to create a .yml file for Windows (will be skipped for ubuntu-latest runner) | |
if: runner.os == 'Windows' | |
run: tcy windows --yml_name=${{ matrix.os }} --yml_dir=./environments --yml_file_name=${{ matrix.os }}.yml --tsv_path=./environments/packages.tsv --necessity=required | |
- name: setup micromamba and create an environment using the .yml file that tcy produced | |
uses: mamba-org/setup-micromamba@v1 | |
with: | |
environment-file: ./environments/${{ matrix.os }}.yml | |
environment-name: ${{ matrix.os }} | |
- name: initialize conda for Git Bash (will be skipped for linux runner) | |
if: runner.os == 'Windows' | |
run: echo ". /c/Miniconda/etc/profile.d/conda.sh" >> ~/.bash_profile | |
- name: export conda environment both as .yml file and as a spec-file.txt and export the pip-packages as requirements.txt file | |
run: | | |
conda env export -p "${MAMBA_ROOT_PREFIX}/envs/${{ matrix.os }}" | grep -v "^prefix: " | sed -E 's/^name:.*(ubuntu-latest|windows-latest)/name: \1/' > ./environments/${{ matrix.os }}_solved.yml | |
conda list -p "${MAMBA_ROOT_PREFIX}/envs/${{ matrix.os }}" --explicit > ./environments/${{ matrix.os }}_solved.txt | |
pip freeze | grep -v "@ file" > ./environments/${{ matrix.os }}_solved_pip-requirements.txt | |
- name: upload exported files as artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ matrix.os }} | |
path: | | |
./environments/${{ matrix.os }}.yml | |
./environments/${{ matrix.os }}_solved.yml | |
./environments/${{ matrix.os }}_solved.txt | |
./environments/${{ matrix.os }}_solved_pip-requirements.txt | |
download-artifacts-and-push: | |
name: download all files that where created by the runners and push them to repo (but only if something has changed) | |
if: ${{ always() }} | |
needs: solve-environments-and-upload-files | |
runs-on: ubuntu-latest | |
steps: | |
- name: checkout repository | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.head_ref }} | |
- name: download all files that were created using different operating systems | |
uses: actions/download-artifact@v4 | |
with: | |
path: ./environments | |
- name: add and commit files (but only if something has changed) | |
uses: stefanzweifel/git-auto-commit-action@v5 |