Skip to content

Update s3pathssync.yml #22

Update s3pathssync.yml

Update s3pathssync.yml #22

Workflow file for this run

name: list changed-filesd
on:
pull_request:
types:
- closed
jobs:
workflow:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
name: Test changed-files
steps:
- name: Checkout
uses: actions/checkout@v4
- name: List all files in AutoDuty/Paths folder
id: list-local-files
run: |
find AutoDuty/Paths -type f > local_files.txt
echo "Local files:"
cat local_files.txt
- name: Configure AWS Credentials
uses: aws-actions/[email protected]
with:
aws-access-key-id: ${{ secrets.AWS_KEY }}
aws-secret-access-key: ${{ secrets.AWS_SECRET }}
aws-region: us-west-2
- name: Debug S3 ls output
run: |
echo "Debugging S3 ls output:"
aws s3 ls s3://${{ secrets.AWS_BUCKET_NAME }} --recursive --human-readable --summarize
- name: List all files in S3 bucket
id: list-s3-files
run: |
aws s3 ls s3://${{ secrets.AWS_BUCKET_NAME }} --recursive | awk '{$1=$2=$3=$4=""; print substr($0,5)}' > s3_files.txt
echo "S3 files:"
cat s3_files.txt
- name: Delete files in S3 bucket not in local folder
if: steps.changed-files-specific.outputs.any_changed == 'true'
run: |
comm -23 <(sort s3_files.txt) <(sort local_files.txt) > files_to_delete.txt
echo "Files to delete:"
cat files_to_delete.txt
while read -r file; do
aws s3 rm s3://${{ secrets.AWS_BUCKET_NAME }}/$file
done < files_to_delete.txt
- name: Get changed files in the paths folder
id: changed-files-specific
uses: tj-actions/[email protected]
with:
json: "true"
quotepath: "false"
files: AutoDuty/Paths/**
separator: ","
- name: Run step if any file(s) in the paths folder change
if: steps.changed-files-specific.outputs.any_changed == 'true'
env:
ALL_CHANGED_FILES: ${{ steps.changed-files-specific.outputs.all_changed_files }}
run: |
echo "One or more files in the paths folder has changed."
echo "List all the files that have changed: $ALL_CHANGED_FILES"
- name: Move changed files to temporary folder
if: steps.changed-files-specific.outputs.any_changed == 'true'
run: |
TEMP_DIR=$(mktemp -d)
echo "Temporary directory created at $TEMP_DIR"
for file in $(echo $ALL_CHANGED_FILES | jq -r '.[]'); do
mkdir -p "$TEMP_DIR/$(dirname $file)"
rsync -R "$file" "$TEMP_DIR/$(dirname $file)"
done
echo "Files moved to $TEMP_DIR"
- name: List all files in temporary folder
if: steps.changed-files-specific.outputs.any_changed == 'true'
run: |
echo "Listing all files in $TEMP_DIR:"
find $TEMP_DIR -type f
- name: Sync temp folder to S3 bucket
if: steps.changed-files-specific.outputs.any_changed == 'true'
run: |
aws s3 sync $TEMP_DIR s3://${{ secrets.AWS_BUCKET_NAME }}/ --exclude ".github/*"