Skip to content

Chore/android sdkmanager fixes #1

Chore/android sdkmanager fixes

Chore/android sdkmanager fixes #1

Workflow file for this run

name: Release
on:
pull_request:
types: [closed]
branches:
- main
workflow_dispatch:
inputs:
version_type:
description: 'Version bump type (major, minor, patch)'
required: true
default: 'minor'
type: choice
options:
- major
- minor
- patch
generate_changelog:
description: 'Generate comprehensive changelog'
required: false
default: true
type: boolean
permissions:
contents: write
pull-requests: read
jobs:
release:
name: Create Release
runs-on: ubuntu-latest
# Only run on:
# 1. Manual workflow_dispatch
# 2. Merged PRs with 'release:major' or 'release:minor' labels
if: |
github.event_name == 'workflow_dispatch' ||
(github.event.pull_request.merged == true &&
(contains(github.event.pull_request.labels.*.name, 'release:major') ||
contains(github.event.pull_request.labels.*.name, 'release:minor')))
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for changelog generation
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Read current version
id: current_version
run: |
if [ -f "package.json" ]; then
VERSION=$(node -p "require('./package.json').version")
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Current version: $VERSION"
else
# Default to 0.1.0 if no package.json exists
echo "version=0.1.0" >> $GITHUB_OUTPUT
echo "No package.json found, using default version: 0.1.0"
fi
- name: Determine version bump type
id: bump_type
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
# Manual dispatch - use input
echo "type=${{ github.event.inputs.version_type }}" >> $GITHUB_OUTPUT
echo "Releasing with version bump: ${{ github.event.inputs.version_type }}"
else
# PR merge - detect from labels
PR_LABELS="${{ join(github.event.pull_request.labels.*.name, ',') }}"
if echo "$PR_LABELS" | grep -q "release:major"; then
echo "type=major" >> $GITHUB_OUTPUT
echo "Detected major release from PR labels"
elif echo "$PR_LABELS" | grep -q "release:minor"; then
echo "type=minor" >> $GITHUB_OUTPUT
echo "Detected minor release from PR labels"
else
echo "Error: No valid release label found (release:major or release:minor)"
exit 1
fi
fi
- name: Bump version
id: new_version
run: |
CURRENT="${{ steps.current_version.outputs.version }}"
BUMP_TYPE="${{ steps.bump_type.outputs.type }}"
# Parse semver
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT"
case "$BUMP_TYPE" in
major)
MAJOR=$((MAJOR + 1))
MINOR=0
PATCH=0
;;
minor)
MINOR=$((MINOR + 1))
PATCH=0
;;
patch)
PATCH=$((PATCH + 1))
;;
esac
NEW_VERSION="$MAJOR.$MINOR.$PATCH"
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "tag=v$NEW_VERSION" >> $GITHUB_OUTPUT
echo "New version: $NEW_VERSION"
- name: Update package.json version
if: hashFiles('package.json') != ''
run: |
NEW_VERSION="${{ steps.new_version.outputs.version }}"
node -e "const fs=require('fs'); const pkg=JSON.parse(fs.readFileSync('package.json')); pkg.version='$NEW_VERSION'; fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n');"
echo "Updated package.json to version $NEW_VERSION"
- name: Generate changelog content
id: changelog_content
run: |
TAG="${{ steps.new_version.outputs.tag }}"
PREV_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
BUMP_TYPE="${{ steps.bump_type.outputs.type }}"
# Comprehensive changelog for major/minor releases
# For workflow_dispatch, respect the input; for PR merge, default to true
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
GENERATE_COMPREHENSIVE="${{ github.event.inputs.generate_changelog }}"
else
GENERATE_COMPREHENSIVE="true"
fi
{
echo "changelog<<EOF"
echo "## Release ${{ steps.new_version.outputs.version }}"
echo ""
if [ -n "$PREV_TAG" ]; then
echo "### 📦 Changes since $PREV_TAG"
else
echo "### 📦 Initial Release"
fi
echo ""
# Categorize commits for minor/major releases
if [ "$BUMP_TYPE" = "minor" ] || [ "$BUMP_TYPE" = "major" ] || [ "$GENERATE_COMPREHENSIVE" = "true" ]; then
echo "#### ✨ Features & Enhancements"
git log ${PREV_TAG:+$PREV_TAG..}HEAD --pretty=format:"- %s (%h)" --no-merges --grep="feat\|feature\|add" -i || echo "- No new features"
echo ""
echo ""
echo "#### 🐛 Bug Fixes"
git log ${PREV_TAG:+$PREV_TAG..}HEAD --pretty=format:"- %s (%h)" --no-merges --grep="fix\|bug" -i || echo "- No bug fixes"
echo ""
echo ""
echo "#### 🔒 Security"
git log ${PREV_TAG:+$PREV_TAG..}HEAD --pretty=format:"- %s (%h)" --no-merges --grep="security\|vuln\|cve" -i || echo "- No security updates"
echo ""
echo ""
echo "#### 📚 Documentation"
git log ${PREV_TAG:+$PREV_TAG..}HEAD --pretty=format:"- %s (%h)" --no-merges --grep="doc\|readme" -i || echo "- No documentation changes"
echo ""
echo ""
echo "#### 🔧 Chores & Maintenance"
git log ${PREV_TAG:+$PREV_TAG..}HEAD --pretty=format:"- %s (%h)" --no-merges --grep="chore\|refactor\|style" -i || echo "- No maintenance updates"
echo ""
echo ""
else
# Simple changelog for patch releases
echo "#### Changes:"
git log ${PREV_TAG:+$PREV_TAG..}HEAD --pretty=format:"- %s (%h)" --no-merges || echo "- Initial release"
echo ""
echo ""
fi
# Add contributors
echo "#### 👥 Contributors"
git log ${PREV_TAG:+$PREV_TAG..}HEAD --pretty=format:"- @%an" --no-merges | sort -u
echo ""
echo ""
if [ -n "$PREV_TAG" ]; then
echo "**Full Changelog**: https://github.com/${{ github.repository }}/compare/$PREV_TAG...$TAG"
else
echo "**Full Changelog**: https://github.com/${{ github.repository }}/commits/$TAG"
fi
echo "EOF"
} >> $GITHUB_OUTPUT
- name: Update CHANGELOG.md
run: |
TAG="${{ steps.new_version.outputs.tag }}"
CHANGELOG_ENTRY="${{ steps.changelog_content.outputs.changelog }}"
# Create CHANGELOG.md if it doesn't exist
if [ ! -f "CHANGELOG.md" ]; then
echo "# Changelog" > CHANGELOG.md
echo "" >> CHANGELOG.md
echo "All notable changes to OSA (Open Source Automation) will be documented in this file." >> CHANGELOG.md
echo "" >> CHANGELOG.md
echo "The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)," >> CHANGELOG.md
echo "and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html)." >> CHANGELOG.md
echo "" >> CHANGELOG.md
echo "---" >> CHANGELOG.md
echo "" >> CHANGELOG.md
fi
# Prepend new release to CHANGELOG.md (after header)
{
head -n 9 CHANGELOG.md # Keep header
echo ""
echo "$CHANGELOG_ENTRY"
echo ""
echo "---"
echo ""
tail -n +10 CHANGELOG.md # Rest of the file
} > CHANGELOG.md.tmp
mv CHANGELOG.md.tmp CHANGELOG.md
git add CHANGELOG.md
echo "Updated CHANGELOG.md with release notes"
- name: Commit version bump
run: |
TAG="${{ steps.new_version.outputs.tag }}"
if [ -f "package.json" ]; then
git add package.json
fi
# Add CHANGELOG.md if it was updated
if [ -f "CHANGELOG.md" ]; then
git add CHANGELOG.md
fi
git commit -m "chore: bump version to $TAG" --allow-empty || echo "No changes to commit"
- name: Create and push tag
run: |
TAG="${{ steps.new_version.outputs.tag }}"
git tag -a "$TAG" -m "Release $TAG"
git push origin "$TAG"
git push origin main
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.new_version.outputs.tag }}
name: Release ${{ steps.new_version.outputs.version }}
body: ${{ steps.changelog_content.outputs.changelog }}
draft: false
prerelease: false
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
outputs:
version: ${{ steps.new_version.outputs.version }}
tag: ${{ steps.new_version.outputs.tag }}