From 6d58c9f42e80ca34230fcf9ff33af0ab66e6f1ee Mon Sep 17 00:00:00 2001 From: Muhammad Tahir Nawaz Date: Sat, 4 Apr 2026 18:45:04 +0500 Subject: [PATCH] feat(TMF-2078): added qa report field --- .github/actions/gcs-history/action.yml | 45 ++ .github/actions/gcs-history/gcs-history.sh | 729 +++++++++++++++++++++ .github/workflows/deployment.yaml | 34 +- 3 files changed, 798 insertions(+), 10 deletions(-) create mode 100644 .github/actions/gcs-history/action.yml create mode 100644 .github/actions/gcs-history/gcs-history.sh diff --git a/.github/actions/gcs-history/action.yml b/.github/actions/gcs-history/action.yml new file mode 100644 index 0000000..14cb8e2 --- /dev/null +++ b/.github/actions/gcs-history/action.yml @@ -0,0 +1,45 @@ +name: 'GCS Release History' +description: 'Generate and upload release history HTML dashboard to Google Cloud Storage' + +inputs: + bucket_name: + description: 'GCS bucket name' + required: true + env: + description: 'Environment short name (dev, stage, prod)' + required: true + tag: + description: 'Release tag' + required: true + title: + description: 'Release title' + required: true + env_name: + description: 'Environment full name (development, staging, production)' + required: true + date: + description: 'Release date' + required: true + release_notes: + description: 'Release notes markdown' + required: true + service_name: + description: 'Service name for GCS path and HTML branding' + required: true + +runs: + using: 'composite' + steps: + - name: Run GCS history script + shell: bash + run: | + chmod +x ${{ github.action_path }}/gcs-history.sh + ${{ github.action_path }}/gcs-history.sh \ + "${{ inputs.bucket_name }}" \ + "${{ inputs.env }}" \ + "${{ inputs.tag }}" \ + "${{ inputs.title }}" \ + "${{ inputs.env_name }}" \ + "${{ inputs.date }}" \ + "${{ inputs.release_notes }}" \ + "${{ inputs.service_name }}" diff --git a/.github/actions/gcs-history/gcs-history.sh b/.github/actions/gcs-history/gcs-history.sh new file mode 100644 index 0000000..ddc5ed6 --- /dev/null +++ b/.github/actions/gcs-history/gcs-history.sh @@ -0,0 +1,729 @@ +#!/bin/bash +# GCS release history management script - Creates history.json with all releases + +update_release_history() { + local bucket_name="$1" + local env_prefix="$2" + local version="$3" + local version_tag="$4" + local env_name="$5" + local release_date="$6" + local release_notes="$7" + local service_name="$8" + + local releases_path="gs://${bucket_name}/${service_name}/releases/history.json" + local existing_releases='{"releases":[]}' + + # Download existing releases from GCS if not already present locally + if [[ -f "output-folder/releases/history.json" ]] && jq empty output-folder/releases/history.json 2>/dev/null; then + existing_releases=$(cat output-folder/releases/history.json) + elif gcloud storage cp "$releases_path" ./existing-releases.json 2>/dev/null && jq empty ./existing-releases.json 2>/dev/null; then + existing_releases=$(cat ./existing-releases.json) + rm -f ./existing-releases.json + fi + + # Clean release notes to remove control characters and problematic sequences + local cleaned_release_notes=$(echo "$release_notes" | tr -d '\000-\031\177-\377' | sed 's/\r//g' | sed 's/\x1b\[[0-9;]*m//g') + + # Load PR details if available + local pr_details='[]' + if [[ -f "pr-details.json" ]] && jq empty pr-details.json 2>/dev/null; then + # Extract structured PR info: title, summary, why, dependencies + pr_details=$(jq '[.[] | { + number: .number, + title: .title, + user: .user, + summary: ( + if .body then + ((.body | capture("## Summary[\\s]*(?[\\s\\S]*?)(?=## |$)")) // {"s": ""}) | .s | gsub(""; "") | ltrimstr("\n") | rtrimstr("\n") | gsub("^\\s+|\\s+$"; "") + else "" end + ), + why: ( + if .body then + ((.body | capture("## Why[\\s]*(?[\\s\\S]*?)(?=## |$)")) // {"w": ""}) | .w | gsub(""; "") | ltrimstr("\n") | rtrimstr("\n") | gsub("^\\s+|\\s+$"; "") + else "" end + ), + dependencies: ( + if .body then + ((.body | capture("## Dependencies[\\s]*(?[\\s\\S]*?)(?=## |$)")) // {"d": ""}) | .d | gsub(""; "") | ltrimstr("\n") | rtrimstr("\n") | gsub("^\\s+|\\s+$"; "") + else "" end + ) + }]' pr-details.json 2>/dev/null || echo '[]') + fi + + local new_release=$(jq -n \ + --arg version "$version" \ + --arg versionTag "$version_tag" \ + --arg environment "$env_name" \ + --arg releaseDate "$(date --iso-8601=seconds)" \ + --arg releaseNotes "$cleaned_release_notes" \ + --argjson prDetails "$pr_details" \ + '{ + version: $version, + versionTag: $versionTag, + environment: $environment, + releaseDate: $releaseDate, + releaseNotes: $releaseNotes, + prDetails: $prDetails + }' + ) + + # Update releases (keep latest 30) + local updated_releases=$(echo "$existing_releases" | jq --argjson newRelease "$new_release" ' + .releases = [$newRelease] + (.releases // []) | + .releases = .releases[0:30] + ') + + # Save updated releases to output folder + mkdir -p output-folder/releases + echo "$updated_releases" > output-folder/releases/history.json + + # Generate HTML dashboard + generate_html_dashboard "$updated_releases" "$bucket_name" "$service_name" +} + +generate_html_dashboard() { + local releases_data="$1" + local bucket_name="$2" + local service_name="$3" + + # Create HTML dashboard + cat > latest.html << 'EOF' + + + + + + + + + SERVICE_NAME_PLACEHOLDER - Release Dashboard + + + +
+
+

