Skip to content

Commit

Permalink
splitting into test and release workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
aeturrell committed Jan 2, 2025
1 parent dfc6d55 commit ffc5397
Show file tree
Hide file tree
Showing 8 changed files with 187 additions and 14 deletions.
111 changes: 111 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
name: release

permissions:
contents: write
pages: write

on:
push:
branches:
- main

jobs:
release:
name: release
runs-on: ubuntu-latest
steps:
- name: Check out the repository
uses: actions/checkout@v4
with:
fetch-depth: 2

- name: install mamba
uses: mamba-org/setup-micromamba@v2
with:
environment-file: environment.yml
init-shell: >-
bash
cache-environment: true
post-cleanup: 'all'

- name: set timezone
run: |
TZ="Europe/London" &&
sudo ln -snf /usr/share/zoneinfo/$TZ /etc/localtime
- name: install linux deps
run: |
sudo apt-get -y install openssl graphviz nano texlive graphviz-dev unzip
- name: install special fonts
run: |
mkdir -p /usr/share/fonts/truetype/ &&
wget https://www.wfonts.com/download/data/2015/10/08/varta/varta.zip &&
unzip varta.zip &&
install -m644 *.ttf /usr/share/fonts/truetype/ &&
rm *.ttf
rm varta.zip
- name: install text models
run: |
micromamba run -n codeforecon python3 -m spacy download en_core_web_sm &&
micromamba run -n codeforecon python3 -m nltk.downloader all
- name: special fix for todoify
run: |
sed -i '90 s/^/#/' /home/runner/micromamba/envs/codeforecon/lib/python3.10/site-packages/mdit_py_plugins/tasklists/__init__.py
# Issue with pymc needing np<2.0 and skimpy needing >2.0, so pip install of latter causes upgrade to np
- name: special fix for numpy
run: |
micromamba run -n codeforecon pip install --force-reinstall -v "numpy==1.26"
- name: Monkey patch for binsreg # sets np.math = math
run: |
sed -i '/^import\|^from.*import/ { :a; n; /^import\|^from.*import/! { x; s/.*//; x; ba; }; }; a\import math\nimport numpy as np\nnp.math = math' ~/micromamba/envs/codeforecon/lib/python3.10/site-packages/binsreg/funs.py
- name: git config # Needed as git config --get user.name is used in one example
run: |
git config user.name "$(git log -n 1 --pretty=format:%an)" &&
git config user.email "$(git log -n 1 --pretty=format:%ae)"
- name: build the book
run: |
micromamba run -n codeforecon jupyter-book build . --verbose
- name: Check if there is a parent commit
id: check-parent-commit
run: |
echo "::set-output name=sha::$(git rev-parse --verify --quiet HEAD^)"
- name: Detect and tag new version
id: check-version
if: steps.check-parent-commit.outputs.sha
uses: salsify/[email protected]
with:
version-command: |
micromamba run -n codeforecon toml get --toml-path=pyproject.toml project.version
- name: Bump version for developmental release
if: "! steps.check-version.outputs.tag"
run: |
micromamba run -n codeforecon python version_bumper.py &&
version=$(micromamba run -n codeforecon toml get --toml-path=pyproject.toml project.version) &&
micromamba run -n codeforecon toml set --toml-path=pyproject.toml project.version $version.dev.$(date +%s)
- name: Publish
if: steps.check-version.outputs.tag
run: ghp-import -n -p -f _build/html

