Skip to content

Commit 1916dfd

Browse files
author
bakebot
committed
Cookie updated targeting develop by NetworkToCode Cookie Drift Manager Tool
Template: ``` { "template": "https://github.com/networktocode-llc/cookiecutter-ntc.git", "dir": "python", "ref": "main", "path": "/__w/cookiecutter-nautobot-app-drift-manager/cookiecutter-nautobot-app-drift-manager/cookiecutter-ntc/python" } ``` Cookie: ``` { "remote": "https://github.com/networktocode/jdiff.git", "path": "/tmp/tmpjukp_9wv/jdiff", "repository_path": "/tmp/tmpjukp_9wv/jdiff", "dir": "", "branch_prefix": "drift-manager/develop", "context": { "codeowner_github_usernames": "@lvrfrc87 @scetron @grelleum @jeffkala @pszulczewski", "full_name": "Network to Code, LLC", "email": "info@networktocode.com", "github_org": "networktocode", "description": "Python library for examining structured data.", "project_name": "jdiff", "project_slug": "jdiff", "repo_url": "https://github.com/networktocode/jdiff", "base_url": "jdiff", "project_python_name": "jdiff", "project_python_base_version": "3.10", "project_with_config_settings": "no", "generate_docs": "yes", "version": "1.0.1", "original_publish_year": "2022", "_template": "/__w/cookiecutter-nautobot-app-drift-manager/cookiecutter-nautobot-app-drift-manager/cookiecutter-ntc/python", "_output_dir": "/tmp/tmpjukp_9wv", "_repo_dir": "/__w/cookiecutter-nautobot-app-drift-manager/cookiecutter-nautobot-app-drift-manager/cookiecutter-ntc/python", "_checkout": null }, "drift_managed_branch": "develop", "remote_name": "origin", "pull_request_strategy": "PullRequestStrategy.UPDATE_OR_CREATE", "post_actions": [], "baked_commit_ref": "bc931311336d391d878202dba239389783ee9f09", "draft": false } ``` CLI Arguments: ``` { "cookie_dir": "", "input": false, "json_filename": "", "output_dir": "", "push": true, "template": "./cookiecutter-ntc", "template_dir": "python", "template_ref": "main", "pull_request": "update-or-create", "post_action": [], "disable_post_actions": true, "draft": null, "drift_managed_branch": "develop" } ```
1 parent f91f4f9 commit 1916dfd

12 files changed

Lines changed: 428 additions & 39 deletions

