Skip to content

Commit cb644fa

Browse files
asadsmalikAsad Malik
andauthored
Auto security release workflow now updates minor version if changes include user updates and adds TODO to PR title (#29)
Co-authored-by: Asad Malik <asadmal@amazon.com>
1 parent 0277f72 commit cb644fa

1 file changed

Lines changed: 65 additions & 10 deletions

File tree

.github/workflows/auto-security-release.yml

Lines changed: 65 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,28 +88,40 @@ jobs:
8888
echo "$COMMITS"
8989
9090
- name: Verify all commits are from dependabot
91-
if: steps.check-commits.outputs.has_commits == 'true' && inputs.force == false
91+
if: steps.check-commits.outputs.has_commits == 'true'
9292
id: verify-authors
9393
run: |
9494
LAST_TAG="${{ steps.last-tag.outputs.tag }}"
9595
NON_BOT_AUTHORS=$(git log "${LAST_TAG}..HEAD" --no-merges --format='%an <%ae>' -- "${{ inputs.working-directory }}" | sort -u | grep -iv 'dependabot' || true)
9696
if [ -n "$NON_BOT_AUTHORS" ]; then
9797
echo "Non-dependabot commits found from:"
9898
echo "$NON_BOT_AUTHORS"
99-
echo "Skipping auto-release — only dependabot-only changes qualify."
99+
if [ "${{ inputs.force }}" != "true" ]; then
100+
echo "Skipping auto-release — only dependabot-only changes qualify."
101+
echo "dependabot_only=false" >> "$GITHUB_OUTPUT"
102+
exit 0
103+
fi
104+
echo "Force flag set — proceeding with minor version bump"
100105
echo "dependabot_only=false" >> "$GITHUB_OUTPUT"
101-
exit 0
106+
echo "bump_type=minor" >> "$GITHUB_OUTPUT"
107+
else
108+
echo "All commits are from dependabot."
109+
echo "dependabot_only=true" >> "$GITHUB_OUTPUT"
110+
echo "bump_type=patch" >> "$GITHUB_OUTPUT"
102111
fi
103-
echo "dependabot_only=true" >> "$GITHUB_OUTPUT"
104-
echo "All commits are from dependabot."
105112
106113
- name: Bump version (node)
107114
if: (steps.verify-authors.outputs.dependabot_only == 'true' || inputs.force) && steps.detect.outputs.ecosystem == 'node'
108115
id: bump-node
109116
run: |
110117
CURRENT=$(jq -r .version package.json)
111118
IFS='.' read -r major minor patch <<< "$CURRENT"
112-
NEW_VERSION="${major}.${minor}.$((patch + 1))"
119+
BUMP_TYPE="${{ steps.verify-authors.outputs.bump_type || 'patch' }}"
120+
if [ "$BUMP_TYPE" = "minor" ]; then
121+
NEW_VERSION="${major}.$((minor + 1)).0"
122+
else
123+
NEW_VERSION="${major}.${minor}.$((patch + 1))"
124+
fi
113125
jq --arg v "$NEW_VERSION" '.version = $v' package.json > tmp.json && mv tmp.json package.json
114126
if [ -f package-lock.json ]; then
115127
jq --arg v "$NEW_VERSION" '.version = $v | .packages[""].version = $v' package-lock.json > tmp.json && mv tmp.json package-lock.json
@@ -123,7 +135,12 @@ jobs:
123135
run: |
124136
CURRENT=$(jq -r .version Package.version)
125137
IFS='.' read -r major minor patch <<< "$CURRENT"
126-
NEW_VERSION="${major}.${minor}.$((patch + 1))"
138+
BUMP_TYPE="${{ steps.verify-authors.outputs.bump_type || 'patch' }}"
139+
if [ "$BUMP_TYPE" = "minor" ]; then
140+
NEW_VERSION="${major}.$((minor + 1)).0"
141+
else
142+
NEW_VERSION="${major}.${minor}.$((patch + 1))"
143+
fi
127144
jq --arg v "$NEW_VERSION" '.version = $v' Package.version > tmp.json && mv tmp.json Package.version
128145
echo "current=$CURRENT" >> "$GITHUB_OUTPUT"
129146
echo "new_version=$NEW_VERSION" >> "$GITHUB_OUTPUT"
@@ -143,7 +160,12 @@ jobs:
143160
exit 1
144161
fi
145162
IFS='.' read -r major minor patch <<< "$CURRENT"
146-
NEW_VERSION="${major}.${minor}.$((patch + 1))"
163+
BUMP_TYPE="${{ steps.verify-authors.outputs.bump_type || 'patch' }}"
164+
if [ "$BUMP_TYPE" = "minor" ]; then
165+
NEW_VERSION="${major}.$((minor + 1)).0"
166+
else
167+
NEW_VERSION="${major}.${minor}.$((patch + 1))"
168+
fi
147169
sed -i "s/$CURRENT/$NEW_VERSION/" "$GRADLE_FILE"
148170
echo "current=$CURRENT" >> "$GITHUB_OUTPUT"
149171
echo "new_version=$NEW_VERSION" >> "$GITHUB_OUTPUT"
@@ -201,8 +223,8 @@ jobs:
201223
app-id: ${{ secrets.APP_ID }}
202224
private-key: ${{ secrets.APP_PRIVATE_KEY }}
203225
204-
- name: Create Pull Request
205-
if: steps.bump.outputs.new_version != ''
226+
- name: Create Pull Request (security patch)
227+
if: steps.bump.outputs.new_version != '' && steps.verify-authors.outputs.bump_type == 'patch'
206228
uses: peter-evans/create-pull-request@v6
207229
with:
208230
token: ${{ steps.app-token.outputs.token }}
@@ -234,3 +256,36 @@ jobs:
234256
security
235257
release
236258
delete-branch: true
259+
260+
- name: Create Pull Request (forced minor)
261+
if: steps.bump.outputs.new_version != '' && steps.verify-authors.outputs.bump_type == 'minor'
262+
uses: peter-evans/create-pull-request@v6
263+
with:
264+
token: ${{ steps.app-token.outputs.token }}
265+
branch: auto-release/${{ inputs.tag-prefix }}${{ steps.bump.outputs.new_version }}
266+
base: main
267+
commit-message: "chore: bump ${{ steps.detect.outputs.ecosystem }} version to ${{ steps.bump.outputs.new_version }}"
268+
title: "chore: release ${{ inputs.tag-prefix }}${{ steps.bump.outputs.new_version }} - TODO"
269+
body: |
270+
## Release ${{ inputs.tag-prefix }}${{ steps.bump.outputs.new_version }}
271+
272+
This PR was auto-generated by the **Auto Security Release** workflow (forced).
273+
274+
### What changed
275+
- Ecosystem: `${{ steps.detect.outputs.ecosystem }}`
276+
- Working directory: `${{ inputs.working-directory }}`
277+
- Version bumped from `${{ steps.bump.outputs.current }}` → `${{ steps.bump.outputs.new_version }}`
278+
- `CHANGELOG.md` updated with dependency update entries
279+
- ⚠️ Contains non-dependabot commits — please update the title and describe the changes below
280+
281+
### Summary
282+
TODO — describe what's included in this release
283+
284+
### Before merging
285+
- [ ] Update the PR title with a meaningful description
286+
- [ ] Verify CI passes
287+
- [ ] Confirm no unintended changes are included
288+
labels: |
289+
automated
290+
release
291+
delete-branch: true

0 commit comments

Comments
 (0)