Skip to content

Commit b72a57e

Browse files
authored
Cookie updated targeting develop by NetworkToCode Cookie Drift Manager Tool (#315)
1 parent 9a04099 commit b72a57e

File tree

15 files changed

+1963
-1021
lines changed

15 files changed

+1963
-1021
lines changed

.cookiecutter.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
"_drift_manager": {
2020
"template": "https://github.com/nautobot/cookiecutter-nautobot-app.git",
2121
"template_dir": "nautobot-app",
22-
"template_ref": "nautobot-app-v3.0.0",
22+
"template_ref": "nautobot-app-v3.1.1",
2323
"cookie_dir": "",
2424
"pull_request_strategy": "create",
2525
"post_actions": [],
2626
"draft": false,
27-
"baked_commit_ref": "0546953f4b8be3516b003c41e69785f114f008ed",
27+
"baked_commit_ref": "799b2ad59cda22a814ea31435366b205381b708e",
2828
"drift_managed_branch": "develop"
2929
}
3030
}

.github/workflows/ci.yml

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- name: "Check out repository code"
2121
uses: "actions/checkout@v4"
2222
- name: "Setup environment"
23-
uses: "networktocode/gh-action-setup-poetry-environment@v6"
23+
uses: "networktocode/gh-action-setup-poetry-environment@v7"
2424
with:
2525
poetry-version: "2.1.3"
2626
poetry-install-options: "--only-root"
@@ -44,7 +44,7 @@ jobs:
4444
with:
4545
name: "poetry-lock"
4646
- name: "Setup environment"
47-
uses: "networktocode/gh-action-setup-poetry-environment@v6"
47+
uses: "networktocode/gh-action-setup-poetry-environment@v7"
4848
with:
4949
poetry-version: "2.1.3"
5050
- name: "Linting: ruff format"
@@ -62,7 +62,7 @@ jobs:
6262
with:
6363
name: "poetry-lock"
6464
- name: "Setup environment"
65-
uses: "networktocode/gh-action-setup-poetry-environment@v6"
65+
uses: "networktocode/gh-action-setup-poetry-environment@v7"
6666
with:
6767
poetry-version: "2.1.3"
6868
- name: "Linting: ruff"
@@ -80,7 +80,7 @@ jobs:
8080
with:
8181
name: "poetry-lock"
8282
- name: "Setup environment"
83-
uses: "networktocode/gh-action-setup-poetry-environment@v6"
83+
uses: "networktocode/gh-action-setup-poetry-environment@v7"
8484
with:
8585
poetry-version: "2.1.3"
8686
poetry-install-options: "--only dev,docs"
@@ -94,11 +94,29 @@ jobs:
9494
- name: "Check out repository code"
9595
uses: "actions/checkout@v4"
9696
- name: "Setup environment"
97-
uses: "networktocode/gh-action-setup-poetry-environment@v6"
97+
uses: "networktocode/gh-action-setup-poetry-environment@v7"
9898
with:
9999
poetry-version: "2.1.3"
100100
- name: "Checking: poetry lock file"
101101
run: "poetry run invoke lock --check"
102+
djlint:
103+
needs: "generate-lockfile"
104+
runs-on: "ubuntu-latest"
105+
env:
106+
INVOKE_NAUTOBOT_BGP_MODELS_LOCAL: "True"
107+
steps:
108+
- name: "Check out repository code"
109+
uses: "actions/checkout@v4"
110+
- name: "Download poetry.lock artifact"
111+
uses: "actions/download-artifact@v4"
112+
with:
113+
name: "poetry-lock"
114+
- name: "Setup environment"
115+
uses: "networktocode/gh-action-setup-poetry-environment@v7"
116+
with:
117+
poetry-version: "2.1.3"
118+
- name: "Linting: djlint"
119+
run: "poetry run invoke djlint"
102120
yamllint:
103121
needs: "generate-lockfile"
104122
runs-on: "ubuntu-latest"
@@ -112,7 +130,7 @@ jobs:
112130
with:
113131
name: "poetry-lock"
114132
- name: "Setup environment"
115-
uses: "networktocode/gh-action-setup-poetry-environment@v6"
133+
uses: "networktocode/gh-action-setup-poetry-environment@v7"
116134
with:
117135
poetry-version: "2.1.3"
118136
- name: "Linting: yamllint"
@@ -130,7 +148,7 @@ jobs:
130148
with:
131149
name: "poetry-lock"
132150
- name: "Setup environment"
133-
uses: "networktocode/gh-action-setup-poetry-environment@v6"
151+
uses: "networktocode/gh-action-setup-poetry-environment@v7"
134152
with:
135153
poetry-version: "2.1.3"
136154
- name: "Linting: markdownlint"
@@ -155,7 +173,7 @@ jobs:
155173
- name: "Check out repository code"
156174
uses: "actions/checkout@v4"
157175
- name: "Setup environment"
158-
uses: "networktocode/gh-action-setup-poetry-environment@v6"
176+
uses: "networktocode/gh-action-setup-poetry-environment@v7"
159177
with:
160178
poetry-version: "2.1.3"
161179
- name: "Constrain Nautobot version and regenerate lock file"
@@ -210,7 +228,7 @@ jobs:
210228
- name: "Check out repository code"
211229
uses: "actions/checkout@v4"
212230
- name: "Setup environment"
213-
uses: "networktocode/gh-action-setup-poetry-environment@v6"
231+
uses: "networktocode/gh-action-setup-poetry-environment@v7"
214232
with:
215233
poetry-version: "2.1.3"
216234
- name: "Constrain Nautobot version and regenerate lock file"
@@ -260,7 +278,7 @@ jobs:
260278
- name: "Check out repository code"
261279
uses: "actions/checkout@v4"
262280
- name: "Setup environment"
263-
uses: "networktocode/gh-action-setup-poetry-environment@v6"
281+
uses: "networktocode/gh-action-setup-poetry-environment@v7"
264282
with:
265283
poetry-version: "2.1.3"
266284
- name: "Constrain Nautobot version and regenerate lock file"
@@ -328,7 +346,7 @@ jobs:
328346
with:
329347
name: "poetry-lock"
330348
- name: "Setup environment"
331-
uses: "networktocode/gh-action-setup-poetry-environment@v6"
349+
uses: "networktocode/gh-action-setup-poetry-environment@v7"
332350
with:
333351
poetry-version: "2.1.3"
334352
- name: "Check for changelog entry"
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 App Release Notes and update mkdocs.yml"
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: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ 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"
1818
python-version: "3.12"
@@ -104,3 +104,62 @@ jobs:
104104
}
105105
]
106106
}
107+
108+
create-pr-to-develop:
109+
if: "github.event.release.target_commitish == 'main'"
110+
permissions:
111+
contents: "write"
112+
pull-requests: "write"
113+
name: "Create a PR from main into develop"
114+
needs:
115+
- "publish-github"
116+
- "publish-pypi"
117+
runs-on: "ubuntu-latest"
118+
steps:
119+
- name: "Checkout main"
120+
uses: "actions/checkout@v4"
121+
with:
122+
ref: "main"
123+
fetch-depth: 0
124+
125+
- name: "Setup environment"
126+
uses: "networktocode/gh-action-setup-poetry-environment@v6"
127+
with:
128+
poetry-version: "2.1.3"
129+
poetry-install-options: "--no-root"
130+
131+
- name: "Create release branch from main"
132+
id: "branch"
133+
run: |
134+
135+
git config user.name "${{ github.actor }}"
136+
git config user.email "${{ github.actor }}@users.noreply.github.com"
137+
138+
TAG_NAME="${{ github.event.release.tag_name }}"
139+
VERSION="${TAG_NAME#v}"
140+
141+
BRANCH_NAME="release-${VERSION}-to-develop"
142+
143+
# Ensure release branch doesn't already exist
144+
if git rev-parse --verify origin/$BRANCH_NAME > /dev/null 2>&1; then
145+
echo "Error: Release branch $BRANCH_NAME already exists."
146+
exit 1
147+
fi
148+
149+
git checkout -b "$BRANCH_NAME"
150+
151+
poetry version prepatch
152+
git add pyproject.toml && git commit -m "Bump version"
153+
git push origin "$BRANCH_NAME"
154+
155+
echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT
156+
157+
- name: "Create Pull Request to develop"
158+
env:
159+
GH_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
160+
run: |
161+
gh pr create \
162+
--title "Post release ${{ github.event.release.tag_name }} to develop" \
163+
--body "Please do a merge commit." \
164+
--base "develop" \
165+
--head "${{ steps.branch.outputs.branch_name }}"

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Apache Software License 2.0
22

3-
Copyright (c) 2025, Network to Code, LLC
3+
Copyright (c) 2026, Network to Code, LLC
44

55
Licensed under the Apache License, Version 2.0 (the "License");
66
you may not use this file except in compliance with the License.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Rebaked from the cookie `nautobot-app-v3.1.1`.

0 commit comments

Comments
 (0)