Skip to content

Commit 2327234

Browse files
Add artifact-backup GH action
1 parent 51003ea commit 2327234

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

artifact-backup/action.yml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: 'artifact-backup'
2+
description: 'Backup release artifacts to S3'
3+
inputs:
4+
release_tag:
5+
description: 'Tag of the release'
6+
required: true
7+
artifact_path:
8+
description: 'Path to the generated artifact'
9+
required: true
10+
11+
runs:
12+
using: "composite"
13+
steps:
14+
- name: Extract repository name
15+
id: repo-name
16+
shell: bash
17+
run: |
18+
REPO_NAME="${GITHUB_REPOSITORY#*/}"
19+
echo "name=$REPO_NAME" >> $GITHUB_OUTPUT
20+
echo "Repository: $GITHUB_REPOSITORY"
21+
echo "Repository Owner: $GITHUB_REPOSITORY_OWNER"
22+
echo "Repository Name: $REPO_NAME"
23+
24+
- name: Get temporary AWS credentials
25+
uses: aws-actions/configure-aws-credentials@v4
26+
with:
27+
aws-region: us-east-1
28+
role-to-assume: arn:aws:iam::178185592318:role/GHRole-${{ github.repository_owner }}-${{ steps.repo-name.outputs.name }}
29+
role-duration-seconds: 900
30+
unset-current-credentials: true
31+
32+
- name: Add file to s3 bucket
33+
env:
34+
BUCKET_NAME: frtos-artifact-bckup-us-east-1-alpha
35+
shell: bash
36+
run: |
37+
# Get the artifact file name and extension
38+
FILE=${{ inputs.artifact_path }}
39+
FILENAME=$(basename "$FILE")
40+
EXTENSION="${FILENAME##*.}"
41+
BASENAME="${FILENAME%.*}"
42+
43+
# Rename with timestamp
44+
TIMESTAMP="$(date +%Y%m%d%H%M%S)"
45+
NEW_FILENAME="${BASENAME}.${TIMESTAMP}.${EXTENSION}"
46+
47+
# Upload to S3 without overwriting
48+
if ! aws s3api put-object \
49+
--bucket ${{ env.BUCKET_NAME }} \
50+
--key ${{ github.repository }}/${{ inputs.release_tag }}/${NEW_FILENAME} \
51+
--body ${{ inputs.artifact_path }} \
52+
--if-none-match "*"; then
53+
echo "::error::Failed to upload artifact to S3"
54+
exit 1
55+
fi
56+
57+
echo "Successfully uploaded artifact to S3"
58+
59+
- name: Upload SHA256 of the artifact
60+
env:
61+
BUCKET_NAME: frtos-artifact-bckup-us-east-1-alpha
62+
shell: bash
63+
run: |
64+
# Calculate and upload SHA256 hash with platform compatibility
65+
if [[ "$OSTYPE" == "darwin"* ]]; then
66+
# macOS uses shasum
67+
HASH=$(shasum -a 256 "${{ inputs.artifact_path }}" | awk '{print $1}')
68+
else
69+
# Linux uses sha256sum
70+
HASH=$(sha256sum "${{ inputs.artifact_path }}" | awk '{print $1}')
71+
fi
72+
73+
echo "$HASH" > SHA256.txt
74+
75+
echo "Uploading SHA256.txt to S3..."
76+
if ! aws s3api put-object \
77+
--bucket ${{ env.BUCKET_NAME }} \
78+
--key ${{ github.repository }}/${{ inputs.release_tag }}/SHA256.txt \
79+
--body SHA256.txt \
80+
--if-none-match "*"; then
81+
echo "::error::Failed to upload SHA256 hash to S3"
82+
exit 1
83+
fi
84+
85+
echo "Successfully uploaded SHA256 hash to S3"

0 commit comments

Comments
 (0)