‎.cookiecutter.json‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@
2323
"pull_request_strategy": "update-or-create",
2424
"post_actions": [],
2525
"draft": false,
26+
<<<<<<< HEAD
2627
"baked_commit_ref": "bc931311336d391d878202dba239389783ee9f09",
28+
=======
29+
"baked_commit_ref": "83a4975ef60cb34219557649eb08b8e599d5ec1c",
30+
>>>>>>> d408d2a (Cookie updated targeting develop by NetworkToCode Cookie Drift Manager Tool)
2731
"drift_managed_branch": "develop"
2832
}
2933
}
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
---
2+
name: "Prepare Release"
3+
on: # yamllint disable-line rule:truthy rule:comments
4+
workflow_dispatch:
5+
inputs:
6+
bump_rule:
7+
description: "Select the version bump type"
8+
required: true
9+
default: "patch"
10+
type: "choice"
11+
options:
12+
- "prerelease"
13+
- "patch"
14+
- "minor"
15+
- "major"
16+
target_branch:
17+
description: "Create the release from this branch (default: main)."
18+
required: true
19+
default: "main"
20+
date:
21+
description: "Date of the release YYYY-MM-DD (defaults to today's date in the US Eastern TZ)."
22+
required: false
23+
default: ""
24+
25+
jobs:
26+
prepare-release:
27+
permissions:
28+
contents: "write"
29+
pull-requests: "write"
30+
name: "Prepare Release"
31+
runs-on: "ubuntu-latest"
32+
steps:
33+
- name: "Checkout code"
34+
uses: "actions/checkout@v4"
35+
with:
36+
# If target_branch is 'main', use 'develop' as the source branch. Otherwise, the source and target branch are the same.
37+
ref: "${{ github.event.inputs['target_branch'] == 'main' && 'develop' || github.event.inputs['target_branch'] }}"
38+
fetch-depth: 0 # Fetch all history for git tags
39+
40+
- name: "Setup environment"
41+
uses: "networktocode/gh-action-setup-poetry-environment@v6"
42+
with:
43+
poetry-version: "2.1.3"
44+
poetry-install-options: "--with dev"
45+
46+
- name: "Validate Branch and Tags"
47+
run: |
48+
# 1. Verify branch exists
49+
if ! git rev-parse --verify origin/${{ github.event.inputs.target_branch }} > /dev/null 2>&1; then
50+
echo "Error: Branch ${{ github.event.inputs.target_branch }} does not exist."
51+
exit 1
52+
fi
53+
54+
# 2. Try to get the previous version tag
55+
# If it fails (no tags), get the hash of the first commit
56+
if PREV_TAG=$(git describe --tags --abbrev=0 2>/dev/null); then
57+
echo "PREVIOUS_TAG=$PREV_TAG" >> $GITHUB_ENV
58+
echo "Found previous tag: $PREV_TAG"
59+
else
60+
# Fallback to the first commit in the repository
61+
FIRST_COMMIT=$(git rev-list --max-parents=0 HEAD)
62+
echo "PREVIOUS_TAG=$FIRST_COMMIT" >> $GITHUB_ENV
63+
echo "No tags found. Falling back to initial commit: $FIRST_COMMIT"
64+
fi
65+
66+
- name: "Determine New Version"
67+
id: "versioning"
68+
run: |
69+
# Perform the bump based on the user input
70+
poetry version ${{ github.event.inputs.bump_rule }}
71+
72+
# Capture the New version string for use in other steps
73+
NEW_VER=$(poetry version --short)
74+
echo "NEW_VERSION=$NEW_VER" >> $GITHUB_ENV
75+
echo "RELEASE_BRANCH=release/$NEW_VER" >> $GITHUB_ENV
76+
77+
- name: "Set Date Variable"
78+
run: |
79+
if [ -z "${{ github.event.inputs.date }}" ]; then
80+
RELEASE_DATE=$(TZ=America/New_York date +%Y-%m-%d)
81+
else
82+
RELEASE_DATE="${{ github.event.inputs.date }}"
83+
fi
84+
echo "RELEASE_DATE=$RELEASE_DATE" >> $GITHUB_ENV
85+
86+
- name: "Create Release Branch"
87+
env:
88+
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
89+
run: |
90+
git config user.name "${{ github.actor }}"
91+
git config user.email "${{ github.actor }}@users.noreply.github.com"
92+
93+
# Ensure release branch doesn't already exist
94+
if git rev-parse --verify origin/${{ env.RELEASE_BRANCH }} > /dev/null 2>&1; then
95+
echo "Error: Release branch ${{ env.RELEASE_BRANCH }} already exists."
96+
exit 1
97+
fi
98+
99+
# Create a new branch for the release
100+
git checkout -b "${{ env.RELEASE_BRANCH }}"
101+
102+
- name: "Regenerate poetry.lock"
103+
run: "poetry lock --regenerate"
104+
105+
- name: "Generate Github Release Notes"
106+
env:
107+
GH_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
108+
run: |
109+
# 1. Get Towncrier Draft
110+
TOWNCRIER_NOTES=$(poetry run towncrier build --version "${{ env.NEW_VERSION }}" --date "${{ env.RELEASE_DATE }}" --draft)
111+
112+
# 2. Call GitHub API to generate raw notes
113+
RAW_GH_NOTES=$(gh api /repos/${{ github.repository }}/releases/generate-notes \
114+
-f tag_name="v${{ env.NEW_VERSION }}" \
115+
-f target_commitish="${{ github.event.inputs['target_branch'] == 'main' && 'develop' || github.event.inputs['target_branch'] }}" \
116+
-f previous_tag_name="${{ env.PREVIOUS_TAG }}" --jq '.body')
117+
118+
# 3. Parse usernames (Regex match)
119+
# We use grep to find "@user" patterns, sort, and uniq them
120+
USERNAMES=$(echo "$RAW_GH_NOTES" | grep -oP 'by @\K[a-zA-Z0-9-]+' | sort -u | grep -vE 'dependabot|nautobot-bot|github-actions' || true)
121+
122+
# 4. Format the Contributors section
123+
CONTRIBUTORS_SECTION="## Contributors"
124+
for user in $USERNAMES; do
125+
CONTRIBUTORS_SECTION="$CONTRIBUTORS_SECTION"$'\n'"* @$user"
126+
done
127+
128+
# 5. Extract the "Full Changelog" or "New Contributors" part
129+
# Using awk to grab everything from '## New Contributors' or '**Full Changelog**' to the end
130+
GH_FOOTER=$(echo "$RAW_GH_NOTES" | awk '/## New Contributors/ || /\*\*Full Changelog\*\*/ {found=1} found {print}')
131+
if [ -z "$GH_FOOTER" ]; then
132+
GH_FOOTER=$(echo "$RAW_GH_NOTES" | sed -n '/**Full Changelog**/,$p')
133+
fi
134+
135+
# 6. Combine everything
136+
FINAL_NOTES="$TOWNCRIER_NOTES"$'\n\n'"$CONTRIBUTORS_SECTION"$'\n\n'"$GH_FOOTER"
137+
138+
# 7. Save to a temporary file to avoid shell argument length limits
139+
echo "$FINAL_NOTES" > ../consolidated_notes.md
140+
141+
- name: "Generate Release Notes"
142+
run: "poetry run inv generate-release-notes --version '${{ env.NEW_VERSION }}' --date '${{ env.RELEASE_DATE }}'"
143+
144+
- name: "Commit Changes and Push"
145+
run: |
146+
# Add all changes (pyproject.toml, poetry.lock, etc.)
147+
git add .
148+
git commit -m "prepare release v${{ env.NEW_VERSION }}"
149+
git push origin "${{ env.RELEASE_BRANCH }}"
150+
151+
- name: "Create Pull Request"
152+
env:
153+
GH_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
154+
run: |
155+
gh pr create \
156+
--title "Release v${{ env.NEW_VERSION }}" \
157+
--body-file "../consolidated_notes.md" \
158+
--base "${{ github.event.inputs.target_branch }}" \
159+
--head "${{ env.RELEASE_BRANCH }}"
160+
161+
- name: "Create Draft Release"
162+
env:
163+
GH_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
164+
run: |
165+
if [[ "${{ github.event.inputs.bump_rule }}" == "prerelease" ]]; then
166+
RELEASE_FLAGS="--prerelease"
167+
elif [[ "${{ github.event.inputs.target_branch }}" == "main" ]]; then
168+
RELEASE_FLAGS="--latest"
169+
else
170+
RELEASE_FLAGS="--latest=false"
171+
fi
172+
173+
gh release create "v${{ env.NEW_VERSION }}" \
174+
--draft \
175+
$RELEASE_FLAGS \
176+
--title "v${{ env.NEW_VERSION }} - ${{ env.RELEASE_DATE }}" \
177+
--notes-file "../consolidated_notes.md" \
178+
--target "${{ github.event.inputs.target_branch }}"