🚀 SERVICE_NAME_PLACEHOLDER

+

Release Dashboard

+

Deployment and Release History

+
+ +
+
+
+

📚 Release History

+
+
+
+ + +
+ + + + +EOF + + # Replace service name placeholder in the generated HTML + sed -i "s/SERVICE_NAME_PLACEHOLDER/${service_name}/g" latest.html + + # Save the JSON data to a temporary file to avoid shell escaping issues + echo "$releases_data" > temp_releases.json + + # Use Python to safely replace the placeholder with JSON data and save to output folder + python3 -c " +import sys +import json +import os +from datetime import datetime, timezone + +try: + # Read the HTML file + with open('latest.html', 'r') as f: + html_content = f.read() + + # Read and validate the JSON data from file + with open('temp_releases.json', 'r') as f: + json_data = f.read() + + # Clean the JSON data to remove control characters + import re + # Remove control characters except newlines and tabs + json_data = re.sub(r'[\x00-\x08\x0b\x0c\x0e-\x1f\x7f-\x9f]', '', json_data) + + # Parse to validate JSON + parsed_json = json.loads(json_data) + + # Add cache-busting timestamp to the JSON + parsed_json['lastUpdated'] = datetime.now(timezone.utc).isoformat() + parsed_json['cacheVersion'] = str(int(datetime.now(timezone.utc).timestamp())) + + # Replace the placeholder with the actual JSON data + html_content = html_content.replace('const releaseData = RELEASE_DATA_PLACEHOLDER;', 'const releaseData = ' + json.dumps(parsed_json, indent=2) + ';') + + # Create output folder if it doesn't exist + os.makedirs('output-folder/releases', exist_ok=True) + + # Write the updated HTML file directly to output folder + with open('output-folder/releases/latest.html', 'w') as f: + f.write(html_content) + +except Exception as e: + print(f'Error processing data: {e}') + import traceback + traceback.print_exc() + sys.exit(1) +" + + # Clean up temporary files + rm -f latest.html temp_releases.json +} + +# Execute if called directly +if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then + update_release_history "$@" +fi diff --git a/.github/workflows/deployment.yaml b/.github/workflows/deployment.yaml index badeef7..b27b52d 100644 --- a/.github/workflows/deployment.yaml +++ b/.github/workflows/deployment.yaml @@ -202,7 +202,8 @@ jobs: id: deploy_status run: echo "success=true" >> $GITHUB_OUTPUT - - name: Create release and update GCS history + - name: Create release + id: create_release if: steps.deploy_status.outputs.success == 'true' env: GH_TOKEN: ${{ github.token }} @@ -272,15 +273,28 @@ jobs: echo "$PR_DETAILS" > pr-details.json - chmod +x ./.github/scripts/gcs-history.sh - ./.github/scripts/gcs-history.sh \ - "${{ secrets.BUCKET_NAME }}" \ - "$ENV" \ - "$TAG" \ - "$TITLE" \ - "$ENV_NAME" \ - "$DATE" \ - "$RELEASE_NOTES" + # Export variables for the next step + echo "DEPLOY_ENV=$ENV" >> $GITHUB_ENV + echo "DEPLOY_TAG=$TAG" >> $GITHUB_ENV + echo "DEPLOY_TITLE=$TITLE" >> $GITHUB_ENV + echo "DEPLOY_ENV_NAME=$ENV_NAME" >> $GITHUB_ENV + echo "DEPLOY_DATE=$DATE" >> $GITHUB_ENV + echo "DEPLOY_RELEASE_NOTES<> $GITHUB_ENV + echo "$RELEASE_NOTES" >> $GITHUB_ENV + echo "EOFNOTES" >> $GITHUB_ENV + + - name: Update GCS release history + if: steps.deploy_status.outputs.success == 'true' + uses: WanAware/.github/.github/actions/gcs-history@main + with: + bucket_name: ${{ secrets.BUCKET_NAME }} + env: ${{ env.DEPLOY_ENV }} + tag: ${{ env.DEPLOY_TAG }} + title: ${{ env.DEPLOY_TITLE }} + env_name: ${{ env.DEPLOY_ENV_NAME }} + date: ${{ env.DEPLOY_DATE }} + release_notes: ${{ env.DEPLOY_RELEASE_NOTES }} + service_name: ${{ inputs.service_name }} - name: Upload docs to GCS if: ${{ inputs.generate_docs }}