diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md new file mode 100644 index 0000000..a141a29 --- /dev/null +++ b/.github/CONTRIBUTING.md @@ -0,0 +1,7 @@ +## Updating the code + +Please make sure that introduced changes are consistent with the testing api and add additional tests if relevant. + +## Updating the versioning + +Please add to `changelog.yaml` and then run `make changelog` before committing the results ONCE in this PR. diff --git a/.github/changelog_template.md b/.github/changelog_template.md new file mode 100644 index 0000000..8a1e679 --- /dev/null +++ b/.github/changelog_template.md @@ -0,0 +1,8 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +{{changelog}} \ No newline at end of file diff --git a/.github/get_changelog_diff.sh b/.github/get_changelog_diff.sh new file mode 100644 index 0000000..66c2bfd --- /dev/null +++ b/.github/get_changelog_diff.sh @@ -0,0 +1,2 @@ +last_tagged_commit=`git describe --tags --abbrev=0 --first-parent` +git --no-pager diff $last_tagged_commit -- CHANGELOG.md \ No newline at end of file diff --git a/.github/has_functional_changes.sh b/.github/has_functional_changes.sh new file mode 100644 index 0000000..4c8a1d0 --- /dev/null +++ b/.github/has_functional_changes.sh @@ -0,0 +1,12 @@ +#! /usr/bin/env bash + +IGNORE_DIFF_ON="README.md CONTRIBUTING.md Makefile docs/* .gitignore LICENSE* .github/* data/*" + +last_tagged_commit=`git describe --tags --abbrev=0 --first-parent` # --first-parent ensures we don't follow tags not published in master through an unlikely intermediary merge commit + +if git diff-index --name-only --exit-code $last_tagged_commit -- . `echo " $IGNORE_DIFF_ON" | sed 's/ / :(exclude)/g'` # Check if any file that has not be listed in IGNORE_DIFF_ON has changed since the last tag was published. +then + echo "No functional changes detected." + exit 1 +else echo "The functional files above were changed." +fi \ No newline at end of file diff --git a/.github/is_version_number_acceptable.sh b/.github/is_version_number_acceptable.sh new file mode 100644 index 0000000..9a912ad --- /dev/null +++ b/.github/is_version_number_acceptable.sh @@ -0,0 +1,33 @@ +#! /usr/bin/env bash + +if [[ ${GITHUB_REF#refs/heads/} == master ]] +then + echo "No need for a version check on master." + exit 0 +fi + +if ! $(dirname "$BASH_SOURCE")/has-functional-changes.sh +then + echo "No need for a version update." + exit 0 +fi + +current_version=`python .github/fetch_version.py` + +if git rev-parse --verify --quiet $current_version +then + echo "Version $current_version already exists in commit:" + git --no-pager log -1 $current_version + echo + echo "Update the version number in setup.py before merging this branch into master." + echo "Look at the CONTRIBUTING.md file to learn how the version number should be updated." + exit 1 +fi + +if ! $(dirname "$BASH_SOURCE")/has-functional-changes.sh | grep --quiet CHANGELOG.md +then + echo "CHANGELOG.md has not been modified, while functional changes were made." + echo "Explain what you changed before merging this branch into master." + echo "Look at the CONTRIBUTING.md file to learn how to write the changelog." + exit 2 +fi \ No newline at end of file diff --git a/.github/publish_git_tag.sh b/.github/publish_git_tag.sh new file mode 100644 index 0000000..ce9ff58 --- /dev/null +++ b/.github/publish_git_tag.sh @@ -0,0 +1,4 @@ +#! /usr/bin/env bash + +git tag `python .github/fetch_version.py` # create a new tag +git push --tags || true # update the repository version \ No newline at end of file diff --git a/.github/workflows/changelog_entry.yaml b/.github/workflows/changelog_entry.yaml new file mode 100644 index 0000000..911c28e --- /dev/null +++ b/.github/workflows/changelog_entry.yaml @@ -0,0 +1,29 @@ +name: Versioning + +on: + pull_request: + branches: [ main ] + +jobs: + check-changelog-entry: + name: Changelog entry check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Check for changelog entry + run: | + if [ ! -f "changelog_entry.yaml" ]; then + echo "Error: changelog_entry.yaml file is missing." + echo "Please add a changelog_entry.yaml file at the root of the repository." + exit 1 + fi + + # Check if the file is empty + if [ ! -s "changelog_entry.yaml" ]; then + echo "Error: changelog_entry.yaml file is empty." + echo "Please add content to the changelog_entry.yaml file." + exit 1 + fi + + echo "Changelog entry found and is not empty." diff --git a/.github/workflows/versioning.yaml b/.github/workflows/versioning.yaml new file mode 100644 index 0000000..18bcb0b --- /dev/null +++ b/.github/workflows/versioning.yaml @@ -0,0 +1,38 @@ +# Workflow that runs on versioning metadata updates. + +name: Versioning updates +on: + push: + branches: + - main + + paths: + - changelog_entry.yaml + - "!pyproject.toml" + +jobs: + Versioning: + runs-on: ubuntu-latest + if: | + (!(github.event.head_commit.message == 'Update package version')) + steps: + - name: Checkout repo + uses: actions/checkout@v4 + with: + repository: ${{ github.event.pull_request.head.repo.full_name }} + ref: ${{ github.event.pull_request.head.ref }} + token: ${{ secrets.POLICYENGINE_GITHUB }} + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: 3.11 + - name: Build changelog + run: pip install yaml-changelog && make changelog + - name: Preview changelog update + run: ".github/get-changelog-diff.sh" + - name: Update changelog + uses: EndBug/add-and-commit@v9 + with: + add: "." + message: Update package version + \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..ff638f4 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,16 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [0.1.0] - 2025-06-17 00:00:00 + +### Added + +- Initialized project + + + + diff --git a/Makefile b/Makefile index 75263ae..9060590 100644 --- a/Makefile +++ b/Makefile @@ -26,4 +26,11 @@ build: clean: rm -rf dist/ build/ *.egg-info/ - rm -rf docs/_build/ \ No newline at end of file + rm -rf docs/_build/ + +changelog: + build-changelog changelog.yaml --output changelog.yaml --update-last-date --start-from 0.1.0 --append-file changelog_entry.yaml + build-changelog changelog.yaml --org PolicyEngine --repo microcalibrate --output CHANGELOG.md --template .github/changelog_template.md + bump-version changelog.yaml pyproject.toml + rm changelog_entry.yaml || true + touch changelog_entry.yaml \ No newline at end of file diff --git a/README.md b/README.md index e69de29..134f35c 100644 --- a/README.md +++ b/README.md @@ -0,0 +1 @@ +# MicroCalibrate diff --git a/changelog.yaml b/changelog.yaml new file mode 100644 index 0000000..e74ca36 --- /dev/null +++ b/changelog.yaml @@ -0,0 +1,5 @@ +- changes: + added: + - Initialized project + date: 2025-06-17 + version: 0.1.0 diff --git a/changelog_entry.yaml b/changelog_entry.yaml new file mode 100644 index 0000000..9975054 --- /dev/null +++ b/changelog_entry.yaml @@ -0,0 +1,4 @@ +- bump: minor + changes: + changed: + - Initialized changelog. diff --git a/pyproject.toml b/pyproject.toml index 3481600..d2beab6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,6 +26,7 @@ dev = [ "mypy>=1.0.0,<2.0.0", "build>=1.0.0,<2.0.0", "linecheck>=0.1.0,<0.2.0", + "yaml-changelog>=0.1.7", ] docs = [