‎.github/workflows/release.yml‎

Lines changed: 65 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
name: "Release"
3-
on: # yamllint disable-line rule:truthy rule:comments
3+
on: # yamllint disable-line rule:truthy rule:comments
44
release:
55
types: ["published"]
66

@@ -12,10 +12,10 @@ jobs:
1212
steps:
1313
- uses: "actions/checkout@v4"
1414
- name: "Setup environment"
15-
uses: "networktocode/gh-action-setup-poetry-environment@v6"
15+
uses: "networktocode/gh-action-setup-poetry-environment@v7"
1616
with:
1717
poetry-version: "2.1.3"
18-
python-version: "3.13"
18+
python-version: "3.12"
1919
poetry-install-options: "--no-root"
2020
- name: "Run Poetry Build"
2121
run: "poetry build"
@@ -56,7 +56,9 @@ jobs:
5656
if: "startsWith(github.ref, 'refs/tags/v')"
5757
needs: "build"
5858
environment: "pypi"
59-
# Steps to publish to PyPI.
59+
# IMPORTANT: this permission is mandatory for trusted publishing.
60+
permissions:
61+
id-token: "write"
6062
steps:
6163
- name: "Retrieve built package from cache"
6264
uses: "actions/download-artifact@v4"
@@ -65,11 +67,6 @@ jobs:
6567
path: "dist/"
6668
- name: "Publish package distributions to PyPI"
6769
uses: "pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e" # v1.13.0
68-
## Used for networktocode org since trusted publisher isn't supported for GitHub Plan.
69-
with:
70-
user: "__token__"
71-
password: "${{ secrets.PYPI_API_TOKEN }}"
72-
# End publish to PyPI job.
7370

