Repository: stevieflyer/pydantic-api-models-notion
Pull request #13: ci: add ci step
Author: login: joscha
Created: 2025-03-23T13:58:50Z | Merged: 2025-03-26T13:19:12Z

@stevieflyer in order to make this work, you will need to either add me as a collaborator on the pypi project or go to https://pypi.org/manage/account/publishing/ and add the following configuration:

<img width="954" alt="SCR-20250323-mnas" src="https://github.com/user-attachments/assets/fd490c12-2756-4f1e-b9e3-53aa34460bac" />

After that (with the changes in this pull request), tag creation will automatically generate a new release and publish it.


Diff:
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
new file mode 100644
index 0000000..3004612
--- /dev/null
+++ b/.github/workflows/test.yml
@@ -0,0 +1,56 @@
+name: "Test"
+on:
+  pull_request:
+  push:
+jobs:
+  tests:
+    strategy:
+      matrix:
+        os: [ubuntu-latest, macos-latest]
+    runs-on: ${{ matrix.os }}
+    permissions:
+      contents: read
+    steps:
+      - uses: actions/checkout@v4
+      - uses: cachix/install-nix-action@v31
+      - name: Install devenv.sh
+        run: nix profile install nixpkgs#devenv
+      - name: Build the devenv shell and run any pre-commit hooks
+        run: devenv test
+  build:
+    name: Build distribution 📦
+    runs-on: ubuntu-latest
+    needs:
+      - tests
+    steps:
+      - uses: actions/checkout@v4
+      - uses: cachix/install-nix-action@v31
+      - name: Install devenv.sh
+        run: nix profile install nixpkgs#devenv
+      - name: Create the package tarball
+        run: devenv shell build
+      - name: Store the distribution packages
+        uses: actions/upload-artifact@v4
+        with:
+          name: python-package-distributions
+          path: dist/
+  publish-to-pypi:
+    name: >-
+      Publish Python 🐍 distribution 📦 to PyPI
+    if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
+    needs:
+      - build
+    runs-on: ubuntu-latest
+    environment:
+      name: release
+      url: https://pypi.org/p/pydantic-api-models-notion
+    permissions:
+      id-token: write # IMPORTANT: mandatory for trusted publishing  
+    steps:
+      - name: Download all the dists
+        uses: actions/download-artifact@v4
+        with:
+          name: python-package-distributions
+          path: dist/
+      - name: Publish distribution 📦 to PyPI
+        uses: pypa/gh-action-pypi-publish@release/v1
diff --git a/.yamlfmt b/.yamlfmt
new file mode 100644
index 0000000..9da12de
--- /dev/null
+++ b/.yamlfmt
@@ -0,0 +1,5 @@
+gitignore_excludes: true
+eof_newline: true
+exclude:
+  - .yamllint
+  - .pre-commit-config.yaml
diff --git a/.yamllint b/.yamllint
new file mode 100644
index 0000000..8f989ac
--- /dev/null
+++ b/.yamllint
@@ -0,0 +1,3 @@
+ignore: |
+  .pre-commit-config.yaml
+document-start: false
diff --git a/README.md b/README.md
index bde8ab9..fb8eb44 100644
--- a/README.md
+++ b/README.md
@@ -1 +1,20 @@
 # Data models for Notion API
