diff --git a/.github/workflows/rollback.yml b/.github/workflows/rollback.yml index 7dcb8cd727..5386cc1fb1 100644 --- a/.github/workflows/rollback.yml +++ b/.github/workflows/rollback.yml @@ -2,6 +2,16 @@ name: Rollback Production Deployment on: workflow_dispatch: + # TODO: Remove the inputs once the dev testing is done + inputs: + environment: + required: true + type: choice + options: + - development + - staging + - production + default: 'development' permissions: id-token: write # allows the JWT to be requested from GitHub's OIDC provider @@ -15,8 +25,8 @@ env: MODERN_DIR_NAME: "modern" INTEGRATIONS_DIR_NAME: "js-integrations" PLUGINS_DIR_NAME: "plugins" - MAJOR_VERSION_DIR_NAME: "v3" - LEGACY_MAJOR_VERSION_DIR_NAME: "v1.1" + LATEST_VERSION_DIR_NAME: "v3" + LEGACY_SDK_LATEST_VERSION_DIR_NAME: "v1.1" jobs: validate-actor: @@ -47,43 +57,111 @@ jobs: with: ref: ${{ github.sha }} - - name: Get new versions + - name: Get rollback sdk versions run: | - current_version_v1=$(jq -r .version packages/analytics-v1.1/package.json) - current_version=$(jq -r .version packages/analytics-js/package.json) - echo "CURRENT_VERSION_V1_VALUE=$current_version_v1" >> $GITHUB_ENV - echo "CURRENT_VERSION_VALUE=$current_version" >> $GITHUB_ENV + rollback_version=$(jq -r .version packages/analytics-js/package.json) + echo "ROLLBACK_VERSION_VALUE=$rollback_version" >> $GITHUB_ENV + + legacy_sdk_rollback_version=$(jq -r .version packages/analytics-v1.1/package.json) + echo "LEGACY_SDK_ROLLBACK_VERSION_VALUE=$legacy_sdk_rollback_version" >> $GITHUB_ENV + + - name: Configure environment variables + run: | + echo "DATE=$(date)" >> $GITHUB_ENV + + # TODO: Remove the below once the dev testing is done + if [ "${{ inputs.environment }}" == "production" ]; then + AWS_S3_BUCKET_NAME="${{ secrets.AWS_PROD_S3_BUCKET_NAME }}" + AWS_CF_DISTRIBUTION_ID="${{ secrets.AWS_PROD_CF_DISTRIBUTION_ID }}" + elif [ "${{ inputs.environment }}" == "staging" ]; then + AWS_S3_BUCKET_NAME="${{ secrets.AWS_STAGING_S3_BUCKET_NAME_TEMP }}" + AWS_CF_DISTRIBUTION_ID="${{ secrets.AWS_STAGING_CF_DISTRIBUTION_ID_TEMP }}" + elif [ "${{ inputs.environment }}" == "development" ]; then + AWS_S3_BUCKET_NAME="${{ secrets.AWS_DEV_S3_BUCKET_NAME_TEMP }}" + AWS_CF_DISTRIBUTION_ID="${{ secrets.AWS_DEV_CF_DISTRIBUTION_ID_TEMP }}" + fi + + echo "AWS_S3_BUCKET_NAME=$AWS_S3_BUCKET_NAME" >> $GITHUB_ENV + echo "AWS_CF_DISTRIBUTION_ID=$AWS_CF_DISTRIBUTION_ID" >> $GITHUB_ENV - name: Copy the core SDK artifacts from the previous version to the latest version directory run: | - integrations_modern_path_prefix="${{ env.CURRENT_VERSION_VALUE }}/${{ env.MODERN_DIR_NAME }}/${{ env.INTEGRATIONS_DIR_NAME }}" - integrations_legacy_path_prefix="${{ env.CURRENT_VERSION_VALUE }}/${{ env.LEGACY_DIR_NAME }}/${{ env.INTEGRATIONS_DIR_NAME }}" - plugins_modern_path_prefix="${{ env.CURRENT_VERSION_VALUE }}/${{ env.MODERN_DIR_NAME }}/${{ env.PLUGINS_DIR_NAME }}" - s3_path_prefix="s3://${{ secrets.AWS_PROD_S3_BUCKET_NAME }}" + integrations_modern_path_prefix="${{ env.ROLLBACK_VERSION_VALUE }}/${{ env.MODERN_DIR_NAME }}/${{ env.INTEGRATIONS_DIR_NAME }}" + integrations_legacy_path_prefix="${{ env.ROLLBACK_VERSION_VALUE }}/${{ env.LEGACY_DIR_NAME }}/${{ env.INTEGRATIONS_DIR_NAME }}" + + plugins_modern_path_prefix="${{ env.ROLLBACK_VERSION_VALUE }}/${{ env.MODERN_DIR_NAME }}/${{ env.PLUGINS_DIR_NAME }}" + + s3_path_prefix="s3://${{ env.AWS_S3_BUCKET_NAME }}" # Copy from S3 bucket versioned directory to the same S3 bucket in the latest version directory - # Exclude the plugins and js-integrations directories + # excluding the plugins and js-integrations directories + + echo "Copying core SDK legacy artifacts from $s3_path_prefix/${{ env.ROLLBACK_VERSION_VALUE }}/${{ env.LEGACY_DIR_NAME }}/ to $s3_path_prefix/${{ env.LATEST_VERSION_DIR_NAME }}/${{ env.LEGACY_DIR_NAME }}/" - aws s3 cp $s3_path_prefix/${{ env.CURRENT_VERSION_VALUE }}/${{ env.LEGACY_DIR_NAME }}/ $s3_path_prefix/${{ env.MAJOR_VERSION_DIR_NAME }}/${{ env.LEGACY_DIR_NAME }}/ --recursive --exclude "$integrations_legacy_path_prefix/*" --exclude "$integrations_legacy_path_prefix/**" --cache-control ${{ env.CACHE_CONTROL_NO_STORE }}" + aws s3 cp $s3_path_prefix/${{ env.ROLLBACK_VERSION_VALUE }}/${{ env.LEGACY_DIR_NAME }}/ $s3_path_prefix/${{ env.LATEST_VERSION_DIR_NAME }}/${{ env.LEGACY_DIR_NAME }}/ --recursive --exclude "$integrations_legacy_path_prefix/*" --exclude "$integrations_legacy_path_prefix/**" --cache-control ${{ env.CACHE_CONTROL_NO_STORE }} - aws s3 cp $s3_path_prefix/${{ env.CURRENT_VERSION_VALUE }}/${{ env.MODERN_DIR_NAME }}/ $s3_path_prefix/${{ env.MAJOR_VERSION_DIR_NAME }}/${{ env.MODERN_DIR_NAME }}/ --recursive --exclude "$plugins_modern_path_prefix/*" --exclude "$plugins_modern_path_prefix/**" --exclude "$integrations_modern_path_prefix/*" --exclude "$integrations_modern_path_prefix/**" --cache-control ${{ env.CACHE_CONTROL_NO_STORE }}" + echo "Copying core SDK modern artifacts from $s3_path_prefix/${{ env.ROLLBACK_VERSION_VALUE }}/${{ env.MODERN_DIR_NAME }}/ to $s3_path_prefix/${{ env.LATEST_VERSION_DIR_NAME }}/${{ env.MODERN_DIR_NAME }}/" + aws s3 cp $s3_path_prefix/${{ env.ROLLBACK_VERSION_VALUE }}/${{ env.MODERN_DIR_NAME }}/ $s3_path_prefix/${{ env.LATEST_VERSION_DIR_NAME }}/${{ env.MODERN_DIR_NAME }}/ --recursive --exclude "$plugins_modern_path_prefix/*" --exclude "$plugins_modern_path_prefix/**" --exclude "$integrations_modern_path_prefix/*" --exclude "$integrations_modern_path_prefix/**" --cache-control ${{ env.CACHE_CONTROL_NO_STORE }} - name: Invalidate CloudFront cache for the latest version directory run: | - invalidation_id=$(AWS_MAX_ATTEMPTS=10 aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_PROD_CF_DISTRIBUTION_ID }} --paths "/${{ env.MAJOR_VERSION_DIR_NAME }}*" --query "Invalidation.Id" --output text) + invalidation_id=$(AWS_MAX_ATTEMPTS=10 aws cloudfront create-invalidation --distribution-id ${{ env.AWS_CF_DISTRIBUTION_ID }} --paths "/${{ env.LATEST_VERSION_DIR_NAME }}*" --query "Invalidation.Id" --output text) - aws cloudfront wait invalidation-completed --distribution-id ${{ secrets.AWS_PROD_CF_DISTRIBUTION_ID }} --id "$invalidation_id" + aws cloudfront wait invalidation-completed --distribution-id ${{ env.AWS_CF_DISTRIBUTION_ID }} --id "$invalidation_id" # Repeat the above steps for the legacy SDK artifacts - - name: Copy the legacy core SDK artifacts from the previous version to the latest version directory + - name: Copy the legacy SDK artifacts from the previous version to the latest version directory run: | - s3_path_prefix="s3://${{ secrets.AWS_PROD_S3_BUCKET_NAME }}" + s3_path_prefix="s3://${{ env.AWS_S3_BUCKET_NAME }}" # Copy from S3 bucket versioned directory to the same S3 bucket in the latest version directory - aws s3 cp $s3_path_prefix/${{ env.CURRENT_VERSION_V1_VALUE }}/ $s3_path_prefix/${{ env.LEGACY_MAJOR_VERSION_DIR_NAME }}/ --recursive --cache-control ${{ env.CACHE_CONTROL_NO_STORE }} + echo "Copying legacy SDK artifacts from $s3_path_prefix/${{ env.LEGACY_SDK_ROLLBACK_VERSION_VALUE }}/ to $s3_path_prefix/${{ env.LEGACY_SDK_LATEST_VERSION_DIR_NAME }}/" + aws s3 cp $s3_path_prefix/${{ env.LEGACY_SDK_ROLLBACK_VERSION_VALUE }}/ $s3_path_prefix/${{ env.LEGACY_SDK_LATEST_VERSION_DIR_NAME }}/ --recursive --cache-control ${{ env.CACHE_CONTROL_NO_STORE }} - name: Invalidate CloudFront cache for the latest version directory (legacy SDK artifacts) run: | - invalidation_id=$(AWS_MAX_ATTEMPTS=10 aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_PROD_CF_DISTRIBUTION_ID }} --paths "/${{ env.LEGACY_MAJOR_VERSION_DIR_NAME }}*" --query "Invalidation.Id" --output text) - - aws cloudfront wait invalidation-completed --distribution-id ${{ secrets.AWS_PROD_CF_DISTRIBUTION_ID }} --id "$invalidation_id" + invalidation_id=$(AWS_MAX_ATTEMPTS=10 aws cloudfront create-invalidation --distribution-id ${{ env.AWS_CF_DISTRIBUTION_ID }} --paths "/${{ env.LEGACY_SDK_LATEST_VERSION_DIR_NAME }}*" --query "Invalidation.Id" --output text) + + aws cloudfront wait invalidation-completed --distribution-id ${{ env.AWS_CF_DISTRIBUTION_ID }} --id "$invalidation_id" + + - name: Send message to Slack channel + id: slack + continue-on-error: true + uses: slackapi/slack-github-action@v1.27.0 + env: + SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} + PROJECT_NAME: 'JS SDK Browser Package - Rollback - Production' + CDN_URL: ${{ format('https://cdn.rudderlabs.com/{0}/modern/rsa.min.js', env.LATEST_VERSION_DIR_NAME) }} + RELEASES_URL: 'https://github.com/rudderlabs/rudder-sdk-js/releases/tag/@rudderstack/analytics-js@' + LINK_TEXT: ${{ format('v{0}', env.ROLLBACK_VERSION_VALUE) }} + with: + channel-id: ${{ secrets.SLACK_RELEASE_CHANNEL_ID }} + payload: | + { + "text": "*New Release: ${{ env.PROJECT_NAME }} - <${{ env.CDN_URL }}|${{ env.LINK_TEXT }}>*\n${{ env.DATE }}\nCC: ", + "blocks": [ + { + "type": "header", + "text": { + "type": "plain_text", + "text": "New release: ${{ env.PROJECT_NAME }}" + } + }, + { + "type": "divider" + }, + { + "type": "section", + "text": { + "type": "mrkdwn", + "text": "*<${{ env.CDN_URL }}|${{ env.LINK_TEXT }}>*\n${{ env.DATE }}\nCC: " + }, + "accessory": { + "type": "image", + "image_url": "https://cdn.jsdelivr.net/npm/programming-languages-logos/src/javascript/javascript.png", + "alt_text": "JavaScript Icon" + } + } + ${{ format(',{{"type": "context", "elements": [{{"type": "mrkdwn", "text": "For more details, check the full release notes <{0}{1}|here>."}}]}}', env.RELEASES_URL, env.ROLLBACK_VERSION_VALUE) || '' }} + ] + }