7471
slack-notify:
7572
needs:
@@ -104,3 +101,62 @@ jobs:
104101
}
105102
]
106103
}
104+
105+
create-pr-to-develop:
106+
if: "github.event.release.target_commitish == 'main'"
107+
permissions:
108+
contents: "write"
109+
pull-requests: "write"
110+
name: "Create a PR from main into develop"
111+
needs:
112+
- "publish-github"
113+
- "publish-pypi"
114+
runs-on: "ubuntu-latest"
115+
steps:
116+
- name: "Checkout main"
117+
uses: "actions/checkout@v4"
118+
with:
119+
ref: "main"
120+
fetch-depth: 0
121+
122+
- name: "Setup environment"
123+
uses: "networktocode/gh-action-setup-poetry-environment@v6"
124+
with:
125+
poetry-version: "2.1.3"
126+
poetry-install-options: "--no-root"
127+
128+
- name: "Create release branch from main"
129+
id: "branch"
130+
run: |
131+
132+
git config user.name "${{ github.actor }}"
133+
git config user.email "${{ github.actor }}@users.noreply.github.com"
134+
135+
TAG_NAME="${{ github.event.release.tag_name }}"
136+
VERSION="${TAG_NAME#v}"
137+
138+
BRANCH_NAME="release-${VERSION}-to-develop"
139+
140+
# Ensure release branch doesn't already exist
141+
if git rev-parse --verify origin/$BRANCH_NAME > /dev/null 2>&1; then
142+
echo "Error: Release branch $BRANCH_NAME already exists."
143+
exit 1
144+
fi
145+
146+
git checkout -b "$BRANCH_NAME"
147+
148+
poetry version prepatch
149+
git add pyproject.toml && git commit -m "Bump version"
150+
git push origin "$BRANCH_NAME"
151+
152+
echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT
153+
154+
- name: "Create Pull Request to develop"
155+
env:
156+
GH_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
157+
run: |
158+
gh pr create \
159+
--title "Post release ${{ github.event.release.tag_name }} to develop" \
160+
--body "Please do a merge commit." \
161+
--base "develop" \
162+
--head "${{ steps.branch.outputs.branch_name }}"

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,3 +308,4 @@ docs/CHANGELOG.md
308308
public
309309
/compose.yaml
310310
/dump.sql
311+
/jdiff/static/*

‎README.md‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
# Jdiff
22

33
<p align="center">
4+
<<<<<<< HEAD
45
<img src="https://raw.githubusercontent.com/networktocode/jdiff/develop/docs/images/jdiff_logo.png" class="logo" height="200px">
6+
=======
7+
<img src="https://raw.githubusercontent.com/networktocode/jdiff/develop/docs/images/icon-jdiff.png" class="logo" height="200px">
8+
>>>>>>> d408d2a (Cookie updated targeting develop by NetworkToCode Cookie Drift Manager Tool)
59
<br>
610
<a href="https://github.com/networktocode/jdiff/actions"><img src="https://github.com/networktocode/jdiff/actions/workflows/ci.yml/badge.svg?branch=main"></a>
711
<a href="https://jdiff.readthedocs.io/en/latest/"><img src="https://readthedocs.org/projects/jdiff/badge/"></a>
@@ -18,9 +22,15 @@
1822

1923
Full documentation for this library can be found over on the [Jdiff Docs](https://jdiff.readthedocs.io/) website:
2024

25+
<<<<<<< HEAD
2126
- [User Guide](https://jdiff.readthedocs.io/en/latest/user/lib_overview/) - Overview, Using the library, Getting Started.
2227
- [Administrator Guide](https://jdiff.readthedocs.io/en/latest/admin/install/) - How to Install, Configure, Upgrade, or Uninstall the library.
2328
- [Developer Guide](https://jdiff.readthedocs.io/en/latest/dev/contributing/) - Extending the library, Code Reference, Contribution Guide.
29+
=======
30+
- [User Guide](https://jdiff.readthedocs.io/en/latest/user/app_overview/) - Overview, Using the Library, Getting Started.
31+
- [Administrator Guide](https://jdiff.readthedocs.io/en/latest/admin/install/) - How to Install, Configure, Upgrade, or Uninstall the Library.
32+
- [Developer Guide](https://jdiff.readthedocs.io/en/latest/dev/contributing/) - Extending the Library, Code Reference, Contribution Guide.
33+
>>>>>>> d408d2a (Cookie updated targeting develop by NetworkToCode Cookie Drift Manager Tool)
2434
- [Release Notes / Changelog](https://jdiff.readthedocs.io/en/latest/admin/release_notes/).
2535
- [Frequently Asked Questions](https://jdiff.readthedocs.io/en/latest/user/faq/).
2636

0 commit comments

Comments
 (0)