Skip to content

Commit 9d10de5

Browse files
committed
feat(ci): implement automatic draft release management
- Add draft-release job in ci.yml that creates/updates draft release with tag 'next' and title 'Upcoming Changes 🍿' - Generate release notes based on commits since latest published release - Add step in publish.yml to delete draft release after successful publish - Follows indentcorp/backend pattern for automatic draft release management 🤖 Generated with assistance of OhMyOpenCode (https://github.com/code-yeongyu/oh-my-opencode)
1 parent 30ae22a commit 9d10de5

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

.github/workflows/ci.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,61 @@ jobs:
6767
run: |
6868
test -f dist/index.js || (echo "ERROR: dist/index.js not found!" && exit 1)
6969
test -f dist/index.d.ts || (echo "ERROR: dist/index.d.ts not found!" && exit 1)
70+
71+
draft-release:
72+
runs-on: ubuntu-latest
73+
needs: [build]
74+
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
75+
permissions:
76+
contents: write
77+
steps:
78+
- uses: actions/checkout@v4
79+
with:
80+
fetch-depth: 0
81+
82+
- name: Get latest published release tag
83+
id: latest-release
84+
run: |
85+
LATEST_TAG=$(gh release list --exclude-drafts --exclude-pre-releases --limit 1 --json tagName --jq '.[0].tagName // empty')
86+
echo "tag=${LATEST_TAG}" >> $GITHUB_OUTPUT
87+
echo "Latest published release: ${LATEST_TAG:-none}"
88+
env:
89+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
90+
91+
- name: Generate release notes
92+
id: notes
93+
run: |
94+
if [ -n "${{ steps.latest-release.outputs.tag }}" ]; then
95+
NOTES=$(gh api repos/${{ github.repository }}/releases/generate-notes \
96+
-f tag_name=next \
97+
-f previous_tag_name=${{ steps.latest-release.outputs.tag }} \
98+
--jq '.body')
99+
else
100+
NOTES="Initial release"
101+
fi
102+
echo "notes<<EOF" >> $GITHUB_OUTPUT
103+
echo "$NOTES" >> $GITHUB_OUTPUT
104+
echo "EOF" >> $GITHUB_OUTPUT
105+
env:
106+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
107+
108+
- name: Create or update draft release
109+
run: |
110+
EXISTING_DRAFT=$(gh release list --json tagName,isDraft --jq '.[] | select(.isDraft == true and .tagName == "next") | .tagName')
111+
112+
if [ -n "$EXISTING_DRAFT" ]; then
113+
echo "Updating existing draft release..."
114+
gh release edit next \
115+
--title "Upcoming Changes 🍿" \
116+
--notes "${{ steps.notes.outputs.notes }}" \
117+
--draft
118+
else
119+
echo "Creating new draft release..."
120+
gh release create next \
121+
--title "Upcoming Changes 🍿" \
122+
--notes "${{ steps.notes.outputs.notes }}" \
123+
--draft \
124+
--target ${{ github.sha }}
125+
fi
126+
env:
127+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/publish.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,8 @@ jobs:
8989
CI: true
9090
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
9191
NPM_CONFIG_PROVENANCE: true
92+
93+
- name: Delete draft release
94+
run: gh release delete next --yes 2>/dev/null || echo "No draft release to delete"
95+
env:
96+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)