|
| 1 | +name: Create Release on Merge |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [closed] |
| 6 | + branches: |
| 7 | + - main |
| 8 | + |
| 9 | +# Also allow manual trigger for flexibility |
| 10 | +workflow_dispatch: |
| 11 | + inputs: |
| 12 | + bump_type: |
| 13 | + description: 'Version bump type' |
| 14 | + required: true |
| 15 | + default: 'patch' |
| 16 | + type: choice |
| 17 | + options: |
| 18 | + - patch |
| 19 | + - minor |
| 20 | + - major |
| 21 | + |
| 22 | +permissions: |
| 23 | + contents: write |
| 24 | + pull-requests: read |
| 25 | + |
| 26 | +jobs: |
| 27 | + release: |
| 28 | + # Only run if PR was merged (not just closed) |
| 29 | + if: github.event.pull_request.merged == true || github.event_name == 'workflow_dispatch' |
| 30 | + runs-on: ubuntu-latest |
| 31 | + timeout-minutes: 10 |
| 32 | + |
| 33 | + steps: |
| 34 | + - name: Checkout repository |
| 35 | + uses: actions/checkout@v4 |
| 36 | + with: |
| 37 | + fetch-depth: 0 |
| 38 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 39 | + |
| 40 | + - name: Configure Git |
| 41 | + run: | |
| 42 | + git config user.name "github-actions[bot]" |
| 43 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 44 | +
|
| 45 | + - name: Determine version bump type |
| 46 | + id: bump-type |
| 47 | + run: | |
| 48 | + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then |
| 49 | + echo "type=${{ github.event.inputs.bump_type }}" >> $GITHUB_OUTPUT |
| 50 | + else |
| 51 | + # Check PR labels for version bump type |
| 52 | + LABELS='${{ toJson(github.event.pull_request.labels.*.name) }}' |
| 53 | + |
| 54 | + if echo "$LABELS" | grep -q "major"; then |
| 55 | + echo "type=major" >> $GITHUB_OUTPUT |
| 56 | + elif echo "$LABELS" | grep -q "minor"; then |
| 57 | + echo "type=minor" >> $GITHUB_OUTPUT |
| 58 | + else |
| 59 | + echo "type=patch" >> $GITHUB_OUTPUT |
| 60 | + fi |
| 61 | + fi |
| 62 | + |
| 63 | + echo "Bump type: $(cat $GITHUB_OUTPUT | grep type | cut -d= -f2)" |
| 64 | +
|
| 65 | + - name: Get current version and calculate new version |
| 66 | + id: version |
| 67 | + run: | |
| 68 | + # Read current version from version.json |
| 69 | + CURRENT_VERSION=$(jq -r '.version' version.json) |
| 70 | + MAJOR=$(jq -r '.major' version.json) |
| 71 | + MINOR=$(jq -r '.minor' version.json) |
| 72 | + PATCH=$(jq -r '.patch' version.json) |
| 73 | + |
| 74 | + echo "Current version: $CURRENT_VERSION" |
| 75 | + |
| 76 | + BUMP_TYPE="${{ steps.bump-type.outputs.type }}" |
| 77 | + |
| 78 | + case $BUMP_TYPE in |
| 79 | + major) |
| 80 | + MAJOR=$((MAJOR + 1)) |
| 81 | + MINOR=0 |
| 82 | + PATCH=0 |
| 83 | + ;; |
| 84 | + minor) |
| 85 | + MINOR=$((MINOR + 1)) |
| 86 | + PATCH=0 |
| 87 | + ;; |
| 88 | + patch) |
| 89 | + PATCH=$((PATCH + 1)) |
| 90 | + ;; |
| 91 | + esac |
| 92 | + |
| 93 | + NEW_VERSION="$MAJOR.$MINOR.$PATCH" |
| 94 | + |
| 95 | + echo "New version: $NEW_VERSION" |
| 96 | + echo "current=$CURRENT_VERSION" >> $GITHUB_OUTPUT |
| 97 | + echo "new=$NEW_VERSION" >> $GITHUB_OUTPUT |
| 98 | + echo "major=$MAJOR" >> $GITHUB_OUTPUT |
| 99 | + echo "minor=$MINOR" >> $GITHUB_OUTPUT |
| 100 | + echo "patch=$PATCH" >> $GITHUB_OUTPUT |
| 101 | +
|
| 102 | + - name: Update version.json |
| 103 | + run: | |
| 104 | + BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ") |
| 105 | + GIT_COMMIT=$(git rev-parse --short HEAD) |
| 106 | + |
| 107 | + jq --arg version "${{ steps.version.outputs.new }}" \ |
| 108 | + --argjson major ${{ steps.version.outputs.major }} \ |
| 109 | + --argjson minor ${{ steps.version.outputs.minor }} \ |
| 110 | + --argjson patch ${{ steps.version.outputs.patch }} \ |
| 111 | + --arg build_date "$BUILD_DATE" \ |
| 112 | + --arg git_commit "$GIT_COMMIT" \ |
| 113 | + '.version = $version | .major = $major | .minor = $minor | .patch = $patch | .build_date = $build_date | .git_commit = $git_commit' \ |
| 114 | + version.json > version.json.tmp && mv version.json.tmp version.json |
| 115 | + |
| 116 | + echo "Updated version.json:" |
| 117 | + cat version.json |
| 118 | +
|
| 119 | + - name: Commit version update |
| 120 | + run: | |
| 121 | + git add version.json |
| 122 | + git commit -m "chore: bump version to ${{ steps.version.outputs.new }} [skip ci]" |
| 123 | + git push |
| 124 | +
|
| 125 | + - name: Create and push tag |
| 126 | + run: | |
| 127 | + git tag -a "v${{ steps.version.outputs.new }}" -m "Release v${{ steps.version.outputs.new }}" |
| 128 | + git push origin "v${{ steps.version.outputs.new }}" |
| 129 | +
|
| 130 | + - name: Generate release notes |
| 131 | + id: release-notes |
| 132 | + run: | |
| 133 | + # Get the previous tag |
| 134 | + PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "") |
| 135 | + |
| 136 | + if [ -z "$PREV_TAG" ]; then |
| 137 | + # First release - get all commits |
| 138 | + CHANGELOG=$(git log --pretty=format:"- %s (%h)" --max-count=50) |
| 139 | + COMPARE_URL="" |
| 140 | + else |
| 141 | + CHANGELOG=$(git log ${PREV_TAG}..HEAD --pretty=format:"- %s (%h)") |
| 142 | + COMPARE_URL="**Full Changelog**: https://github.com/${{ github.repository }}/compare/${PREV_TAG}...v${{ steps.version.outputs.new }}" |
| 143 | + fi |
| 144 | + |
| 145 | + # Escape special characters for GitHub output |
| 146 | + CHANGELOG="${CHANGELOG//'%'/'%25'}" |
| 147 | + CHANGELOG="${CHANGELOG//$'\n'/'%0A'}" |
| 148 | + CHANGELOG="${CHANGELOG//$'\r'/'%0D'}" |
| 149 | + |
| 150 | + echo "changelog<<EOF" >> $GITHUB_OUTPUT |
| 151 | + echo "$CHANGELOG" >> $GITHUB_OUTPUT |
| 152 | + echo "EOF" >> $GITHUB_OUTPUT |
| 153 | + echo "compare_url=$COMPARE_URL" >> $GITHUB_OUTPUT |
| 154 | +
|
| 155 | + - name: Create GitHub Release |
| 156 | + uses: softprops/action-gh-release@v2 |
| 157 | + with: |
| 158 | + tag_name: v${{ steps.version.outputs.new }} |
| 159 | + name: Release v${{ steps.version.outputs.new }} |
| 160 | + body: | |
| 161 | + ## 🚀 LiteMindUI v${{ steps.version.outputs.new }} |
| 162 | + |
| 163 | + ### 📋 Changes |
| 164 | + |
| 165 | + ${{ steps.release-notes.outputs.changelog }} |
| 166 | + |
| 167 | + ### 🐳 Docker Images |
| 168 | + |
| 169 | + Pull the latest images: |
| 170 | + ```bash |
| 171 | + docker pull debabratamishra1/litemindui-backend:${{ steps.version.outputs.new }} |
| 172 | + docker pull debabratamishra1/litemindui-frontend:${{ steps.version.outputs.new }} |
| 173 | + ``` |
| 174 | + |
| 175 | + Or use the `latest` tag: |
| 176 | + ```bash |
| 177 | + docker pull debabratamishra1/litemindui-backend:latest |
| 178 | + docker pull debabratamishra1/litemindui-frontend:latest |
| 179 | + ``` |
| 180 | + |
| 181 | + ### 📦 Quick Start |
| 182 | + |
| 183 | + ```bash |
| 184 | + # Clone and start |
| 185 | + git clone https://github.com/${{ github.repository }}.git |
| 186 | + cd litemind-ui |
| 187 | + docker-compose up -d |
| 188 | + ``` |
| 189 | + |
| 190 | + ### 🌐 Access Points |
| 191 | + |
| 192 | + - **Frontend (Streamlit)**: http://localhost:8501 |
| 193 | + - **Backend API**: http://localhost:8000 |
| 194 | + - **API Documentation**: http://localhost:8000/docs |
| 195 | + |
| 196 | + --- |
| 197 | + |
| 198 | + ${{ steps.release-notes.outputs.compare_url }} |
| 199 | + draft: false |
| 200 | + prerelease: false |
| 201 | + generate_release_notes: false |
| 202 | + env: |
| 203 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments