refactor(ci): enhance mobile release workflow with emojis and extracted scripts

✨ Enhanced mobile-release.yml workflow:
- 📱 Added emojis to all steps for better visual feedback
- 🔧 Version now automatically extracted from pubspec.yaml
  - No manual version input required
  - Reads from apps/mobile/apps/staff/pubspec.yaml for worker
  - Reads from apps/mobile/apps/client/pubspec.yaml for client
- 📝 Removed manual version input field from workflow

🔨 Created reusable shell scripts in .github/scripts/:
1. extract-version.sh - Extract version from pubspec.yaml
2. generate-tag-name.sh - Generate tag names consistently
3. extract-release-notes.sh - Extract CHANGELOG sections
4. create-release-summary.sh - Generate GitHub Step Summary with emojis

Benefits:
✅ Simpler workflow - just select app and environment
✅ Single source of truth for versions (pubspec.yaml)
✅ Reusable scripts can be used in other workflows
✅ Better error messages and validation
✅ Enhanced visual feedback with emojis
✅ Cleaner workflow file (moved logic to scripts)
This commit is contained in:
Achintha Isuru
2026-03-05 11:49:11 -05:00
parent 054852fcde
commit 0e296bf83b
5 changed files with 244 additions and 110 deletions

73
.github/scripts/create-release-summary.sh vendored Executable file
View File

