Skip to content

Commit 6457df7

Browse files
authored
Merge pull request #6 from draphy/draphy/dro-64-test-draphyos-and-optimize
feat: [DRO-64] Release workflow
2 parents 4e49ee6 + e263617 commit 6457df7

1 file changed

Lines changed: 184 additions & 31 deletions

File tree

.github/workflows/release.yml

Lines changed: 184 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,43 +10,196 @@ permissions:
1010
pull-requests: write
1111

1212
jobs:
13-
release-please:
14-
name: Release Please
13+
release:
14+
name: Auto Release
1515
runs-on: ubuntu-latest
16-
outputs:
17-
release_created: ${{ steps.release.outputs.release_created }}
18-
tag_name: ${{ steps.release.outputs.tag_name }}
19-
pr: ${{ steps.release.outputs.pr }}
20-
steps:
21-
- name: Release Please
22-
id: release
23-
uses: googleapis/release-please-action@v4
24-
with:
25-
release-type: simple
26-
include-v-in-tag: true
27-
changelog-types: >
28-
[
29-
{"type": "feat", "section": "Features", "hidden": false},
30-
{"type": "fix", "section": "Bug Fixes", "hidden": false},
31-
{"type": "perf", "section": "Performance", "hidden": false},
32-
{"type": "docs", "section": "Documentation", "hidden": false},
33-
{"type": "chore", "section": "Maintenance", "hidden": true},
34-
{"type": "style", "section": "Styles", "hidden": true},
35-
{"type": "refactor", "section": "Refactoring", "hidden": true}
36-
]
37-
38-
validate:
39-
name: Validate Release
40-
runs-on: ubuntu-latest
41-
needs: release-please
42-
if: ${{ needs.release-please.outputs.release_created }}
4316
steps:
4417
- name: Checkout
4518
uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 0
21+
22+
- name: Get latest tag
23+
id: get_tag
24+
run: |
25+
# Get latest semver tag (v*.*.*)
26+
LATEST_TAG=$(git tag -l "v[0-9]*.[0-9]*.[0-9]*" | sort -V | tail -1)
27+
if [ -z "$LATEST_TAG" ]; then
28+
LATEST_TAG="v0.0.0"
29+
fi
30+
echo "latest_tag=$LATEST_TAG" >> $GITHUB_OUTPUT
31+
echo "Latest tag: $LATEST_TAG"
32+
33+
- name: Analyze commits and determine version
34+
id: version
35+
run: |
36+
LATEST_TAG="${{ steps.get_tag.outputs.latest_tag }}"
37+
38+
# Get commits since last tag
39+
if [ "$LATEST_TAG" = "v0.0.0" ]; then
40+
COMMITS=$(git log --pretty=format:"%s" HEAD)
41+
else
42+
COMMITS=$(git log --pretty=format:"%s" ${LATEST_TAG}..HEAD)
43+
fi
4644
47-
- name: Validate Scripts
45+
if [ -z "$COMMITS" ]; then
46+
echo "No new commits since $LATEST_TAG"
47+
echo "skip=true" >> $GITHUB_OUTPUT
48+
exit 0
49+
fi
50+
51+
echo "Commits since $LATEST_TAG:"
52+
echo "$COMMITS"
53+
54+
# Determine version bump from conventional commits
55+
MAJOR=0
56+
MINOR=0
57+
PATCH=0
58+
59+
while IFS= read -r commit; do
60+
if echo "$commit" | grep -qE "^feat(\(.+\))?!:|^fix(\(.+\))?!:|^refactor(\(.+\))?!:|BREAKING CHANGE"; then
61+
MAJOR=1
62+
elif echo "$commit" | grep -qE "^feat(\(.+\))?:"; then
63+
MINOR=1
64+
elif echo "$commit" | grep -qE "^fix(\(.+\))?:|^perf(\(.+\))?:|^refactor(\(.+\))?:"; then
65+
PATCH=1
66+
fi
67+
done <<< "$COMMITS"
68+
69+
# Parse current version
70+
VERSION="${LATEST_TAG#v}"
71+
IFS='.' read -r CUR_MAJOR CUR_MINOR CUR_PATCH <<< "$VERSION"
72+
73+
# Calculate new version
74+
if [ "$MAJOR" -eq 1 ]; then
75+
NEW_VERSION="$((CUR_MAJOR + 1)).0.0"
76+
BUMP_TYPE="major"
77+
elif [ "$MINOR" -eq 1 ]; then
78+
NEW_VERSION="${CUR_MAJOR}.$((CUR_MINOR + 1)).0"
79+
BUMP_TYPE="minor"
80+
elif [ "$PATCH" -eq 1 ]; then
81+
NEW_VERSION="${CUR_MAJOR}.${CUR_MINOR}.$((CUR_PATCH + 1))"
82+
BUMP_TYPE="patch"
83+
else
84+
echo "No releasable commits (need feat:, fix:, perf:, refactor:, or breaking change)"
85+
echo "skip=true" >> $GITHUB_OUTPUT
86+
exit 0
87+
fi
88+
89+
echo "new_version=v${NEW_VERSION}" >> $GITHUB_OUTPUT
90+
echo "bump_type=$BUMP_TYPE" >> $GITHUB_OUTPUT
91+
echo "skip=false" >> $GITHUB_OUTPUT
92+
echo "New version: v${NEW_VERSION} ($BUMP_TYPE bump)"
93+
94+
- name: Generate release notes
95+
if: steps.version.outputs.skip != 'true'
96+
id: notes
4897
run: |
49-
echo "🚀 Validating ${{ needs.release-please.outputs.tag_name }}..."
98+
LATEST_TAG="${{ steps.get_tag.outputs.latest_tag }}"
99+
NEW_VERSION="${{ steps.version.outputs.new_version }}"
100+
101+
# Generate notes from commits
102+
NOTES=""
103+
FEATURES=""
104+
FIXES=""
105+
PERF=""
106+
OTHER=""
107+
108+
if [ "$LATEST_TAG" = "v0.0.0" ]; then
109+
COMMITS=$(git log --pretty=format:"%s|%h" HEAD)
110+
else
111+
COMMITS=$(git log --pretty=format:"%s|%h" ${LATEST_TAG}..HEAD)
112+
fi
113+
114+
while IFS='|' read -r msg hash; do
115+
if echo "$msg" | grep -qE "^feat(\(.+\))?:"; then
116+
CLEAN_MSG=$(echo "$msg" | sed -E 's/^feat(\([^)]+\))?:\s*//')
117+
FEATURES="${FEATURES}- ${CLEAN_MSG} (${hash})\n"
118+
elif echo "$msg" | grep -qE "^fix(\(.+\))?:"; then
119+
CLEAN_MSG=$(echo "$msg" | sed -E 's/^fix(\([^)]+\))?:\s*//')
120+
FIXES="${FIXES}- ${CLEAN_MSG} (${hash})\n"
121+
elif echo "$msg" | grep -qE "^perf(\(.+\))?:"; then
122+
CLEAN_MSG=$(echo "$msg" | sed -E 's/^perf(\([^)]+\))?:\s*//')
123+
PERF="${PERF}- ${CLEAN_MSG} (${hash})\n"
124+
fi
125+
done <<< "$COMMITS"
126+
127+
# Build release notes
128+
if [ -n "$FEATURES" ]; then
129+
NOTES="${NOTES}## Features\n${FEATURES}\n"
130+
fi
131+
if [ -n "$FIXES" ]; then
132+
NOTES="${NOTES}## Bug Fixes\n${FIXES}\n"
133+
fi
134+
if [ -n "$PERF" ]; then
135+
NOTES="${NOTES}## Performance\n${PERF}\n"
136+
fi
137+
138+
# Add installation instructions
139+
NOTES="${NOTES}## Installation\n\`\`\`bash\ncurl -fsSL https://raw.githubusercontent.com/draphy/draphyOS/latest/install.sh | bash\n\`\`\`"
140+
141+
# Save to file (handle multiline)
142+
echo -e "$NOTES" > /tmp/release_notes.md
143+
echo "Generated release notes"
144+
145+
- name: Validate scripts
146+
if: steps.version.outputs.skip != 'true'
147+
run: |
148+
echo "Validating shell scripts..."
50149
bash -n install.sh
51150
bash -n uninstall.sh
52151
echo "✅ Scripts are valid"
152+
153+
- name: Create tag and release
154+
if: steps.version.outputs.skip != 'true'
155+
run: |
156+
NEW_VERSION="${{ steps.version.outputs.new_version }}"
157+
158+
# Configure git
159+
git config user.name "github-actions[bot]"
160+
git config user.email "github-actions[bot]@users.noreply.github.com"
161+
162+
# Create and push tag
163+
git tag "$NEW_VERSION"
164+
git push origin "$NEW_VERSION"
165+
166+
# Create GitHub release
167+
gh release create "$NEW_VERSION" \
168+
--title "$NEW_VERSION" \
169+
--notes-file /tmp/release_notes.md \
170+
--latest
171+
172+
echo "✅ Released $NEW_VERSION"
173+
env:
174+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
175+
176+
- name: Comment on merged PRs
177+
if: steps.version.outputs.skip != 'true'
178+
run: |
179+
LATEST_TAG="${{ steps.get_tag.outputs.latest_tag }}"
180+
NEW_VERSION="${{ steps.version.outputs.new_version }}"
181+
182+
# Get PR numbers from commits since last tag
183+
if [ "$LATEST_TAG" = "v0.0.0" ]; then
184+
COMMITS=$(git log --pretty=format:"%H" HEAD)
185+
else
186+
COMMITS=$(git log --pretty=format:"%H" ${LATEST_TAG}..HEAD)
187+
fi
188+
189+
# Find PRs associated with these commits
190+
COMMENTED_PRS=""
191+
while IFS= read -r sha; do
192+
# Get PR number for this commit
193+
PR_DATA=$(gh pr list --state merged --search "$sha" --json number --jq '.[0].number' 2>/dev/null || echo "")
194+
195+
if [ -n "$PR_DATA" ] && [ "$PR_DATA" != "null" ]; then
196+
# Avoid duplicate comments
197+
if [[ ! "$COMMENTED_PRS" =~ "$PR_DATA" ]]; then
198+
gh pr comment "$PR_DATA" --body "🚀 Released in [$NEW_VERSION](https://github.com/${{ github.repository }}/releases/tag/$NEW_VERSION)" 2>/dev/null || true
199+
COMMENTED_PRS="${COMMENTED_PRS} ${PR_DATA}"
200+
echo "Commented on PR #$PR_DATA"
201+
fi
202+
fi
203+
done <<< "$COMMITS"
204+
env:
205+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)