Skip to content

Commit 05db145

Browse files
authored
Merge pull request #61 from PolicyEngine/fix/improve-versioning
Fix version checking
2 parents bf17d84 + 85fdf34 commit 05db145

3 files changed

Lines changed: 68 additions & 10 deletions

File tree

.github/fetch_version.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
from policyengine_us_data.__version__ import __version__
1+
# Note: Action must be run in Python 3.11 or later
2+
import tomllib
23

34

45
def fetch_version():
5-
try:
6-
return __version__
7-
except Exception as e:
8-
print(f"Error fetching version: {e}")
9-
return None
6+
with open("pyproject.toml", "rb") as f:
7+
pyproject = tomllib.load(f)
8+
return pyproject["project"]["version"]
109

1110

1211
if __name__ == "__main__":

.github/workflows/ci_cd.yaml

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ on:
99
jobs:
1010
lint:
1111
runs-on: ubuntu-latest
12+
if: >
13+
github.event_name == 'pull_request' ||
14+
(
15+
github.repository == 'PolicyEngine/policyengine-us-data'
16+
&& github.event.head_commit.message == 'Update PolicyEngine US data'
17+
)
1218
name: Lint
1319
steps:
1420
- uses: actions/checkout@v4
@@ -22,9 +28,50 @@ jobs:
2228
pip install black
2329
- name: Check formatting
2430
run: black . -l 79 --check
31+
check-version:
32+
name: Check version
33+
runs-on: ubuntu-latest
34+
if: >
35+
github.event_name == 'pull_request' ||
36+
(
37+
github.repository == 'PolicyEngine/policyengine-us-data'
38+
&& github.event.head_commit.message != 'Update PolicyEngine US data'
39+
)
40+
steps:
41+
- name: Checkout code
42+
uses: actions/checkout@v4
43+
with:
44+
fetch-depth: 0 # Fetch all history for all tags and branches
45+
repository: ${{ github.event.pull_request.head.repo.full_name }}
46+
ref: ${{ github.event.pull_request.head.ref }}
47+
- name: Set up Python
48+
uses: actions/setup-python@v5
49+
with:
50+
python-version: 3.12
51+
- name: Build changelog
52+
run: pip install "yaml-changelog>=0.1.7" && make changelog
53+
- name: Preview changelog update
54+
run: ".github/get-changelog-diff.sh"
55+
- name: Check version number has been properly updated
56+
run: ".github/is-version-number-acceptable.sh"
57+
- name: Update changelog
58+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
59+
uses: EndBug/add-and-commit@v9
60+
with:
61+
add: "."
62+
committer_name: Github Actions[bot]
63+
author_name: Github Actions[bot]
64+
message: Update PolicyEngine US data
65+
github_token: ${{ secrets.POLICYENGINE_GITHUB }}
2566
test:
2667
name: Build and test
2768
runs-on: ubuntu-latest
69+
if: >
70+
github.event_name == 'pull_request' ||
71+
(
72+
github.repository == 'PolicyEngine/policyengine-us-data'
73+
&& github.event.head_commit.message == 'Update PolicyEngine US data'
74+
)
2875
steps:
2976
- name: Checkout code
3077
uses: actions/checkout@v4
@@ -51,7 +98,9 @@ jobs:
5198
publish-to-pypi:
5299
name: Publish to PyPI
53100
runs-on: ubuntu-latest
54-
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
101+
if: >
102+
github.repository == 'PolicyEngine/policyengine-us-data'
103+
&& github.event.head_commit.message == 'Update PolicyEngine US data'
55104
steps:
56105
- name: Checkout code
57106
uses: actions/checkout@v4
@@ -76,7 +125,9 @@ jobs:
76125
docker:
77126
name: Docker
78127
runs-on: ubuntu-latest
79-
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
128+
if: >
129+
github.repository == 'PolicyEngine/policyengine-us-data'
130+
&& github.event.head_commit.message == 'Update PolicyEngine US data'
80131
steps:
81132
- name: Checkout repo
82133
uses: actions/checkout@v4
@@ -93,7 +144,9 @@ jobs:
93144
publish-docs:
94145
name: Publish documentation
95146
runs-on: ubuntu-latest
96-
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
147+
if: >
148+
github.repository == 'PolicyEngine/policyengine-us-data'
149+
&& github.event.head_commit.message == 'Update PolicyEngine US data'
97150
steps:
98151
- name: Checkout code
99152
uses: actions/checkout@v4
@@ -117,7 +170,9 @@ jobs:
117170
name: Upload data
118171
runs-on: ubuntu-latest
119172
needs: [lint, test]
120-
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
173+
if: >
174+
github.repository == 'PolicyEngine/policyengine-us-data'
175+
&& github.event.head_commit.message == 'Update PolicyEngine US data'
121176
steps:
122177
- name: Checkout code
123178
uses: actions/checkout@v4

changelog_entry.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
- bump: patch
2+
changes:
3+
fixed:
4+
- Corrected versioning issues

0 commit comments

Comments
 (0)