- name: Publish the release notes
uses: release-drafter/[email protected]
with:
publish: ${{ steps.check-version.outputs.tag != '' }}
tag: ${{ steps.check-version.outputs.tag }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Success
if: steps.check-version.outputs.tag
run: |
echo "Success in releasing a new version of Coding for Economists!"
26 changes: 12 additions & 14 deletions .github/workflows/build.yml → .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
name: build

# permissions:
# contents: write
# pages: write
name: tests

on:
push:
branches:
- build-book-action

pull_request:

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10.6'
- uses: pre-commit/[email protected]

build:
name: build
runs-on: ubuntu-latest
steps:
- name: Check out the repository
Expand Down Expand Up @@ -60,9 +61,6 @@ jobs:
- name: special fix for numpy
run: |
micromamba run -n codeforecon pip install --force-reinstall -v "numpy==1.26"
# sed -i 's/if np\.obj2sctype(dtype) is None:/if np.dtype(dtype).type is None:/' ~/micromamba/envs/codeforecon/lib/python3.10/site-packages/pytensor/tensor/type.py &&
# sed -i 's/from numpy import e, euler_gamma, inf, infty, nan, newaxis, pi/from numpy import e, euler_gamma, inf, nan, newaxis, pi/' ~/micromamba/envs/codeforecon/lib/python3.10/site-packages/pytensor/tensor/__init__.py &&
# sed -i 's/infty/inf/g' ~/micromamba/envs/codeforecon/lib/python3.10/site-packages/pytensor/tensor/__init__.py
- name: Monkey patch for binsreg # sets np.math = math
run: |
Expand All @@ -79,4 +77,4 @@ jobs:
- name: success
run: |
echo "success!"
echo "Success in building book without errors!"
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ To read or use the book, head to the [*Coding for Economists* website](https://a

The rest of this readme is intended to help those who are contributing to the book, rather than readers.

Note that there is a custom, non-compliant `pyproject.toml` file included in this project. Its main purpose is to provide the version of the book, and the version of Python.

## Dev

These instructions are only for developers working on the book.
Expand Down
1 change: 1 addition & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,4 @@ sphinx:
bibtex_reference_style: author_year
suppress_warnings: ["mystnb.unknown_mime_type"]
nb_execution_show_tb: true
nb_execution_raise_on_error: true # Make build fail any content errors (don't want to publish if errors)
4 changes: 4 additions & 0 deletions auto-research-outputs.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ kernelspec:
(auto-research-outputs)=
# Automating Research Outputs

```{code-cell} ipython3
print(errrywerror)
```

In this chapter, you'll learn how to automate the inclusion of figures and tables in LaTeX-derived research outputs including PDFs and slides——plus how to convert those outputs to Microsoft Word documents and more. Much of what you'll see in this chapter applies to a wide range of coding languages.

This chapter has some similarities with another chapter, on {ref}`quarto`. But this chapter puts the LaTeX typesetting language front and centre, because it's the *de facto* standard for preparing *research outputs* (most journals have a LaTeX template for submission, for example), and it gives you full control over every aspect of how your outputs look. However, if you don't already know LaTeX, there is a steep-ish learning curve and—if you're just looking to create some automated reports using code and text rather than write pre-prints, working papers, journal articles, or academic-talk style slide decks—the chapter on {ref}`quarto` is going to be a better and easier fit for you.
Expand Down
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,4 @@ dependencies:
- pyfixest>=0.17.0
- watermark
- ydata_profiling
- toml-cli
11 changes: 11 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[project]
name = "Coding for Economists"
version = "1.0.2"
description = "A guide for economists on what programming is, why it's useful, and how to do it."
authors = [{name="Arthur Turrell", email="[email protected]"}]
readme = "README.md"
classifiers = [
"Development Status :: 5 - Production/Stable",
"Programming Language :: Python :: 3.10",
]
requires-python = "==3.10.16"
45 changes: 45 additions & 0 deletions version_bumper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import subprocess
from typing import Literal

import toml


def bump_version(part: Literal["major", "minor", "patch"] = "patch") -> None:
file_path = "pyproject.toml"

with open(file_path, "r") as f:
pyproject = toml.load(f)

version = pyproject["project"]["version"]
major, minor, patch = map(int, version.split("."))

if part == "major":
major += 1
minor = 0
patch = 0
elif part == "minor":
minor += 1
patch = 0
elif part == "patch":
patch += 1
else:
raise ValueError("Invalid part value. Choose 'major', 'minor', or 'patch'.")

new_version = f"{major}.{minor}.{patch}"
subprocess.run(
[
"uvx",
"--from=toml-cli",
"toml",
"set",
"--toml-path=pyproject.toml",
"project.version",
new_version,
]
)

print(f"Version bumped to {major}.{minor}.{patch}")


if __name__ == "__main__":
bump_version()

0 comments on commit ffc5397

Please sign in to comment.