|
| 1 | +name: "Document Sync" |
| 2 | +description: "Sync Documents between INT and a target Environment" |
| 3 | +inputs: |
| 4 | + TARGET_ENVIRONMENT: |
| 5 | + required: true |
| 6 | + description: "The Environment to Copy Files into (e.g., DEV, PROD)" |
| 7 | + STACK: |
| 8 | + required: false |
| 9 | + description: "The stack being deployed (ie., 'epsam' or 'epsam-pr-123')" |
| 10 | + default: "epsam" |
| 11 | + INT_CLOUD_FORMATION_DEPLOY_ROLE: |
| 12 | + required: true |
| 13 | + description: "The role to assume for the source (INT) account" |
| 14 | + TARGET_CLOUD_FORMATION_DEPLOY_ROLE: |
| 15 | + required: true |
| 16 | + description: "The role to assume for the target account" |
| 17 | + |
| 18 | +runs: |
| 19 | + using: "composite" |
| 20 | + steps: |
| 21 | + - name: Connect to Source Account (INT) |
| 22 | + uses: aws-actions/configure-aws-credentials@61815dcd50bd041e203e49132bacad1fd04d2708 |
| 23 | + with: |
| 24 | + aws-region: eu-west-2 |
| 25 | + role-to-assume: ${{ inputs.INT_CLOUD_FORMATION_DEPLOY_ROLE }} |
| 26 | + role-session-name: epsam-document-sync-source |
| 27 | + |
| 28 | + - name: Find Source Bucket by Partial Name |
| 29 | + id: find-source-bucket |
| 30 | + shell: bash |
| 31 | + working-directory: .github/scripts |
| 32 | + env: |
| 33 | + STACK: "epsam" |
| 34 | + run: ./find_s3_bucket.sh |
| 35 | + |
| 36 | + - name: Download all Files from Source Bucket |
| 37 | + shell: bash |
| 38 | + run: | |
| 39 | + mkdir -p ./s3-content |
| 40 | + aws s3 sync s3://${{ steps.find-source-bucket.outputs.BUCKET_NAME }} ./s3-content |
| 41 | +
|
| 42 | + - name: Connect to Target Account |
| 43 | + uses: aws-actions/configure-aws-credentials@61815dcd50bd041e203e49132bacad1fd04d2708 |
| 44 | + with: |
| 45 | + aws-region: eu-west-2 |
| 46 | + role-to-assume: ${{ inputs.TARGET_CLOUD_FORMATION_DEPLOY_ROLE }} |
| 47 | + role-session-name: epsam-document-sync-target |
| 48 | + |
| 49 | + - name: Find Destination Bucket by Partial Name |
| 50 | + id: find-destination-bucket |
| 51 | + shell: bash |
| 52 | + working-directory: .github/scripts |
| 53 | + env: |
| 54 | + STACK: ${{ inputs.STACK }} |
| 55 | + run: ./find_s3_bucket.sh |
| 56 | + |
| 57 | + - name: Check Discrepancies |
| 58 | + id: compare |
| 59 | + shell: bash |
| 60 | + run: | |
| 61 | + printf "\n" |
| 62 | + echo "Comparing local files with s3://${{ steps.find-destination-bucket.outputs.BUCKET_NAME }}..." |
| 63 | + DIFFS=$(aws s3 sync ./s3-content s3://${{ steps.find-destination-bucket.outputs.BUCKET_NAME }} --dryrun) |
| 64 | +
|
| 65 | + if [ -z "$DIFFS" ]; then |
| 66 | + echo -e "\033[0;32m✔ NO DISCREPANCIES FOUND.\033[0m" |
| 67 | + else |
| 68 | + echo -e "\033[0;33m⚠ WARNING: DISCREPANCIES FOUND:" |
| 69 | +
|
| 70 | + echo "$DIFFS" |
| 71 | + echo "--------------------------------------------------\033[0m" |
| 72 | +
|
| 73 | + CLEAN_DIFFS="${DIFFS//$'\n'/'%0A'}" |
| 74 | + echo "::warning title=Discrepancy Found in ${{ inputs.TARGET_ENVIRONMENT }}::$CLEAN_DIFFS" |
| 75 | + fi |
| 76 | + printf "\n" |
| 77 | +
|
| 78 | + - name: Upload Files to Target S3 |
| 79 | + shell: bash |
| 80 | + run: | |
| 81 | + echo "Updating s3://${{ steps.find-destination-bucket.outputs.BUCKET_NAME }}..." |
| 82 | + aws s3 sync ./s3-content s3://${{ steps.find-destination-bucket.outputs.BUCKET_NAME }} --delete |
0 commit comments