diff --git a/.github/workflows/backmerge-to-develop.yml b/.github/workflows/backmerge-to-develop.yml deleted file mode 100644 index 7983f7f..0000000 --- a/.github/workflows/backmerge-to-develop.yml +++ /dev/null @@ -1,203 +0,0 @@ -name: Backmerge to Develop - -on: - pull_request: - types: [closed] - branches: - - main - -jobs: - backmerge: - # Only run if PR was merged (not just closed) and came from release/* or hotfix/* branch - if: | - github.event.pull_request.merged == true && - (startsWith(github.event.pull_request.head.ref, 'release/') || - startsWith(github.event.pull_request.head.ref, 'hotfix/')) - - runs-on: ubuntu-latest - - permissions: - contents: write - pull-requests: write - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - with: - fetch-depth: 0 # Fetch all history for all branches - token: ${{ secrets.GITHUB_TOKEN }} - - - name: Configure Git - run: | - git config user.name "github-actions[bot]" - git config user.email "github-actions[bot]@users.noreply.github.com" - - - name: Extract version from branch name - id: version - run: | - BRANCH_NAME="${{ github.event.pull_request.head.ref }}" - echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT - - if [[ $BRANCH_NAME == release/v* ]]; then - VERSION=$(echo $BRANCH_NAME | sed 's/release\/v//') - TYPE="release" - elif [[ $BRANCH_NAME == hotfix/v* ]]; then - VERSION=$(echo $BRANCH_NAME | sed 's/hotfix\/v//') - TYPE="hotfix" - fi - - echo "version=$VERSION" >> $GITHUB_OUTPUT - echo "type=$TYPE" >> $GITHUB_OUTPUT - - - name: Check if develop branch exists - id: check_develop - run: | - if git ls-remote --heads origin develop | grep -q develop; then - echo "exists=true" >> $GITHUB_OUTPUT - else - echo "exists=false" >> $GITHUB_OUTPUT - echo "โš ๏ธ Develop branch does not exist. Skipping backmerge." - fi - - - name: Create backmerge pull request - if: steps.check_develop.outputs.exists == 'true' - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - # Create a unique branch name for the backmerge - BACKMERGE_BRANCH="backmerge/main-to-develop-$(date +%Y%m%d-%H%M%S)" - - # Fetch and checkout develop - git fetch origin develop:develop - - # Create new branch from develop - git checkout -b $BACKMERGE_BRANCH develop - - # Merge main into the backmerge branch - echo "Attempting to merge main into $BACKMERGE_BRANCH..." - - # Try to merge main - if git merge origin/main --no-edit; then - echo "โœ… Merge successful, no conflicts" - - # Push the backmerge branch - git push origin $BACKMERGE_BRANCH - - # Create PR using GitHub CLI - PR_TITLE="chore: backmerge v${{ steps.version.outputs.version }} to develop" - - cat > pr_body.md << EOF - ## Automated Backmerge - - This PR automatically backmerges changes from \`main\` to \`develop\` branch. - - ### Source - - **Original PR:** #${{ github.event.pull_request.number }} - - **Title:** ${{ github.event.pull_request.title }} - - **Merged by:** @${{ github.event.pull_request.merged_by.login }} - - **Merged at:** ${{ github.event.pull_request.merged_at }} - - ### Branch Information - - **Source branch:** \`${{ github.event.pull_request.head.ref }}\` - - **Type:** ${{ github.event.pull_request.head.ref }} - - ### Actions Required - - ๐Ÿ‘€ **Review Required** - This PR needs approval before merging - - โœ… Ensure all CI/CD checks pass - - โœ… Review changes for any conflicts or issues - - โœ… Merge after approval - - --- - *This PR was automatically created by GitHub Actions workflow.* - EOF - - # Create PR with review requirements - # Uncomment --draft if you want PRs to be created as draft - # Add --reviewer "username1,username2" to auto-assign reviewers - gh pr create \ - --base develop \ - --head $BACKMERGE_BRANCH \ - --title "$PR_TITLE" \ - --body-file pr_body.md \ - --label "chore,auto-generated" \ - --no-maintainer-edit - - echo "โœ… Pull request created successfully" - - else - echo "โŒ Merge conflicts detected" - - # Reset merge - git merge --abort - - # Push the branch anyway for manual resolution - git push origin $BACKMERGE_BRANCH - - # Create PR with conflict warning - PR_TITLE="chore: backmerge v${{ steps.version.outputs.version }} to develop (conflicts)" - - cat > pr_conflict_body.md << EOF - ## โš ๏ธ Automated Backmerge with Conflicts - - This PR attempts to backmerge changes from \`main\` to \`develop\` branch, but **conflicts were detected**. - - ### Source - - **Original PR:** #${{ github.event.pull_request.number }} - - **Title:** ${{ github.event.pull_request.title }} - - **Merged by:** @${{ github.event.pull_request.merged_by.login }} - - **Merged at:** ${{ github.event.pull_request.merged_at }} - - ### Branch Information - - **Source branch:** \`${{ github.event.pull_request.head.ref }}\` - - **Type:** ${{ github.event.pull_request.head.ref }} - - ### โš ๏ธ Manual Actions Required - 1. Checkout the branch locally - 2. Merge \`main\` and resolve conflicts manually - 3. Push the resolved changes - 4. Request review and merge this PR - - \`\`\`bash - git fetch origin - git checkout -b \${BACKMERGE_BRANCH} origin/\${BACKMERGE_BRANCH} - git merge origin/main - # Resolve conflicts in your editor - git add . - git commit - git push origin \${BACKMERGE_BRANCH} - \`\`\` - - --- - *This PR was automatically created by GitHub Actions workflow. Manual conflict resolution is required.* - EOF - - gh pr create \ - --base develop \ - --head $BACKMERGE_BRANCH \ - --title "$PR_TITLE" \ - --body-file pr_conflict_body.md \ - --label "chore,auto-generated,has-conflicts" \ - --no-maintainer-edit - - echo "โš ๏ธ Pull request created with conflict warning" - - # Exit with error to mark the job as failed - exit 1 - fi - - - name: Summary - if: always() - run: | - echo "## Backmerge Summary" >> $GITHUB_STEP_SUMMARY - echo "" >> $GITHUB_STEP_SUMMARY - echo "- **Source PR:** #${{ github.event.pull_request.number }}" >> $GITHUB_STEP_SUMMARY - echo "- **Source Branch:** \`${{ github.event.pull_request.head.ref }}\`" >> $GITHUB_STEP_SUMMARY - echo "- **Target Branch:** \`develop\`" >> $GITHUB_STEP_SUMMARY - echo "- **Triggered by:** @${{ github.event.pull_request.merged_by.login }}" >> $GITHUB_STEP_SUMMARY - echo "" >> $GITHUB_STEP_SUMMARY - - if [ "${{ steps.check_develop.outputs.exists }}" == "false" ]; then - echo "โš ๏ธ **Status:** Skipped - develop branch does not exist" >> $GITHUB_STEP_SUMMARY - else - echo "โœ… **Status:** Backmerge PR created" >> $GITHUB_STEP_SUMMARY - fi diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index a25bb3b..413d350 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -4,6 +4,12 @@ on: push: tags: - "v*.*.*" # Triggers on version tags like v1.0.0, v2.1.3, etc. + workflow_dispatch: + inputs: + tag: + description: 'Tag to deploy (e.g., v1.0.0)' + required: true + type: string jobs: build-and-deploy: @@ -14,6 +20,7 @@ jobs: uses: actions/checkout@v4 with: fetch-depth: 0 + ref: ${{ github.event.inputs.tag || github.ref }} - name: Install pnpm uses: pnpm/action-setup@v2 @@ -28,8 +35,14 @@ jobs: - name: Get version from tag run: | - echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV - echo "Deploying documentation version: ${GITHUB_REF#refs/tags/}" + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then + VERSION="${{ github.event.inputs.tag }}" + else + VERSION="${{ github.ref }}" + VERSION="${VERSION#refs/tags/}" + fi + echo "VERSION=$VERSION" >> $GITHUB_ENV + echo "Deploying documentation version: $VERSION" - name: Install dependencies run: pnpm install @@ -67,7 +80,7 @@ jobs: # Create deployment info cat > deploy-package/DEPLOY_INFO.txt << EOF PICO SulTeng COVID-19 API Documentation - Version: ${{ env.VERSION }} + Version: $VERSION Deployed: $(date -u '+%Y-%m-%d %H:%M:%S UTC') Built with: Vue.js + Vite Target: Hostinger Shared Hosting @@ -80,65 +93,80 @@ jobs: - name: Setup SSH Agent uses: webfactory/ssh-agent@v0.8.0 + env: + DEPLOY_SSH_KEY: ${{ secrets.DEPLOY_SSH_KEY }} with: - ssh-private-key: ${{ secrets.DEPLOY_SSH_KEY }} + ssh-private-key: ${{ env.DEPLOY_SSH_KEY }} log-public-key: false - name: Add server to known hosts + env: + DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }} + DEPLOY_PORT: ${{ secrets.DEPLOY_PORT }} run: | mkdir -p ~/.ssh - echo "Adding ${{ secrets.DEPLOY_HOST }}:${{ secrets.DEPLOY_PORT }} to known hosts..." - ssh-keyscan -H -p ${{ secrets.DEPLOY_PORT }} ${{ secrets.DEPLOY_HOST }} >> ~/.ssh/known_hosts + echo "Adding $DEPLOY_HOST:$DEPLOY_PORT to known hosts..." + ssh-keyscan -H -p $DEPLOY_PORT $DEPLOY_HOST >> ~/.ssh/known_hosts - name: Test SSH connection + env: + DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }} + DEPLOY_PORT: ${{ secrets.DEPLOY_PORT }} + DEPLOY_USER: ${{ secrets.DEPLOY_USER }} run: | - echo "Testing SSH connection to ${{ secrets.DEPLOY_HOST }}:${{ secrets.DEPLOY_PORT }}..." - ssh -p ${{ secrets.DEPLOY_PORT }} -o ConnectTimeout=10 -o BatchMode=yes ${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }} 'echo "SSH connection successful"' + echo "Testing SSH connection to $DEPLOY_HOST:$DEPLOY_PORT..." + ssh -p $DEPLOY_PORT -o ConnectTimeout=10 -o BatchMode=yes $DEPLOY_USER@$DEPLOY_HOST 'echo "SSH connection successful"' - name: Deploy to production server + env: + VERSION: ${{ env.VERSION }} + DEPLOY_PATH: ${{ secrets.DOCS_DEPLOY_PATH }} + DEPLOY_PORT: ${{ secrets.DEPLOY_PORT }} + DEPLOY_USER: ${{ secrets.DEPLOY_USER }} + DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }} run: | - echo "๐Ÿš€ Starting deployment of documentation ${{ env.VERSION }} to production..." + echo "๐Ÿš€ Starting deployment of documentation $VERSION to production..." # Create temporary deployment archive - tar -czf docs-${{ env.VERSION }}.tar.gz -C deploy-package . + tar -czf docs-$VERSION.tar.gz -C deploy-package . # Upload deployment package echo "๐Ÿ“ค Uploading deployment package..." - scp -P ${{ secrets.DEPLOY_PORT }} docs-${{ env.VERSION }}.tar.gz ${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }}:/tmp/ + scp -P $DEPLOY_PORT docs-$VERSION.tar.gz $DEPLOY_USER@$DEPLOY_HOST:/tmp/ # Execute deployment script on remote server - ssh -p ${{ secrets.DEPLOY_PORT }} ${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }} << 'EOF' + ssh -p $DEPLOY_PORT $DEPLOY_USER@$DEPLOY_HOST << EOF set -e - - DEPLOY_PATH="${{ secrets.DOCS_DEPLOY_PATH }}" - VERSION="${{ env.VERSION }}" - TEMP_ARCHIVE="/tmp/docs-${VERSION}.tar.gz" + + DEPLOY_PATH="$DEPLOY_PATH" + VERSION="$VERSION" + TEMP_ARCHIVE="/tmp/docs-\${VERSION}.tar.gz" BACKUP_DIR="" echo "๐Ÿ” Checking deployment environment..." - echo "Deploy path: $DEPLOY_PATH" - + echo "Deploy path: \$DEPLOY_PATH" + # Create deployment directory if it doesn't exist - mkdir -p "$DEPLOY_PATH" - cd "$DEPLOY_PATH" + mkdir -p "\$DEPLOY_PATH" + cd "\$DEPLOY_PATH" echo "๐Ÿ“ Current directory contents:" ls -la echo "๐Ÿ’พ Creating backup of current deployment..." if [ -f "index.html" ]; then - BACKUP_DIR="../docs-backup-$(date +%Y%m%d_%H%M%S)" - mkdir -p "$BACKUP_DIR" - cp -r * "$BACKUP_DIR/" 2>/dev/null || echo "โš ๏ธ Some files couldn't be backed up" - echo "โœ… Backup created at: $BACKUP_DIR" - echo "BACKUP_DIR=$BACKUP_DIR" > /tmp/backup_path.txt + BACKUP_DIR="../docs-backup-\$(date +%Y%m%d_%H%M%S)" + mkdir -p "\$BACKUP_DIR" + cp -r * "\$BACKUP_DIR/" 2>/dev/null || echo "โš ๏ธ Some files couldn't be backed up" + echo "โœ… Backup created at: \$BACKUP_DIR" + echo "BACKUP_DIR=\$BACKUP_DIR" > /tmp/backup_path.txt else echo "โ„น๏ธ No existing deployment found, skipping backup" echo "BACKUP_DIR=" > /tmp/backup_path.txt fi echo "๐Ÿ“ฆ Extracting new deployment..." - tar -xzf "$TEMP_ARCHIVE" -C . + tar -xzf "\$TEMP_ARCHIVE" -C . echo "๐Ÿ”ง Setting proper permissions..." find . -type f -name "*.html" -exec chmod 644 {} \; @@ -149,7 +177,7 @@ jobs: find . -type d -exec chmod 755 {} \; echo "๐Ÿงน Cleaning up temporary files..." - rm -f "$TEMP_ARCHIVE" + rm -f "\$TEMP_ARCHIVE" echo "โœ… New deployment files deployed!" echo "๐Ÿ“Š Deployed files:" @@ -157,6 +185,13 @@ jobs: EOF - name: Verify deployment and handle rollback + env: + VERSION: ${{ env.VERSION }} + DEPLOY_PATH: ${{ secrets.DOCS_DEPLOY_PATH }} + DOCS_URL: ${{ secrets.DOCS_URL }} + DEPLOY_PORT: ${{ secrets.DEPLOY_PORT }} + DEPLOY_USER: ${{ secrets.DEPLOY_USER }} + DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }} run: | echo "๐Ÿ” Verifying deployment..." sleep 5 # Give the site time to propagate @@ -164,22 +199,22 @@ jobs: HEALTH_CHECK_PASSED=false # Check if the documentation site is accessible - if [ -n "${{ secrets.DOCS_URL }}" ]; then - echo "Testing documentation site at: ${{ secrets.DOCS_URL }}" - + if [ -n "$DOCS_URL" ]; then + echo "Testing documentation site at: $DOCS_URL" + # Perform multiple health checks CHECKS_PASSED=0 TOTAL_CHECKS=3 - + for i in $(seq 1 $TOTAL_CHECKS); do echo "Health check attempt $i/$TOTAL_CHECKS..." - + # Check if site responds with 200 - if curl -f -s -I "${{ secrets.DOCS_URL }}" | head -n1 | grep -q "200"; then + if curl -f -s -I "$DOCS_URL" | head -n1 | grep -q "200"; then echo "โœ… HTTP status check passed" - + # Check if it's serving the Vue.js app content - if curl -f -s "${{ secrets.DOCS_URL }}" | grep -q "PICO SulTeng\|pico-api-docs"; then + if curl -f -s "$DOCS_URL" | grep -q "PICO SulTeng\|pico-api-docs"; then echo "โœ… Content verification passed" CHECKS_PASSED=$((CHECKS_PASSED + 1)) else @@ -188,12 +223,12 @@ jobs: else echo "โŒ HTTP status check failed" fi - + if [ $i -lt $TOTAL_CHECKS ]; then sleep 3 fi done - + # Determine if health check passed (majority of checks must pass) if [ $CHECKS_PASSED -ge 2 ]; then HEALTH_CHECK_PASSED=true @@ -208,14 +243,14 @@ jobs: fi # Handle success/failure - ssh -p ${{ secrets.DEPLOY_PORT }} ${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }} << EOF + ssh -p $DEPLOY_PORT $DEPLOY_USER@$DEPLOY_HOST << EOF # Read backup path from previous step if [ -f "/tmp/backup_path.txt" ]; then BACKUP_DIR=\$(grep "BACKUP_DIR=" /tmp/backup_path.txt | cut -d'=' -f2) else BACKUP_DIR="" fi - + if [ "$HEALTH_CHECK_PASSED" = "true" ]; then echo "๐ŸŽ‰ Deployment verification successful!" @@ -225,17 +260,17 @@ jobs: rm -rf "\$BACKUP_DIR" echo "โœ… Backup cleaned up successfully" fi - + # Clean up backup path file rm -f /tmp/backup_path.txt - - echo "โœ… Deployment ${{ env.VERSION }} completed successfully!" - + + echo "โœ… Deployment $VERSION completed successfully!" + else echo "โŒ Deployment verification failed! Rolling back..." - + if [ -n "\$BACKUP_DIR" ] && [ -d "\$BACKUP_DIR" ]; then - DEPLOY_PATH="${{ secrets.DOCS_DEPLOY_PATH }}" + DEPLOY_PATH="$DEPLOY_PATH" cd "\$DEPLOY_PATH" echo "๐Ÿ”„ Restoring from backup: \$BACKUP_DIR" @@ -259,8 +294,8 @@ jobs: # Clean up backup path file rm -f /tmp/backup_path.txt - - echo "โŒ Deployment ${{ env.VERSION }} failed and rolled back" + + echo "โŒ Deployment $VERSION failed and rolled back" exit 1 fi EOF @@ -272,12 +307,16 @@ jobs: fi - name: Create deployment summary + env: + VERSION: ${{ env.VERSION }} + DOCS_DEPLOY_PATH: ${{ secrets.DOCS_DEPLOY_PATH }} + DOCS_URL: ${{ secrets.DOCS_URL }} run: | echo "## ๐Ÿ“š Documentation Deployment Summary" >> $GITHUB_STEP_SUMMARY - echo "- **Version**: ${{ env.VERSION }}" >> $GITHUB_STEP_SUMMARY - echo "- **Target**: ${{ secrets.DOCS_DEPLOY_PATH }}" >> $GITHUB_STEP_SUMMARY + echo "- **Version**: $VERSION" >> $GITHUB_STEP_SUMMARY + echo "- **Target**: $DOCS_DEPLOY_PATH" >> $GITHUB_STEP_SUMMARY echo "- **Status**: โœ… Deployed successfully" >> $GITHUB_STEP_SUMMARY - echo "- **Site**: ${{ secrets.DOCS_URL || 'URL not configured' }}" >> $GITHUB_STEP_SUMMARY + echo "- **Site**: ${DOCS_URL:-'URL not configured'}" >> $GITHUB_STEP_SUMMARY echo "" >> $GITHUB_STEP_SUMMARY echo "### ๐Ÿ“‹ What was deployed" >> $GITHUB_STEP_SUMMARY echo "- Vue.js documentation site" >> $GITHUB_STEP_SUMMARY @@ -286,7 +325,7 @@ jobs: echo "- Static assets and images" >> $GITHUB_STEP_SUMMARY echo "" >> $GITHUB_STEP_SUMMARY echo "### โœ… Next Steps" >> $GITHUB_STEP_SUMMARY - echo "1. Verify site functionality at ${{ secrets.DOCS_URL }}" >> $GITHUB_STEP_SUMMARY + echo "1. Verify site functionality at $DOCS_URL" >> $GITHUB_STEP_SUMMARY echo "2. Test Vue Router navigation" >> $GITHUB_STEP_SUMMARY echo "3. Verify API proxy is working (if backend is running)" >> $GITHUB_STEP_SUMMARY @@ -306,11 +345,12 @@ jobs: - name: Get version and release info id: release_info run: | - VERSION=${GITHUB_REF#refs/tags/} + VERSION="${{ github.ref }}" + VERSION="${VERSION#refs/tags/}" echo "version=$VERSION" >> $GITHUB_OUTPUT # Get the previous tag for changelog - PREVIOUS_TAG=$(git tag --sort=-version:refname | grep -A1 "^${VERSION}$" | tail -n1) + PREVIOUS_TAG=$(git tag --sort=-version:refname | grep -A1 "^$VERSION$" | tail -n1) if [ -z "$PREVIOUS_TAG" ] || [ "$PREVIOUS_TAG" = "$VERSION" ]; then PREVIOUS_TAG=$(git tag --sort=-version:refname | head -n2 | tail -n1) fi @@ -318,16 +358,18 @@ jobs: - name: Generate release notes id: release_notes + env: + DOCS_URL: ${{ secrets.DOCS_URL }} run: | VERSION=${{ steps.release_info.outputs.version }} PREVIOUS_TAG=${{ steps.release_info.outputs.previous_tag }} # Create release notes - cat > release_notes.md << 'EOF' + cat > release_notes.md << EOF ## ๐Ÿ“š PICO SulTeng COVID-19 API Documentation ${{ steps.release_info.outputs.version }} **Deployment**: โœ… Successfully deployed to production - **Site**: ${{ secrets.DOCS_URL || 'Documentation site' }} + **Site**: ${DOCS_URL:-'Documentation site'} ### ๐Ÿ†• What's New @@ -338,7 +380,7 @@ jobs: echo "Changes since $PREVIOUS_TAG:" >> release_notes.md echo "" >> release_notes.md - git log --pretty=format:"- %s" "${PREVIOUS_TAG}..${VERSION}" | \ + git log --pretty=format:"- %s" "$PREVIOUS_TAG..$VERSION" | \ grep -v "Merge branch\|Merge pull request" | \ head -20 >> release_notes.md else @@ -346,7 +388,7 @@ jobs: fi # Add deployment details - cat >> release_notes.md << 'EOF' + cat >> release_notes.md << EOF ### ๐Ÿš€ Deployment Details @@ -357,8 +399,8 @@ jobs: ### ๐Ÿ”— Quick Links - - [Documentation Site](${{ secrets.DOCS_URL || '#' }}) - - [API Health Check](${{ secrets.DOCS_URL || 'https://pico-api.banuacoder.com' }}/api/v1/health) + - [Documentation Site](${DOCS_URL:-'#'}) + - [API Health Check](${DOCS_URL:-'https://pico-api.banuacoder.com'}/api/v1/health) - [Repository](https://github.com/banua-coder/pico-api-docs) ### ๐Ÿ“ฑ Features Included @@ -395,14 +437,16 @@ jobs: steps: - name: Notify deployment status + env: + DOCS_URL: ${{ secrets.DOCS_URL }} run: | DEPLOY_STATUS="${{ needs.build-and-deploy.result }}" RELEASE_STATUS="${{ needs.create-release.result }}" if [ "$DEPLOY_STATUS" == "success" ]; then echo "โœ… Documentation deployment successful for ${{ github.ref_name }}" - echo "๐ŸŒ Site should be available at: ${{ secrets.DOCS_URL }}" - + echo "๐ŸŒ Site should be available at: $DOCS_URL" + if [ "$RELEASE_STATUS" == "success" ]; then echo "โœ… GitHub release created successfully" else diff --git a/.github/workflows/release-automation.yml b/.github/workflows/release-automation.yml index bbba816..8dbea75 100644 --- a/.github/workflows/release-automation.yml +++ b/.github/workflows/release-automation.yml @@ -149,23 +149,57 @@ jobs: echo "โœ… Tag $VERSION created and pushed successfully" - - name: Trigger deployment workflow + - name: Wait for deployment workflow to trigger if: steps.check_tag.outputs.tag_exists == 'false' env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | VERSION="${{ steps.version.outputs.version }}" - - echo "๐Ÿš€ Manually triggering deployment workflow for tag $VERSION..." - - # Trigger the deploy workflow by creating a repository dispatch event - # Since we can't directly trigger tag-based workflows, we'll use workflow_dispatch - # But first, let's try using the GitHub CLI to trigger it - gh workflow run deploy.yml --ref "$VERSION" || echo "โš ๏ธ Could not trigger via workflow dispatch, deployment should trigger automatically" - - echo "โœ… Deployment trigger attempted" - - # STEP 2: CREATE BACK-MERGE TO DEVELOP + + echo "๐Ÿš€ Waiting for deployment workflow to trigger for tag $VERSION..." + + # Wait a moment for the tag push to trigger the deployment workflow + sleep 5 + + # Check if deployment workflow has started + echo "๐Ÿ” Checking for deployment workflow runs..." + + # Get the latest workflow runs for deploy.yml + WORKFLOW_RUNS=$(gh run list --workflow=deploy.yml --limit=5 --json status,headBranch,createdAt,conclusion) + + # Check if a run for our tag exists + if echo "$WORKFLOW_RUNS" | jq -r ".[] | select(.headBranch==\"$VERSION\")"; then + echo "โœ… Deployment workflow triggered successfully for $VERSION" + else + echo "โš ๏ธ Deployment workflow may not have triggered automatically. Please check manually." + echo " You can manually trigger deployment by:" + echo " 1. Go to Actions tab" + echo " 2. Select 'Deploy Documentation to Production' workflow" + echo " 3. Re-run the workflow for tag $VERSION" + fi + + # STEP 2: SYNC DEVELOP WITH MAIN AND CREATE BACK-MERGE + - name: Sync develop with main before back-merge + id: sync_develop + run: | + echo "๐Ÿ”„ Syncing develop with main to prevent conflicts..." + + # Fetch latest develop and main + git fetch origin develop:develop + git fetch origin main:main + + # Check if develop is behind main + BEHIND_COUNT=$(git rev-list --count develop..main) + echo "behind_count=$BEHIND_COUNT" >> $GITHUB_OUTPUT + + if [ "$BEHIND_COUNT" -gt 0 ]; then + echo "โš ๏ธ Develop is $BEHIND_COUNT commits behind main" + echo "needs_sync=true" >> $GITHUB_OUTPUT + else + echo "โœ… Develop is up to date with main" + echo "needs_sync=false" >> $GITHUB_OUTPUT + fi + - name: Generate unique back-merge branch name id: branch_name run: | @@ -203,12 +237,46 @@ jobs: BACKMERGE_BRANCH="${{ steps.check_branch.outputs.final_branch }}" echo "backmerge_branch=$BACKMERGE_BRANCH" >> $GITHUB_OUTPUT - # Fetch latest develop + # Fetch latest develop and main git fetch origin develop:develop - - # Create and checkout new branch from develop - echo "๐ŸŒฟ Creating branch $BACKMERGE_BRANCH from develop" - git checkout -b "$BACKMERGE_BRANCH" develop + git fetch origin main:main + + # Create and checkout new branch from main (not develop) to avoid conflicts + echo "๐ŸŒฟ Creating branch $BACKMERGE_BRANCH from main" + git checkout -b "$BACKMERGE_BRANCH" main + + # Now merge develop into this branch to see what needs to be preserved + echo "๐Ÿ”„ Checking for develop-specific changes..." + + # Try to merge develop to see if there are any develop-specific changes + if git merge develop --no-commit --no-ff 2>/dev/null; then + # Check if there are actual changes from develop + if git diff --cached --quiet; then + echo "โœ… No develop-specific changes to preserve" + git merge --abort + # Stay on main-based branch + else + echo "๐Ÿ“ Found develop-specific changes to preserve" + # Get the list of changed files + CHANGED_FILES=$(git diff --cached --name-only) + echo "Changed files from develop: $CHANGED_FILES" + + # Abort the merge + git merge --abort + + # Now create the branch from develop instead + git checkout -b "${BACKMERGE_BRANCH}_temp" develop + git branch -D "$BACKMERGE_BRANCH" + git branch -m "${BACKMERGE_BRANCH}_temp" "$BACKMERGE_BRANCH" + fi + else + echo "โš ๏ธ Conflicts detected between main and develop" + git merge --abort + # Create from develop in this case + git checkout -b "${BACKMERGE_BRANCH}_temp" develop + git branch -D "$BACKMERGE_BRANCH" 2>/dev/null || true + git branch -m "${BACKMERGE_BRANCH}_temp" "$BACKMERGE_BRANCH" + fi # Verify we're on the correct branch CURRENT_BRANCH=$(git branch --show-current) @@ -219,11 +287,20 @@ jobs: exit 1 fi - # Merge main into the back-merge branch with conflict resolution - echo "๐Ÿ”„ Merging main into $BACKMERGE_BRANCH" + # Now perform the actual merge based on the branch base + CURRENT_BASE=$(git merge-base HEAD main) + MAIN_BASE=$(git merge-base main main) + + if [ "$CURRENT_BASE" = "$MAIN_BASE" ]; then + echo "๐Ÿ”„ Branch is based on main, merging develop changes..." + MERGE_TARGET="develop" + else + echo "๐Ÿ”„ Branch is based on develop, merging main changes..." + MERGE_TARGET="main" + fi - # Attempt merge, if conflicts occur, resolve them automatically - if ! git merge --no-ff main -m "chore: back-merge ${{ steps.version.outputs.version }} from main to develop + # Attempt merge with automatic conflict resolution + if ! git merge --no-ff "$MERGE_TARGET" -m "chore: back-merge ${{ steps.version.outputs.version }} from main to develop Automated back-merge of ${{ steps.version.outputs.type }} ${{ steps.version.outputs.version }} from main branch. @@ -234,10 +311,36 @@ jobs: echo "โš ๏ธ Merge conflicts detected, resolving automatically..." - # For version-related conflicts, prefer develop branch (newer) changes + # For version-related conflicts, intelligently resolve based on versions if git status --porcelain | grep -q "package.json"; then - echo "๐Ÿ”„ Resolving version conflict in package.json (keeping develop version)" - git checkout --ours package.json + echo "๐Ÿ”„ Resolving version conflict in package.json..." + + # Get versions from both branches + MAIN_VERSION=$(git show main:package.json | jq -r '.version' 2>/dev/null || echo "0.0.0") + DEVELOP_VERSION=$(git show develop:package.json | jq -r '.version' 2>/dev/null || echo "0.0.0") + CURRENT_VERSION=$(jq -r '.version' package.json 2>/dev/null || echo "0.0.0") + + echo " Main version: $MAIN_VERSION" + echo " Develop version: $DEVELOP_VERSION" + echo " Current (conflicted) version: $CURRENT_VERSION" + + # Use the higher version number + if [ "$(printf '%s\n' "$MAIN_VERSION" "$DEVELOP_VERSION" | sort -V | tail -n1)" = "$DEVELOP_VERSION" ]; then + echo " โœ… Keeping develop version (higher): $DEVELOP_VERSION" + git checkout develop -- package.json + else + echo " โœ… Keeping main version (higher): $MAIN_VERSION" + git checkout main -- package.json + fi + git add package.json + fi + + # Handle CHANGELOG.md conflicts + if git status --porcelain | grep -q "CHANGELOG.md"; then + echo "๐Ÿ”„ Resolving CHANGELOG.md conflicts..." + # For CHANGELOG, we want to keep all entries from both branches + git checkout --ours CHANGELOG.md + git add CHANGELOG.md fi # Check for any remaining conflicts diff --git a/.github/workflows/release-branch-creation.yml b/.github/workflows/release-branch-creation.yml index 7de8a22..9dae636 100644 --- a/.github/workflows/release-branch-creation.yml +++ b/.github/workflows/release-branch-creation.yml @@ -238,12 +238,32 @@ jobs: fetch-depth: 0 token: ${{ secrets.GITHUB_TOKEN }} + - name: Check for existing version bump PRs + id: check_prs + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + # Check if there's already a version bump PR open for develop + EXISTING_PRS=$(gh pr list --base develop --state open --label "version-bump" --json number,title) + + if [ "$(echo "$EXISTING_PRS" | jq '. | length')" -gt 0 ]; then + echo "โš ๏ธ Found existing version bump PR(s):" + echo "$EXISTING_PRS" | jq -r '.[] | "#\(.number): \(.title)"' + echo "skip_bump=true" >> $GITHUB_OUTPUT + echo "Skipping version bump to avoid conflicts" + else + echo "โœ… No existing version bump PRs found" + echo "skip_bump=false" >> $GITHUB_OUTPUT + fi + - name: Configure Git + if: steps.check_prs.outputs.skip_bump == 'false' run: | git config user.name "github-actions[bot]" git config user.email "github-actions[bot]@users.noreply.github.com" - name: Calculate next development version + if: steps.check_prs.outputs.skip_bump == 'false' id: next_version run: | RELEASE_BRANCH="${{ github.event.ref }}" @@ -270,7 +290,30 @@ jobs: echo "Current release: $CURRENT_VERSION" echo "Next development version: $NEXT_VERSION" + - name: Check current develop version + if: steps.check_prs.outputs.skip_bump == 'false' + id: current_dev_version + run: | + CURRENT_DEV_VERSION=$(jq -r '.version' package.json 2>/dev/null || echo "0.0.0") + NEXT_VERSION="${{ steps.next_version.outputs.clean_next_version }}" + + echo "current_dev_version=$CURRENT_DEV_VERSION" >> $GITHUB_OUTPUT + + # Check if develop already has a higher or equal version + if [ "$(printf '%s\n' "$CURRENT_DEV_VERSION" "$NEXT_VERSION" | sort -V | tail -n1)" = "$CURRENT_DEV_VERSION" ]; then + if [ "$CURRENT_DEV_VERSION" = "$NEXT_VERSION" ]; then + echo "โš ๏ธ Develop already has the target version: $CURRENT_DEV_VERSION" + else + echo "โš ๏ธ Develop already has a higher version: $CURRENT_DEV_VERSION > $NEXT_VERSION" + fi + echo "skip_update=true" >> $GITHUB_OUTPUT + else + echo "โœ… Will update from $CURRENT_DEV_VERSION to $NEXT_VERSION" + echo "skip_update=false" >> $GITHUB_OUTPUT + fi + - name: Update develop branch with next version + if: steps.check_prs.outputs.skip_bump == 'false' && steps.current_dev_version.outputs.skip_update == 'false' run: | CLEAN_VERSION="${{ steps.next_version.outputs.clean_next_version }}" echo "๐Ÿ“ Updating develop branch to $CLEAN_VERSION..." @@ -286,6 +329,7 @@ jobs: fi - name: Create version bump PR + if: steps.check_prs.outputs.skip_bump == 'false' && steps.current_dev_version.outputs.skip_update == 'false' env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | @@ -348,17 +392,25 @@ jobs: --label "version-bump" - name: Create develop bump summary + if: always() run: | - RELEASE_VERSION="${{ steps.next_version.outputs.current_version }}" - NEXT_VERSION="${{ steps.next_version.outputs.next_version }}" - echo "## ๐Ÿ”„ Develop Version Bump" >> $GITHUB_STEP_SUMMARY echo "" >> $GITHUB_STEP_SUMMARY echo "**Release Branch**: \`${{ github.event.ref }}\`" >> $GITHUB_STEP_SUMMARY - echo "**Release Version**: $RELEASE_VERSION" >> $GITHUB_STEP_SUMMARY - echo "**Next Dev Version**: $NEXT_VERSION" >> $GITHUB_STEP_SUMMARY - echo "" >> $GITHUB_STEP_SUMMARY - echo "### โœ… Actions Completed" >> $GITHUB_STEP_SUMMARY - echo "- ๐ŸŽฏ Calculated next minor version: $NEXT_VERSION" >> $GITHUB_STEP_SUMMARY - echo "- ๐Ÿ“ Updated develop branch package.json" >> $GITHUB_STEP_SUMMARY - echo "- ๐Ÿ”„ Created PR to merge version bump" >> $GITHUB_STEP_SUMMARY + + if [[ "${{ steps.check_prs.outputs.skip_bump }}" == "true" ]]; then + echo "**Status**: โš ๏ธ Skipped - existing version bump PR found" >> $GITHUB_STEP_SUMMARY + elif [[ "${{ steps.current_dev_version.outputs.skip_update }}" == "true" ]]; then + echo "**Status**: โš ๏ธ Skipped - develop already has target or higher version" >> $GITHUB_STEP_SUMMARY + echo "**Current Version**: ${{ steps.current_dev_version.outputs.current_dev_version }}" >> $GITHUB_STEP_SUMMARY + else + RELEASE_VERSION="${{ steps.next_version.outputs.current_version }}" + NEXT_VERSION="${{ steps.next_version.outputs.next_version }}" + echo "**Release Version**: $RELEASE_VERSION" >> $GITHUB_STEP_SUMMARY + echo "**Next Dev Version**: $NEXT_VERSION" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "### โœ… Actions Completed" >> $GITHUB_STEP_SUMMARY + echo "- ๐ŸŽฏ Calculated next minor version: $NEXT_VERSION" >> $GITHUB_STEP_SUMMARY + echo "- ๐Ÿ“ Updated develop branch package.json" >> $GITHUB_STEP_SUMMARY + echo "- ๐Ÿ”„ Created PR to merge version bump" >> $GITHUB_STEP_SUMMARY + fi