1+ name : Promote Release to AWS S3 and CloudFront
2+ on :
3+ release :
4+
5+ jobs :
6+ promote :
7+ runs-on : ubuntu-latest
8+ if : github.event.release.prerelease == false
9+ permissions :
10+ contents : read
11+ env :
12+ AWS_ACCESS_KEY_ID : ${{ secrets.AWS_ACCESS_KEY_ID }}
13+ AWS_SECRET_ACCESS_KEY : ${{ secrets.AWS_SECRET_ACCESS_KEY }}
14+ S3_BUCKET : ' interacting-bear-static-website'
15+ S3_BUCKET_REGION : ' us-east-1'
16+ CLOUDFRONT_DISTRIBUTION_ID : ' E2LAO4ZFF55RTR'
17+ steps :
18+
19+ - name : Extract version from tag
20+ id : version
21+ run : echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
22+
23+ - name : Download build artifact from release
24+ run : |
25+ # Get the download URL for the build artifact
26+ echo "Fetching release info for tag: v${{ steps.version.outputs.version }}"
27+
28+ RELEASE_INFO=$(curl -s \
29+ -H "Accept: application/vnd.github+json" \
30+ -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
31+ "https://api.github.com/repos/${{ github.repository }}/releases/tags/v${{ steps.version.outputs.version }}")
32+
33+ echo "Release API response:"
34+ echo "$RELEASE_INFO" | jq '.'
35+
36+ ASSET_ID=$(echo "$RELEASE_INFO" | jq -r '.assets[] | select(.name=="build-artifacts-${{ steps.version.outputs.version }}.zip") | .id')
37+
38+ if [ "$ASSET_ID" = "null" ] || [ -z "$ASSET_ID" ]; then
39+ echo "Error: Could not find build artifact in release assets"
40+ echo "Available assets:"
41+ echo "$RELEASE_INFO" | jq -r '.assets[].name'
42+ exit 1
43+ fi
44+
45+ echo "Asset ID: $ASSET_ID"
46+
47+ # Download the zip file using GitHub API asset endpoint
48+ curl -L \
49+ -H "Accept: application/octet-stream" \
50+ -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
51+ -o build-artifacts-${{ steps.version.outputs.version }}.zip \
52+ "https://api.github.com/repos/${{ github.repository }}/releases/assets/$ASSET_ID"
53+
54+ # Verify the download
55+ if [ ! -f "build-artifacts-${{ steps.version.outputs.version }}.zip" ]; then
56+ echo "Error: Downloaded file not found"
57+ exit 1
58+ fi
59+
60+ echo "Downloaded file size:"
61+ ls -la build-artifacts-${{ steps.version.outputs.version }}.zip
62+
63+ # Extract the zip file
64+ mkdir -p build
65+ unzip build-artifacts-${{ steps.version.outputs.version }}.zip -d build
66+
67+ - name : Deploy to S3 and CloudFront
68+ uses : reggionick/s3-deploy@v4
69+ with :
70+ folder : build
71+ bucket : ${{ env.S3_BUCKET }}
72+ bucket-region : ${{ env.S3_BUCKET_REGION }}
73+ dist-id : ${{ env.CLOUDFRONT_DISTRIBUTION_ID }}
74+ invalidation : /
75+ delete-removed : true
76+ private : true
77+ files-to-include : ' {.*/**,**}'
78+
79+
0 commit comments