@@ -0,0 +1,73 @@
#!/bin/bash
# Generate release summary for GitHub Actions
# Usage: ./create-release-summary.sh <app> <environment> <version> <tag_name>
set -e
APP=$1
ENV=$2
VERSION=$3
TAG_NAME=$4
if [ -z "$APP" ] || [ -z "$ENV" ] || [ -z "$VERSION" ] || [ -z "$TAG_NAME" ]; then
echo "❌ Error: Missing required parameters"
echo "Usage: ./create-release-summary.sh <app> <environment> <version> <tag_name>"
exit 1
fi
# Determine display names
if [ "$APP" = "worker" ]; then
APP_DISPLAY="Worker Mobile"
APP_EMOJI="👷"
else
APP_DISPLAY="Client Mobile"
APP_EMOJI="💼"
fi
ENV_UPPER=$(echo "$ENV" | tr '[:lower:]' '[:upper:]')
RELEASE_NAME="Krow With Us - ${APP_DISPLAY} - ${ENV_UPPER} - v${VERSION}"
# Environment emoji
case "$ENV" in
dev)
ENV_EMOJI="🔧"
;;
stage)
ENV_EMOJI="🎭"
;;
prod)
ENV_EMOJI="🚀"
;;
*)
ENV_EMOJI="📦"
;;
esac
# Generate summary
cat << EOF >> $GITHUB_STEP_SUMMARY
## 🎉 Release Created Successfully
### ${APP_EMOJI} Application Details
- **App:** ${APP_DISPLAY}
- **Environment:** ${ENV_EMOJI} ${ENV_UPPER}
- **Version:** \`${VERSION}\`
- **Tag:** \`${TAG_NAME}\`
### 📦 Release Information
**Release Name:** ${RELEASE_NAME}
### ✅ Next Steps
1. 🔍 **Verify** the tag and release on GitHub
2. 🏗️ **Trigger** CodeMagic build (if configured)
3. 📱 **Monitor** app store deployment
4. 📚 **Update** project documentation if needed
5. 🎯 **Communicate** release to stakeholders
### 🔗 Quick Links
- [View Tag](../../releases/tag/${TAG_NAME})
- [Release Documentation](../../docs/release/MOBILE_RELEASE_PLAN.md)
- [CHANGELOG](../../apps/mobile/apps/${APP}/CHANGELOG.md)
EOF
echo "✅ Summary generated successfully"

65
.github/scripts/extract-release-notes.sh vendored Executable file
View File

@@ -0,0 +1,65 @@
#!/bin/bash
# Extract release notes from CHANGELOG for a specific version
# Usage: ./extract-release-notes.sh <app> <version> <environment> <tag_name> <output_file>
set -e
APP=$1
VERSION=$2
ENV=$3
TAG_NAME=$4
OUTPUT_FILE=$5
if [ -z "$APP" ] || [ -z "$VERSION" ] || [ -z "$ENV" ] || [ -z "$TAG_NAME" ] || [ -z "$OUTPUT_FILE" ]; then
echo "❌ Error: Missing required parameters"
echo "Usage: ./extract-release-notes.sh <app> <version> <environment> <tag_name> <output_file>"
exit 1
fi
# Determine CHANGELOG path and app name
if [ "$APP" = "worker" ]; then
CHANGELOG_PATH="apps/mobile/apps/staff/CHANGELOG.md"
APP_NAME="Staff Mobile App (Worker)"
else
CHANGELOG_PATH="apps/mobile/apps/client/CHANGELOG.md"
APP_NAME="Client Mobile App"
fi
# Try to extract release notes for this version
if [ -f "$CHANGELOG_PATH" ]; then
echo "📝 Found CHANGELOG at $CHANGELOG_PATH"
# Extract section for this version
# Look for ## [VERSION] and collect until next ## [ or end of file
NOTES=$(awk "/## \[${VERSION}\]/,/^## \[/" "$CHANGELOG_PATH" | sed '1d;$d' | sed '/^$/d')
if [ -z "$NOTES" ]; then
echo "⚠️ Warning: No CHANGELOG entry found for version $VERSION"
NOTES="Release $VERSION for $APP_NAME
⚠️ No CHANGELOG entry found for this version. Please update the CHANGELOG manually.
**Environment:** $ENV
**Tag:** $TAG_NAME"
else
echo "✅ Extracted release notes for version $VERSION"
NOTES="# $APP_NAME - Release $VERSION
$NOTES
---
**Environment:** $ENV
**Tag:** $TAG_NAME"
fi
else
echo "⚠️ Warning: CHANGELOG not found at $CHANGELOG_PATH"
NOTES="Release $VERSION for $APP_NAME
**Environment:** $ENV
**Tag:** $TAG_NAME"
fi
# Save to output file
echo "$NOTES" > "$OUTPUT_FILE"
echo "✅ Release notes saved to $OUTPUT_FILE"

48
.github/scripts/extract-version.sh vendored Executable file
View File

@@ -0,0 +1,48 @@
#!/bin/bash
# Extract version from pubspec.yaml for mobile apps
# Usage: ./extract-version.sh <app>
# app: worker or client
set -e
APP=$1
if [ -z "$APP" ]; then
echo "❌ Error: App parameter required (worker or client)"
exit 1
fi
# Determine pubspec path
if [ "$APP" = "worker" ]; then
PUBSPEC_PATH="apps/mobile/apps/staff/pubspec.yaml"
APP_NAME="Staff Mobile App (Worker)"
else
PUBSPEC_PATH="apps/mobile/apps/client/pubspec.yaml"
APP_NAME="Client Mobile App"
fi
# Check if pubspec exists
if [ ! -f "$PUBSPEC_PATH" ]; then
echo "❌ Error: pubspec.yaml not found at $PUBSPEC_PATH"
exit 1
fi
# Extract version (format: X.Y.Z+buildNumber)
VERSION_LINE=$(grep "^version:" "$PUBSPEC_PATH")
if [ -z "$VERSION_LINE" ]; then
echo "❌ Error: Could not find version in $PUBSPEC_PATH"
exit 1
fi
# Extract just the semantic version (before the +)
VERSION=$(echo "$VERSION_LINE" | sed 's/version: *//' | sed 's/+.*//' | tr -d ' ')
# Validate version format
if ! [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "❌ Error: Invalid version format in pubspec.yaml: $VERSION"
echo "Expected format: X.Y.Z (e.g., 0.1.0)"
exit 1
fi
echo "✅ Extracted version from $PUBSPEC_PATH: $VERSION"
echo "$VERSION"

18
.github/scripts/generate-tag-name.sh vendored Executable file
View File

@@ -0,0 +1,18 @@
#!/bin/bash
# Generate tag name for mobile release
# Usage: ./generate-tag-name.sh <app> <environment> <version>
set -e
APP=$1
ENV=$2
VERSION=$3
if [ -z "$APP" ] || [ -z "$ENV" ] || [ -z "$VERSION" ]; then
echo "❌ Error: Missing required parameters"
echo "Usage: ./generate-tag-name.sh <app> <environment> <version>"
exit 1
fi
TAG_NAME="krow-withus-${APP}-mobile/${ENV}-v${VERSION}"
echo "$TAG_NAME"

View File

@@ -1,34 +1,30 @@
name: Mobile Release
name: 📱 Mobile Release
on:
workflow_dispatch:
inputs:
app:
description: 'Mobile App'
description: '📱 Mobile App'
required: true
type: choice
options:
- worker
- client
environment:
description: 'Environment'
description: '🌍 Environment'
required: true
type: choice
options:
- dev
- stage
- prod
version:
description: 'Version (e.g., 0.1.0)'
required: true
type: string
create_github_release:
description: 'Create GitHub Release'
description: '📦 Create GitHub Release'
required: true
type: boolean
default: true
prerelease:
description: 'Mark as Pre-release'
description: '🔖 Mark as Pre-release'
required: false
type: boolean
default: false
@@ -46,96 +42,47 @@ jobs:
with:
fetch-depth: 0
- name: 🔍 Validate version format
- name: <EFBFBD> Make scripts executable
run: |
VERSION="${{ github.event.inputs.version }}"
if ! [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "❌ Error: Version must be in format X.Y.Z (e.g., 0.1.0)"
exit 1
fi
echo "✅ Version format valid: $VERSION"
chmod +x .github/scripts/*.sh
echo "✅ Scripts are now executable"
- name: 📖 Extract version from pubspec.yaml
id: version
run: |
VERSION=$(.github/scripts/extract-version.sh "${{ github.event.inputs.app }}")
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "📌 Extracted version: ${VERSION}"
- name: 🏷️ Generate tag name
id: tag
run: |
APP="${{ github.event.inputs.app }}"
ENV="${{ github.event.inputs.environment }}"
VERSION="${{ github.event.inputs.version }}"
TAG_NAME="krow-withus-${APP}-mobile/${ENV}-v${VERSION}"
TAG_NAME=$(.github/scripts/generate-tag-name.sh \
"${{ github.event.inputs.app }}" \
"${{ github.event.inputs.environment }}" \
"${{ steps.version.outputs.version }}")
echo "tag_name=${TAG_NAME}" >> $GITHUB_OUTPUT
echo "📌 Tag to create: ${TAG_NAME}"
echo "🎯 Tag to create: ${TAG_NAME}"
- name: 🔍 Check if tag already exists
run: |
TAG_NAME="${{ steps.tag.outputs.tag_name }}"
if git rev-parse "$TAG_NAME" >/dev/null 2>&1; then
echo "❌ Error: Tag $TAG_NAME already exists"
echo "💡 Tip: Update the version in pubspec.yaml before creating a new release"
exit 1
fi
echo "✅ Tag does not exist, proceeding..."
- name: 📝 Verify CHANGELOG exists
run: |
APP="${{ github.event.inputs.app }}"
if [ "$APP" = "worker" ]; then
CHANGELOG_PATH="apps/mobile/apps/staff/CHANGELOG.md"
else
CHANGELOG_PATH="apps/mobile/apps/client/CHANGELOG.md"
fi
if [ ! -f "$CHANGELOG_PATH" ]; then
echo "⚠️ Warning: CHANGELOG not found at $CHANGELOG_PATH"
else
echo "✅ CHANGELOG found at $CHANGELOG_PATH"
echo "changelog_path=${CHANGELOG_PATH}" >> $GITHUB_ENV
fi
- name: 📋 Extract release notes from CHANGELOG
id: release_notes
run: |
APP="${{ github.event.inputs.app }}"
VERSION="${{ github.event.inputs.version }}"
if [ "$APP" = "worker" ]; then
CHANGELOG_PATH="apps/mobile/apps/staff/CHANGELOG.md"
APP_NAME="Staff Mobile App (Worker)"
else
CHANGELOG_PATH="apps/mobile/apps/client/CHANGELOG.md"
APP_NAME="Client Mobile App"
fi
# Try to extract release notes for this version
if [ -f "$CHANGELOG_PATH" ]; then
# Extract section for this version
NOTES=$(awk "/## \[${VERSION}\]/,/^## \[/" "$CHANGELOG_PATH" | sed '1d;$d' | sed '/^$/d')
if [ -z "$NOTES" ]; then
NOTES="Release $VERSION for $APP_NAME
No CHANGELOG entry found for this version. Please update the CHANGELOG manually.
**Environment:** ${{ github.event.inputs.environment }}
**Tag:** ${{ steps.tag.outputs.tag_name }}"
else
NOTES="# $APP_NAME - Release $VERSION
$NOTES
---
**Environment:** ${{ github.event.inputs.environment }}
**Tag:** ${{ steps.tag.outputs.tag_name }}"
fi
else
NOTES="Release $VERSION for $APP_NAME
**Environment:** ${{ github.event.inputs.environment }}
**Tag:** ${{ steps.tag.outputs.tag_name }}"
fi
# Save to file to handle multiline
echo "$NOTES" > /tmp/release_notes.md
.github/scripts/extract-release-notes.sh \
"${{ github.event.inputs.app }}" \
"${{ steps.version.outputs.version }}" \
"${{ github.event.inputs.environment }}" \
"${{ steps.tag.outputs.tag_name }}" \
"/tmp/release_notes.md"
echo "notes_file=/tmp/release_notes.md" >> $GITHUB_OUTPUT
- name: 🏷️ Create Git Tag
@@ -143,12 +90,12 @@ $NOTES
TAG_NAME="${{ steps.tag.outputs.tag_name }}"
APP="${{ github.event.inputs.app }}"
ENV="${{ github.event.inputs.environment }}"
VERSION="${{ github.event.inputs.version }}"
VERSION="${{ steps.version.outputs.version }}"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -a "$TAG_NAME" -m "Release ${APP} mobile app ${VERSION} to ${ENV}"
git tag -a "$TAG_NAME" -m "🚀 Release ${APP} mobile app ${VERSION} to ${ENV}"
git push origin "$TAG_NAME"
echo "✅ Tag created and pushed: $TAG_NAME"
@@ -161,7 +108,7 @@ $NOTES
TAG_NAME="${{ steps.tag.outputs.tag_name }}"
APP="${{ github.event.inputs.app }}"
ENV="${{ github.event.inputs.environment }}"
VERSION="${{ github.event.inputs.version }}"
VERSION="${{ steps.version.outputs.version }}"
# Generate release title
if [ "$APP" = "worker" ]; then
@@ -173,43 +120,26 @@ $NOTES
ENV_UPPER=$(echo "$ENV" | tr '[:lower:]' '[:upper:]')
RELEASE_NAME="Krow With Us - ${APP_DISPLAY} - ${ENV_UPPER} - v${VERSION}"
echo "📦 Creating GitHub Release: $RELEASE_NAME"
# Create release
if [ "${{ github.event.inputs.prerelease }}" = "true" ]; then
gh release create "$TAG_NAME" \
--title "$RELEASE_NAME" \
--notes-file "${{ steps.release_notes.outputs.notes_file }}" \
--prerelease
echo "🔖 Pre-release created successfully"
else
gh release create "$TAG_NAME" \
--title "$RELEASE_NAME" \
--notes-file "${{ steps.release_notes.outputs.notes_file }}"
echo "✅ Release created successfully"
fi
echo "✅ GitHub Release created: $RELEASE_NAME"
- name: 📊 Release Summary
- name: 📊 Generate Release Summary
run: |
echo "## 🚀 Release Created Successfully" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**App:** ${{ github.event.inputs.app }}" >> $GITHUB_STEP_SUMMARY
echo "**Environment:** ${{ github.event.inputs.environment }}" >> $GITHUB_STEP_SUMMARY
echo "**Version:** ${{ github.event.inputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "**Tag:** \`${{ steps.tag.outputs.tag_name }}\`" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ "${{ github.event.inputs.app }}" = "worker" ]; then
APP_DISPLAY="Worker Mobile"
else
APP_DISPLAY="Client Mobile"
fi
ENV_UPPER=$(echo "${{ github.event.inputs.environment }}" | tr '[:lower:]' '[:upper:]')
RELEASE_NAME="Krow With Us - ${APP_DISPLAY} - ${ENV_UPPER} - v${{ github.event.inputs.version }}"
echo "**Release Name:** $RELEASE_NAME" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Next Steps" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "1. Verify the tag and release on GitHub" >> $GITHUB_STEP_SUMMARY
echo "2. Trigger CodeMagic build (if configured)" >> $GITHUB_STEP_SUMMARY
echo "3. Monitor app store deployment" >> $GITHUB_STEP_SUMMARY
echo "4. Update project documentation if needed" >> $GITHUB_STEP_SUMMARY
.github/scripts/create-release-summary.sh \
"${{ github.event.inputs.app }}" \
"${{ github.event.inputs.environment }}" \
"${{ steps.version.outputs.version }}" \
"${{ steps.tag.outputs.tag_name }}"