Skip to content

Commit dc2f5d4

Browse files
committed
feat(release): add release draft creation step
This update introduces a new job to create a release draft in the GitHub Actions workflow. It includes steps to fetch tag information, generate a changelog based on commit history, and create a draft release using the generated changelog.
1 parent c90e65c commit dc2f5d4

1 file changed

Lines changed: 54 additions & 1 deletion

File tree

.github/workflows/test-and-publish.yml

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,57 @@ jobs:
9090
echo "Version verified: $PACKAGE_VERSION"
9191
9292
- name: Publish to npm
93-
run: npm publish --access public
93+
run: npm publish --access public
94+
95+
release:
96+
name: Create Release Draft
97+
needs: [test, publish]
98+
runs-on: ubuntu-latest
99+
if: startsWith(github.ref, 'refs/tags/v')
100+
101+
permissions:
102+
contents: write
103+
104+
steps:
105+
- name: Checkout repository
106+
uses: actions/checkout@v4
107+
with:
108+
fetch-depth: 0
109+
110+
- name: Get tag info
111+
id: tag_info
112+
run: |
113+
TAG_NAME=${GITHUB_REF#refs/tags/}
114+
echo "tag_name=$TAG_NAME" >> $GITHUB_OUTPUT
115+
echo "version=${TAG_NAME#v}" >> $GITHUB_OUTPUT
116+
117+
- name: Generate changelog
118+
id: changelog
119+
run: |
120+
PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
121+
122+
if [ -n "$PREV_TAG" ]; then
123+
echo "Getting changes since $PREV_TAG"
124+
CHANGELOG=$(git log --pretty=format:"- %s (%h)" $PREV_TAG..HEAD)
125+
else
126+
echo "Getting all commits"
127+
CHANGELOG=$(git log --pretty=format:"- %s (%h)")
128+
fi
129+
130+
{
131+
echo 'CHANGELOG<<EOF'
132+
echo "## What's Changed"
133+
echo ""
134+
echo "$CHANGELOG"
135+
echo EOF
136+
} >> $GITHUB_OUTPUT
137+
138+
- name: Create Release Draft
139+
uses: softprops/action-gh-release@v2
140+
with:
141+
tag_name: ${{ steps.tag_info.outputs.tag_name }}
142+
name: Release ${{ steps.tag_info.outputs.tag_name }}
143+
body: ${{ steps.changelog.outputs.CHANGELOG }}
144+
draft: true
145+
prerelease: ${{ contains(steps.tag_info.outputs.tag_name, '-') }}
146+
generate_release_notes: true

0 commit comments

Comments
 (0)