Skip to content

Commit fe1155c

Browse files
authored
Add release job to open PR from main into next (#404)
1 parent d85470d commit fe1155c

4 files changed

Lines changed: 115 additions & 0 deletions

File tree

changes/404.housekeeping

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Added a release workflow job that opens a pull request from `main` into `next` after a release is published from `main`.

nautobot-app-commercial/{{ cookiecutter.project_slug }}/.github/workflows/release.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,3 +243,57 @@ jobs:
243243
--body "Please do a merge commit." \
244244
--base "develop" \
245245
--head "{% raw %}${{ steps.branch.outputs.branch_name }}{% endraw %}"
246+
247+
create-pr-to-next:
248+
if: "github.event.release.target_commitish == 'main'"
249+
permissions:
250+
contents: "write"
251+
pull-requests: "write"
252+
name: "Create a PR from main into next"
253+
needs:
254+
- "publish-github"
255+
- "publish-artifactory"
256+
runs-on: "ubuntu-latest"
257+
steps:
258+
- name: "Checkout main"
259+
uses: "actions/checkout@v4"
260+
with:
261+
ref: "main"
262+
fetch-depth: 0
263+
264+
- name: "Create release branch from main"
265+
id: "branch"
266+
run: |
267+
# Skip if there is no 'next' branch to merge into.
268+
if ! git ls-remote --exit-code --heads origin next > /dev/null 2>&1; then
269+
echo "No 'next' branch exists; skipping main -> next PR."
270+
exit 0
271+
fi
272+
273+
TAG_NAME="{% raw %}${{ github.event.release.tag_name }}{% endraw %}"
274+
VERSION="${TAG_NAME#v}"
275+
276+
BRANCH_NAME="release-${VERSION}-to-next"
277+
278+
# Ensure release branch doesn't already exist
279+
if git rev-parse --verify origin/$BRANCH_NAME > /dev/null 2>&1; then
280+
echo "Error: Release branch $BRANCH_NAME already exists."
281+
exit 1
282+
fi
283+
284+
# Base off main, since it's in the released state.
285+
git checkout -b "$BRANCH_NAME"
286+
git push origin "$BRANCH_NAME"
287+
288+
echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT
289+
290+
- name: "Create a PR to next"
291+
if: "steps.branch.outputs.branch_name != ''"
292+
env:
293+
GH_TOKEN: "{% raw %}${{ secrets.NTC_LLC_NAUTOBOT_APPS_REPO_WORKFLOW_GH_TOKEN }}{% endraw %}"
294+
run: |
295+
gh pr create \
296+
--title "Post release {% raw %}${{ github.event.release.tag_name }}{% endraw %} to next" \
297+
--body "Please do a merge commit." \
298+
--base "next" \
299+
--head "{% raw %}${{ steps.branch.outputs.branch_name }}{% endraw %}"

nautobot-app/{{ cookiecutter.project_slug }}/.github/workflows/release.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,3 +238,57 @@ jobs:
238238
--body "Please do a merge commit." \
239239
--base "develop" \
240240
--head "{% raw %}${{ steps.branch.outputs.branch_name }}{% endraw %}"
241+
242+
create-pr-to-next:
243+
if: "github.event.release.target_commitish == 'main'"
244+
permissions:
245+
contents: "write"
246+
pull-requests: "write"
247+
name: "Create a PR from main into next"
248+
needs:
249+
- "publish-github"
250+
- "publish-pypi"
251+
runs-on: "ubuntu-latest"
252+
steps:
253+
- name: "Checkout main"
254+
uses: "actions/checkout@v4"
255+
with:
256+
ref: "main"
257+
fetch-depth: 0
258+
259+
- name: "Create release branch from main"
260+
id: "branch"
261+
run: |
262+
# Skip if there is no 'next' branch to merge into.
263+
if ! git ls-remote --exit-code --heads origin next > /dev/null 2>&1; then
264+
echo "No 'next' branch exists; skipping main -> next PR."
265+
exit 0
266+
fi
267+
268+
TAG_NAME="{% raw %}${{ github.event.release.tag_name }}{% endraw %}"
269+
VERSION="${TAG_NAME#v}"
270+
271+
BRANCH_NAME="release-${VERSION}-to-next"
272+
273+
# Ensure release branch doesn't already exist
274+
if git rev-parse --verify origin/$BRANCH_NAME > /dev/null 2>&1; then
275+
echo "Error: Release branch $BRANCH_NAME already exists."
276+
exit 1
277+
fi
278+
279+
# Base off main, since it's in the released state.
280+
git checkout -b "$BRANCH_NAME"
281+
git push origin "$BRANCH_NAME"
282+
283+
echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT
284+
285+
- name: "Create a PR to next"
286+
if: "steps.branch.outputs.branch_name != ''"
287+
env:
288+
GH_TOKEN: "{% raw %}${{ secrets.GH_NAUTOBOT_BOT_TOKEN }}{% endraw %}"
289+
run: |
290+
gh pr create \
291+
--title "Post release {% raw %}${{ github.event.release.tag_name }}{% endraw %} to next" \
292+
--body "Please do a merge commit." \
293+
--base "next" \
294+
--head "{% raw %}${{ steps.branch.outputs.branch_name }}{% endraw %}"

nautobot-app/{{ cookiecutter.project_slug }}/docs/dev/release_checklist.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ A draft release will automatically be created in GitHub when the Prepare Release
7070

7171
After a release has been published from the `main` branch, a new PR will automatically be created to merge the changes from `main` back into `develop` with a version bump to the next development version (e.g. `1.4.3a1`). Review and merge this PR once CI has completed and the PR has been approved.
7272

73+
### Sync the Release to `next`
74+
75+
Publishing a release from the `main` branch will also automatically create a PR to forward-port the released changes from `main` into `next`, so the `next` branch stays up to date.
76+
77+
If no `next` branch exists, this step is skipped automatically.
78+
7379
## Legacy Documentation for Releases
7480

7581
Please use the above process for all releases going forward, but if you need to refer to the old manual release process for any reason, here are the steps that were previously followed for releases.

0 commit comments

Comments
 (0)