-
Notifications
You must be signed in to change notification settings - Fork 1
179 lines (156 loc) · 6.64 KB
/
releaser.yaml
File metadata and controls
179 lines (156 loc) · 6.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
name: Auto-Release CLI on Push to Main
on:
push:
branches:
- main
workflow_dispatch:
concurrency:
group: release-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: write
pull-requests: write
jobs:
release:
if: "github.event_name == 'workflow_dispatch' || contains(github.event.head_commit.message, '[release]')"
runs-on: ubuntu-latest
steps:
- name: Checkout code with full history
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- name: Install GitHub CLI
run: |
sudo apt-get update
sudo apt-get install -y gh
- name: Install dependencies
run: |
npm install --global prettier@3.5.3
npm install --global semver
- name: Get current and previous tags
id: tags
run: |
git fetch -a
# CURRENT_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
#this is test
CURRENT_TAG=$(git tag --sort=-creatordate | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | head -n 1 || echo "")
if [ -n "$CURRENT_TAG" ]; then
# PREV_TAG=$(git describe --tags --abbrev=0 "$CURRENT_TAG"^ 2>/dev/null || echo "")
PREV_TAG=$(git tag --sort=-creatordate | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | sed -n 2p || echo "")
else
PREV_TAG=""
fi
echo "Current tag: $CURRENT_TAG"
echo "Previous tag: $PREV_TAG"
echo "current_tag=$CURRENT_TAG" >> $GITHUB_OUTPUT
echo "previous_tag=$PREV_TAG" >> $GITHUB_OUTPUT
- name: Check for new commits
id: check_commits
run: |
CURRENT_TAG=${{ steps.tags.outputs.current_tag }}
if [ -z "$CURRENT_TAG" ]; then
echo "No existing tags found - this is the first release"
echo "skip=false" >> $GITHUB_OUTPUT
exit 0
fi
git fetch origin main --tags
COMMIT_COUNT=$(git rev-list --count "$CURRENT_TAG..origin/main" --no-merges)
if [ "$COMMIT_COUNT" -eq 0 ]; then
echo "No new commits since $CURRENT_TAG. Skipping release."
echo "skip=true" >> $GITHUB_OUTPUT
else
echo "Found $COMMIT_COUNT new commits since $CURRENT_TAG"
echo "skip=false" >> $GITHUB_OUTPUT
fi
- name: Determine new version
if: steps.check_commits.outputs.skip != 'true'
id: new_version
run: |
CURRENT_TAG=${{ steps.tags.outputs.current_tag }}
if [ -z "$CURRENT_TAG" ]; then
echo "First release - creating v0.1.0"
echo "new_tag=v0.1.0" >> $GITHUB_OUTPUT
exit 0
fi
VERSION=$(echo "$CURRENT_TAG" | sed 's/^v//')
COMMIT_MSGS=$(git log "$CURRENT_TAG..HEAD" --no-merges --pretty=%B)
if echo "$COMMIT_MSGS" | grep -qi "BREAKING CHANGE"; then
NEW_VERSION=$(semver "$VERSION" -i major)
elif echo "$COMMIT_MSGS" | grep -qi "^feat:"; then
NEW_VERSION=$(semver "$VERSION" -i minor)
else
NEW_VERSION=$(semver "$VERSION" -i patch)
fi
NEW_TAG="v$NEW_VERSION"
while git rev-parse "$NEW_TAG" >/dev/null 2>&1; do
NEW_VERSION=$(semver "$NEW_VERSION" -i patch)
NEW_TAG="v$NEW_VERSION"
done
echo "new_tag=$NEW_TAG" >> $GITHUB_OUTPUT
- name: Create changelog branch
if: steps.check_commits.outputs.skip != 'true'
id: create_branch
run: |
git config user.name "GitHub Actions Bot"
git config user.email "actions@github.com"
BRANCH_NAME="changelog-update-/${{ steps.new_version.outputs.new_tag }}"
git checkout -b "$BRANCH_NAME"
echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Generate Changelog
if: steps.check_commits.outputs.skip != 'true'
env:
RELEASE_TAG: ${{ steps.new_version.outputs.new_tag }}
PREVIOUS_TAG: ${{ steps.tags.outputs.current_tag }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git tag -f "temp-${{ steps.new_version.outputs.new_tag }}"
chmod +x .github/scripts/generate-changelog.sh
.github/scripts/generate-changelog.sh
git tag -d "temp-${{ steps.new_version.outputs.new_tag }}"
git diff --quiet CHANGELOG.md || echo "Changelog updated"
- name: Commit changelog updates
if: steps.check_commits.outputs.skip != 'true'
id: commit_changelog
run: |
git add CHANGELOG.md
if git diff --staged --quiet; then
echo "No changes to CHANGELOG.md. Skipping commit."
echo "skip_pr=true" >> $GITHUB_OUTPUT
exit 0
fi
git commit -m "Update CHANGELOG.md for ${{ steps.new_version.outputs.new_tag }}"
echo "skip_pr=false" >> $GITHUB_OUTPUT
- name: Create and push release tag
if: steps.check_commits.outputs.skip != 'true' && steps.commit_changelog.outputs.skip_pr != 'true'
run: |
RELEASE_COMMIT=$(git rev-parse HEAD)
# Fetch full history and tags to avoid non-fast-forward errors
git fetch --unshallow || true
git fetch --tags
git fetch origin "+refs/heads/*:refs/remotes/origin/*"
# Rebase if the branch exists remotely
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
git pull --rebase origin "$CURRENT_BRANCH" || true
# Create and push tag forcefully
git tag -f ${{ steps.new_version.outputs.new_tag }} -m "Release ${{ steps.new_version.outputs.new_tag }}" $RELEASE_COMMIT
git push origin ${{ steps.new_version.outputs.new_tag }} --force
- name: Push release branch
if: steps.check_commits.outputs.skip != 'true' && steps.commit_changelog.outputs.skip_pr != 'true'
run: |
git push origin ${{ steps.create_branch.outputs.branch_name }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create Pull Request
if: steps.check_commits.outputs.skip != 'true' && steps.commit_changelog.outputs.skip_pr != 'true'
run: |
gh pr create \
--base main \
--head ${{ steps.create_branch.outputs.branch_name }} \
--title "Release ${{ steps.new_version.outputs.new_tag }}" \
--body "Automated release PR for ${{ steps.new_version.outputs.new_tag }}" \
--reviewer enzokamal || echo "PR creation failed, possibly no changes or reviewer issue"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}