88concurrency :
99 group : ${{ github.event.pull_request.number || github.ref }}
1010 cancel-in-progress : true
11-
11+
1212permissions :
1313 contents : write
1414 pull-requests : read
@@ -30,10 +30,10 @@ jobs:
3030 run : |
3131 merged_by="${{ github.event.pull_request.merged_by.login }}"
3232 echo "PR was merged by: $merged_by"
33-
33+
3434 # Get authorized users from CODEOWNERS file
3535 authorized_users=()
36-
36+
3737 # Read CODEOWNERS file if it exists
3838 if [[ -f ".github/CODEOWNERS" ]]; then
3939 echo "[INFO] Reading CODEOWNERS file..."
@@ -46,21 +46,21 @@ jobs:
4646 else
4747 echo "[WARN] No CODEOWNERS file found"
4848 fi
49-
49+
5050 # Get repository collaborators with admin/maintain permissions using GitHub API
5151 echo "[CHECK] Checking repository permissions..."
52-
52+
5353 # Check if user has admin or maintain permissions
5454 user_permission=$(curl -s -H "Authorization: token ${{ secrets.PAT }}" \
5555 -H "Accept: application/vnd.github.v3+json" \
5656 "https://api.github.com/repos/${{ github.repository }}/collaborators/$merged_by/permission" | \
5757 jq -r '.permission // "none"')
58-
58+
5959 echo "User $merged_by has permission level: $user_permission"
60-
60+
6161 # Check if user is authorized
6262 is_authorized=false
63-
63+
6464 # Check if user is in CODEOWNERS
6565 for user in "${authorized_users[@]}"; do
6666 if [[ "$user" == "$merged_by" ]]; then
@@ -69,37 +69,37 @@ jobs:
6969 break
7070 fi
7171 done
72-
72+
7373 # Check if user has admin or maintain permissions
7474 if [[ "$user_permission" == "admin" || "$user_permission" == "maintain" ]]; then
7575 is_authorized=true
7676 echo "[OK] User $merged_by is authorized via repository permissions ($user_permission)"
7777 fi
78-
78+
7979 # Check if user is organization owner (for metaversecloud-com org)
8080 org_response=$(curl -s -H "Authorization: token ${{ secrets.PAT }}" \
8181 -H "Accept: application/vnd.github.v3+json" \
8282 "https://api.github.com/orgs/metaversecloud-com/members/$merged_by" \
8383 -w "%{http_code}")
84-
84+
8585 # Extract HTTP status code from the response
8686 http_code=${org_response: -3}
87-
87+
8888 if [[ "$http_code" == "200" ]]; then
8989 # Check if user is an owner
9090 owner_status=$(curl -s -H "Authorization: token ${{ secrets.PAT }}" \
9191 -H "Accept: application/vnd.github.v3+json" \
9292 "https://api.github.com/orgs/metaversecloud-com/memberships/$merged_by" | \
9393 jq -r '.role // "none"')
94-
94+
9595 if [[ "$owner_status" == "admin" ]]; then
9696 is_authorized=true
9797 echo "[OK] User $merged_by is authorized as organization owner"
9898 fi
9999 fi
100-
100+
101101 echo "is_authorized=$is_authorized" >> $GITHUB_OUTPUT
102-
102+
103103 if [[ "$is_authorized" == "false" ]]; then
104104 echo "[ERROR] User $merged_by is not authorized to trigger releases"
105105 echo "[TIP] Authorized users include:"
@@ -117,16 +117,16 @@ jobs:
117117 run : |
118118 labels='${{ toJson(github.event.pull_request.labels.*.name) }}'
119119 echo "PR Labels: $labels"
120-
120+
121121 has_release_label=false
122122 has_major=false
123123 has_minor=false
124124 has_patch=false
125-
125+
126126 # Check if release label exists
127127 if echo "$labels" | grep -q "release"; then
128128 has_release_label=true
129-
129+
130130 # Check for each type of version bump
131131 if echo "$labels" | grep -q "major"; then
132132 has_major=true
@@ -137,13 +137,13 @@ jobs:
137137 if echo "$labels" | grep -q "patch"; then
138138 has_patch=true
139139 fi
140-
140+
141141 # If no specific version type is specified, default to patch
142142 if [[ "$has_major" == "false" && "$has_minor" == "false" && "$has_patch" == "false" ]]; then
143143 has_patch=true
144144 fi
145145 fi
146-
146+
147147 echo "should_release=$has_release_label" >> $GITHUB_OUTPUT
148148 echo "has_major=$has_major" >> $GITHUB_OUTPUT
149149 echo "has_minor=$has_minor" >> $GITHUB_OUTPUT
@@ -163,51 +163,51 @@ jobs:
163163 run : |
164164 git config --global user.email "github-actions[bot]@users.noreply.github.com"
165165 git config --global user.name "github-actions[bot]"
166-
166+
167167 # Get the latest tag from git
168168 latest_tag=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
169169 echo "Latest git tag: $latest_tag"
170-
170+
171171 # Remove 'v' prefix if present
172172 current_version=${latest_tag#v}
173173 echo "Current version: $current_version"
174-
174+
175175 # Parse current version
176176 IFS='.' read -r major minor patch <<< "$current_version"
177177 echo "Parsed version - Major: $major, Minor: $minor, Patch: $patch"
178-
178+
179179 # Apply cumulative version bumps
180180 if [[ "${{ steps.check.outputs.has_major }}" == "true" ]]; then
181181 major=$((major + 1))
182182 minor=0 # Reset minor when major is bumped
183183 patch=0 # Reset patch when major is bumped
184184 echo "Applied major bump: $major.0.0"
185185 fi
186-
186+
187187 if [[ "${{ steps.check.outputs.has_minor }}" == "true" ]]; then
188188 minor=$((minor + 1))
189189 if [[ "${{ steps.check.outputs.has_major }}" != "true" ]]; then
190190 patch=0 # Reset patch when minor is bumped (only if major wasn't bumped)
191191 fi
192192 echo "Applied minor bump: $major.$minor.$patch"
193193 fi
194-
194+
195195 if [[ "${{ steps.check.outputs.has_patch }}" == "true" ]]; then
196196 patch=$((patch + 1))
197197 echo "Applied patch bump: $major.$minor.$patch"
198198 fi
199-
199+
200200 new_version="$major.$minor.$patch"
201201 echo "Final calculated version: $new_version"
202-
202+
203203 # Create package.json if it doesn't exist
204204 if [[ ! -f "package.json" ]]; then
205205 echo '{"version": "0.0.0"}' > package.json
206206 fi
207-
207+
208208 # Update package.json with new version
209209 npm version $new_version --no-git-tag-version --allow-same-version
210-
210+
211211 echo "NEW_VERSION=v$new_version" >> $GITHUB_ENV
212212 echo "New version will be: v$new_version"
213213
@@ -222,18 +222,18 @@ jobs:
222222 make_latest : true
223223 body : |
224224 ## ? Release ${{ env.NEW_VERSION }}
225-
225+
226226 **Version Bumps Applied:**
227227 - Major: ${{ steps.check.outputs.has_major }}
228228 - Minor: ${{ steps.check.outputs.has_minor }}
229229 - Patch: ${{ steps.check.outputs.has_patch }}
230-
230+
231231 **Triggered by:** PR #${{ github.event.pull_request.number }} - ${{ github.event.pull_request.title }}
232232 **Merged by:** @${{ github.event.pull_request.merged_by.login }}
233-
233+
234234 ### Changes in this PR
235235 ${{ github.event.pull_request.body }}
236-
236+
237237 ---
238238 *This release was automatically created by the Auto Release workflow*
239239
0 commit comments