1- name : AWS S3 Helper
2- description : Upload and download files from AWS S3
3-
4- inputs :
5- s3_bucket :
6- description : S3 Bucket Name
7- required : true
8- local_file :
9- description : Local file paths
10- required : false
11- default : ../artifacts/file_list.txt
12- download_file :
13- description : Download file paths
14- required : false
15- default : ' '
16- mode :
17- description : Mode of operation (upload/download)
18- required : true
19- default : single-upload
20-
21- outputs :
22- presigned_url :
23- description : Pre-signed URL for the uploaded file
24- value : ${{ steps.sync-data.outputs.presigned_url }}
25-
26- runs :
27- using : " composite"
28- steps :
29- - name : Sync Data
30- id : sync-data
31- shell : bash
32- env :
33- UPLOAD_LOCATION : ${{ github.repository_owner }}/${{ github.event.repository.name }}/${{ github.workflow }}/${{ github.head_ref != '' && github.head_ref || github.run_id }}/
34- run : |
35- echo "::group::$(printf '__________ %-100s' 'Process' | tr ' ' _)"
36- case "${{ inputs.mode }}" in
37- multi-upload)
38- echo "Uploading files to S3 bucket..."
39- first_line=true
40- # Start the JSON object
41- echo "{" > ${{ github.workspace }}/presigned_urls.json
42- while IFS= read -r file; do
43- if [ -f "$file" ]; then
44- echo "Uploading $file..."
45- aws s3 cp "$file" s3://${{ inputs.s3_bucket }}/${{ env.UPLOAD_LOCATION }}
46- echo "Uploaded $file to s3://${{ inputs.s3_bucket }}/${{ env.UPLOAD_LOCATION }}"
47- echo "Creating Pre-signed URL for $file..."
48- filename=$(basename "$file")
49- presigned_url=$(aws s3 presign s3://${{ inputs.s3_bucket }}/${{ env.UPLOAD_LOCATION }}$filename --expires-in 3600)
50- if [ "$first_line" = true ]; then
51- first_line=false
52- else
53- echo "," >> ${{ github.workspace }}/presigned_urls.json
54- fi
55- # Append the pre-signed URL to the file
56- echo " \"${file}\": \"${presigned_url}\"" >> ${{ github.workspace }}/presigned_urls.json
57- echo "Pre-signed URL for $file: $presigned_url"
58- else
59- echo "Warning: $file does not exist or is not a regular file."
60- fi
61- done < "${{ inputs.local_file }}"
62- # Close the JSON object
63- echo "}" >> ${{ github.workspace }}/presigned_urls.json
64- ;;
65- single-upload)
66- echo "Uploading single file to S3 bucket..."
67- aws s3 cp "${{ inputs.local_file }}" s3://${{ inputs.s3_bucket }}/${{ env.UPLOAD_LOCATION }}
68- echo "Uploaded ${{ inputs.local_file }} to s3://${{ inputs.s3_bucket }}/${{ env.UPLOAD_LOCATION }}"
69- echo "Creating Pre-signed URL for ${{ inputs.local_file }}..."
70- presigned_url=$(aws s3 presign s3://${{ inputs.s3_bucket }}/${{ env.UPLOAD_LOCATION }}${{ inputs.local_file }} --expires-in 3600)
71- echo "presigned_url=${presigned_url}" >> "$GITHUB_OUTPUT"
72- ;;
73- download)
74- #Download The required file from s3
75- echo "Downloading files from S3 bucket..."
76- aws s3 sync s3://${{ inputs.s3_bucket }}/${{ inputs.download_file }} .
77- ;;
78- *)
79- echo "Invalid mode. Use 'upload' or 'download'."
80- exit 1
81- ;;
82- esac
83-
84- - name : Upload artifacts
85- if : ${{ inputs.mode == 'multi-upload' }}
86- uses : actions/upload-artifact@v4
87- with :
88- name : presigned_urls.json
89- path : ${{ github.workspace }}/presigned_urls.json
1+ name : AWS S3 Helper
2+ description : Upload and download files from AWS S3
3+
4+ inputs :
5+ s3_bucket :
6+ description : S3 Bucket Name
7+ required : true
8+ local_file :
9+ description : Local file paths
10+ required : false
11+ default : ../artifacts/file_list.txt
12+ download_file :
13+ description : Download file paths
14+ required : false
15+ default : ' '
16+ mode :
17+ description : Mode of operation (upload/download)
18+ required : true
19+ default : single-upload
20+
21+ outputs :
22+ presigned_url :
23+ description : Pre-signed URL for the uploaded file
24+ value : ${{ steps.sync-data.outputs.presigned_url }}
25+
26+ runs :
27+ using : " composite"
28+ steps :
29+ - name : Sync Data
30+ id : sync-data
31+ shell : bash
32+ env :
33+ UPLOAD_LOCATION : ${{ github.repository_owner }}/${{ github.event.repository.name }}/${{ github.workflow }}/${{ github.head_ref != '' && github.head_ref || github.run_id }}/
34+ run : |
35+ echo "::group::$(printf '__________ %-100s' 'Process' | tr ' ' _)"
36+ case "${{ inputs.mode }}" in
37+ multi-upload)
38+ echo "Uploading files to S3 bucket..."
39+ first_line=true
40+ # Start the JSON object
41+ echo "{" > ${{ github.workspace }}/presigned_urls.json
42+ while IFS= read -r file; do
43+ if [ -f "$file" ]; then
44+ echo "Uploading $file..."
45+ aws s3 cp "$file" s3://${{ inputs.s3_bucket }}/${{ env.UPLOAD_LOCATION }}
46+ echo "Uploaded $file to s3://${{ inputs.s3_bucket }}/${{ env.UPLOAD_LOCATION }}"
47+ echo "Creating Pre-signed URL for $file..."
48+ filename=$(basename "$file")
49+ presigned_url=$(aws s3 presign s3://${{ inputs.s3_bucket }}/${{ env.UPLOAD_LOCATION }}$filename --expires-in 3600)
50+ if [ "$first_line" = true ]; then
51+ first_line=false
52+ else
53+ echo "," >> ${{ github.workspace }}/presigned_urls.json
54+ fi
55+ # Append the pre-signed URL to the file
56+ echo " \"${file}\": \"${presigned_url}\"" >> ${{ github.workspace }}/presigned_urls.json
57+ echo "Pre-signed URL for $file: $presigned_url"
58+ else
59+ echo "Warning: $file does not exist or is not a regular file."
60+ fi
61+ done < "${{ inputs.local_file }}"
62+ # Close the JSON object
63+ echo "}" >> ${{ github.workspace }}/presigned_urls.json
64+ ;;
65+ single-upload)
66+ echo "Uploading single file to S3 bucket..."
67+ aws s3 cp "${{ inputs.local_file }}" s3://${{ inputs.s3_bucket }}/${{ env.UPLOAD_LOCATION }}
68+ echo "Uploaded ${{ inputs.local_file }} to s3://${{ inputs.s3_bucket }}/${{ env.UPLOAD_LOCATION }}"
69+ echo "Creating Pre-signed URL for ${{ inputs.local_file }}..."
70+ presigned_url=$(aws s3 presign s3://${{ inputs.s3_bucket }}/${{ env.UPLOAD_LOCATION }}${{ inputs.local_file }} --expires-in 3600)
71+ echo "presigned_url=${presigned_url}" >> "$GITHUB_OUTPUT"
72+ ;;
73+ download)
74+ #Download The required file from s3
75+ echo "Downloading files from S3 bucket..."
76+ aws s3 sync s3://${{ inputs.s3_bucket }}/${{ inputs.download_file }} .
77+ ;;
78+ *)
79+ echo "Invalid mode. Use 'upload' or 'download'."
80+ exit 1
81+ ;;
82+ esac
83+
84+ - name : Upload artifacts
85+ if : ${{ inputs.mode == 'multi-upload' }}
86+ uses : actions/upload-artifact@v4
87+ with :
88+ name : presigned_urls.json
89+ path : ${{ github.workspace }}/presigned_urls.json
9090 retention-days : 1
0 commit comments