+
+[![PyPI version](https://img.shields.io/pypi/v/pydantic-api-models-notion)](https://pypi.org/project/pydantic-api-models-notion/)
+
+Pydantic data model for [Notion](https://www.notion.so/).
+
+
+Install via:
+```sh
+pip install pydantic-api-models-notion
+```
+
+## Development
+
+This repository uses [devenv](https://devenv.sh/). Devenv and enabled direnv will give you the best developer experience.
+
+## Releasing
+
+Create a new release [here](https://github.com/stevieflyer/pydantic-api-models-notion/releases/new).
+Choose a semver-style tag (i.e. `X.X.X`). Make sure the tag matches the version in `pyproject.toml`.
diff --git a/devenv.nix b/devenv.nix
index ebb9293..0b9820a 100644
--- a/devenv.nix
+++ b/devenv.nix
@@ -1,4 +1,10 @@
-{ pkgs, lib, config, inputs, ... }:
+{
+  pkgs,
+  lib,
+  config,
+  inputs,
+  ...
+}:
 
 {
   packages = [ pkgs.git ];
@@ -8,9 +14,30 @@
   languages.python.poetry.activate.enable = true;
   languages.python.version = "3.12";
 
+  git-hooks.hooks = {
+    # TODO: enable later
+    # ruff.enable = true;
+    # ruff-format.enable = true;
+    # typos.enable = true;
+    # check-toml.enable = true;
+    # markdownlint.enable = true;
+    yamllint.enable = true;
+    yamlfmt.enable = true;
+    yamlfmt.settings.lint-only = false;
+    nixfmt-rfc-style.enable = true;
+  };
+
   scripts.check-types.exec = ''
     poetry \
       run mypy \
         --explicit-package-bases "$DEVENV_ROOT/pydantic_api/notion/models/"
   '';
+
+  scripts.build.exec = ''
+    poetry build
+  '';
+
+  scripts.format.exec = ''
+    pre-commit run --all-files
+  '';
 }


Reviews:
user: login: joscha
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-03-23T13:59:41Z
user: login: joscha
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-03-23T14:00:03Z
user: login: joscha
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-03-23T14:05:59Z
user: login: joscha
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-03-23T14:06:20Z
user: login: joscha
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-03-23T14:07:06Z

Review comments:
diff_hunk: @@ -8,9 +14,30 @@
   languages.python.poetry.activate.enable = true;
   languages.python.version = "3.12";
 
+  git-hooks.hooks = {
+    # TODO: enable later
path: devenv.nix
user: login: joscha
body: wasn't able to enable these, as the diff would be too big. Will do separately.
created_at: 2025-03-23T13:59:41Z
author_association: COLLABORATOR
diff_hunk: @@ -8,9 +14,30 @@
   languages.python.poetry.activate.enable = true;
   languages.python.version = "3.12";
 
+  git-hooks.hooks = {
+    # TODO: enable later
+    # ruff.enable = true;
+    # ruff-format.enable = true;
+    # typos.enable = true;
+    # check-toml.enable = true;
+    # markdownlint.enable = true;
+    yamllint.enable = true;
+    yamlfmt.enable = true;
+    yamlfmt.settings.lint-only = false;
+    nixfmt-rfc-style.enable = true;
+  };
+
   scripts.check-types.exec = ''
path: devenv.nix
user: login: joscha
body: this one errors too much as well currently, in order to run as part of CI. Will need to get the type errors down first.
created_at: 2025-03-23T14:00:03Z
author_association: COLLABORATOR
diff_hunk: @@ -0,0 +1,56 @@
+name: "Test"
+on:
+  pull_request:
+  push:
+jobs:
+  tests:
+    strategy:
+      matrix:
+        os: [ubuntu-latest, macos-latest]
+    runs-on: ${{ matrix.os }}
+    permissions:
+      contents: read
+    steps:
+      - uses: actions/checkout@v4
+      - uses: cachix/install-nix-action@v31
+      - name: Install devenv.sh
+        run: nix profile install nixpkgs#devenv
+      - name: Build the devenv shell and run any pre-commit hooks
path: .github/workflows/test.yml
user: login: joscha
body: (1) test first
created_at: 2025-03-23T14:05:59Z
author_association: COLLABORATOR
diff_hunk: @@ -0,0 +1,56 @@
+name: "Test"
+on:
+  pull_request:
+  push:
+jobs:
+  tests:
+    strategy:
+      matrix:
+        os: [ubuntu-latest, macos-latest]
+    runs-on: ${{ matrix.os }}
+    permissions:
+      contents: read
+    steps:
+      - uses: actions/checkout@v4
+      - uses: cachix/install-nix-action@v31
+      - name: Install devenv.sh
+        run: nix profile install nixpkgs#devenv
+      - name: Build the devenv shell and run any pre-commit hooks
+        run: devenv test
+  build:
+    name: Build distribution 📦
+    runs-on: ubuntu-latest
+    needs:
+      - tests
+    steps:
+      - uses: actions/checkout@v4
+      - uses: cachix/install-nix-action@v31
+      - name: Install devenv.sh
+        run: nix profile install nixpkgs#devenv
+      - name: Create the package tarball
+        run: devenv shell build
path: .github/workflows/test.yml
user: login: joscha
body: (2) then we create a release artifact, that is uploaded and attached to the build
created_at: 2025-03-23T14:06:20Z
author_association: COLLABORATOR
diff_hunk: @@ -0,0 +1,56 @@
+name: "Test"
+on:
+  pull_request:
+  push:
+jobs:
+  tests:
+    strategy:
+      matrix:
+        os: [ubuntu-latest, macos-latest]
+    runs-on: ${{ matrix.os }}
+    permissions:
+      contents: read
+    steps:
+      - uses: actions/checkout@v4
+      - uses: cachix/install-nix-action@v31
+      - name: Install devenv.sh
+        run: nix profile install nixpkgs#devenv
+      - name: Build the devenv shell and run any pre-commit hooks
+        run: devenv test
+  build:
+    name: Build distribution 📦
+    runs-on: ubuntu-latest
+    needs:
+      - tests
+    steps:
+      - uses: actions/checkout@v4
+      - uses: cachix/install-nix-action@v31
+      - name: Install devenv.sh
+        run: nix profile install nixpkgs#devenv
+      - name: Create the package tarball
+        run: devenv shell build
+      - name: Store the distribution packages
+        uses: actions/upload-artifact@v4
+        with:
+          name: python-package-distributions
+          path: dist/
+  publish-to-pypi:
+    name: >-
+      Publish Python 🐍 distribution 📦 to PyPI
+    if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
+    needs:
+      - build
+    runs-on: ubuntu-latest
+    environment:
+      name: release
+      url: https://pypi.org/p/pydantic-api-models-notion
+    permissions:
+      id-token: write # IMPORTANT: mandatory for trusted publishing  
+    steps:
+      - name: Download all the dists
+        uses: actions/download-artifact@v4
+        with:
+          name: python-package-distributions
+          path: dist/
+      - name: Publish distribution 📦 to PyPI
path: .github/workflows/test.yml
user: login: joscha
body: (3) and then, if the branch is a tag, we download the previously created build artifact and publish it on pypi
created_at: 2025-03-23T14:07:06Z
author_association: COLLABORATOR

PR comments:
user: login: joscha
created_at: 2025-03-25T10:43:24Z
body: @stevieflyer I am a bit blocked on this until we sorted out pypi - do you want to do a quick call about it, so I can explain?
author_association: COLLABORATOR
user: login: joscha
created_at: 2025-03-26T11:44:08Z
body: friendly ping @stevieflyer ^ ?
author_association: COLLABORATOR
user: login: stevieflyer
created_at: 2025-03-26T12:40:29Z
body: hi, @joscha , sorry for the blocks, I just invited u as the maintainer on pypi. I was on vacation this week, sorry for the delay
author_association: OWNER
user: login: joscha
created_at: 2025-03-26T13:05:10Z
body: > hi, @joscha , sorry for the blocks, I just invited u as the maintainer on pypi. I was on vacation this week, sorry for the delay

amazing, thank you. Sorry for the disturbance! Let me see if I can take this from here!
author_association: COLLABORATOR
user: login: joscha
created_at: 2025-03-26T13:07:16Z
body: > hi, @joscha , sorry for the blocks, I just invited u as the maintainer on pypi. I was on vacation this week, sorry for the delay

Sorry @stevieflyer, I think you invited me to the other project (`pydantic-api-sdk-notion`), which is great, I can set it up there, too. But for this repo, I need one for `pydantic-api-sdk-notion`, please.
author_association: COLLABORATOR
user: login: stevieflyer
created_at: 2025-03-26T13:10:01Z
body: my bad. just invited u to another repo, I think it should work now :)
author_association: OWNER
user: login: joscha
created_at: 2025-03-26T13:12:00Z
body: > I think it should work now :)
<img width="811" alt="SCR-20250326-luxu" src="https://github.com/user-attachments/assets/83f1b799-096e-43ad-891b-22e7bb723476" />

Almost. I think I am missing some rights on the projects, I can't update the publisher settings with my current access.
If you don't want to give them away, then you'll need to click on `manage` and then on `publishing` and fill in the form as above in the pull request description, please.

[Direct link](https://pypi.org/manage/project/pydantic-api-models-notion/settings/publishing/) to the publishing settings (403 for me)

author_association: COLLABORATOR
user: login: joscha
created_at: 2025-03-26T13:19:05Z
body: Got access, let me try this 🎉 
author_association: COLLABORATOR
user: login: stevieflyer
created_at: 2025-03-26T13:19:12Z
body: I just updated your role as owner, wish that may help
author_association: OWNER
user: login: joscha
created_at: 2025-03-26T13:22:16Z
body: moment of truth: https://github.com/stevieflyer/pydantic-api-models-notion/actions/runs/14084363071
author_association: COLLABORATOR
user: login: joscha
created_at: 2025-03-26T13:59:08Z
body: Works, see https://pypi.org/project/pydantic-api-models-notion/0.0.20/
author_association: COLLABORATOR