From 5dfe1db7df87c5bdb6a1c89871b2b1df28593ddf Mon Sep 17 00:00:00 2001 From: Anmol1696 Date: Fri, 7 Mar 2025 19:41:06 +0530 Subject: [PATCH 1/8] create initial gh-action to push to s3 bucket --- .github/workflows/s3-action.yaml | 78 ++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 .github/workflows/s3-action.yaml diff --git a/.github/workflows/s3-action.yaml b/.github/workflows/s3-action.yaml new file mode 100644 index 00000000..c68ca675 --- /dev/null +++ b/.github/workflows/s3-action.yaml @@ -0,0 +1,78 @@ +name: S3 Playground + +on: + push: + branches: + - main + - 'v*.*.*' + - anmol/playground-s3 # debug branch + workflow_dispatch: + +jobs: + upload: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: 20 + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ secrets.S3_PLAYGROUND_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.S3_PLAYGROUND_SECRET_ACCESS_KEY }} + aws-region: 'us-east-1' + + - name: Install AWS CLI v2 + run: | + curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o /tmp/awscliv2.zip + unzip -q /tmp/awscliv2.zip -d /tmp + rm /tmp/awscliv2.zip + sudo /tmp/aws/install + rm -rf /tmp/aws/ + + - name: Install tar + run: sudo apt-get update && sudo apt-get install -y tar + + - name: Determine Archive Name + run: | + # Check if triggered by a tag (e.g., v1.0.0) + if [[ "${{ github.ref }}" == refs/tags/* ]]; then + VERSION_TAG="${{ github.ref_name }}" + TARBALL_NAME="${VERSION_TAG}.tar.gz" + else + COMMIT_HASH=$(git rev-parse --short HEAD) + TARBALL_NAME="${COMMIT_HASH}.tar.gz" + fi + echo "TARBALL_NAME=$TARBALL_NAME" >> $GITHUB_ENV + + - name: Create Tarball + run: | + tar -czf "$TARBALL_NAME" ./ --exclude=".git" + + - name: Upload Tarball to S3 + run: | + aws s3 cp "$TARBALL_NAME" "s3://$AWS_S3_BUCKET/create-hyperweb-app/$TARBALL_NAME" --acl public-read + echo "Tarball uploaded: https://$AWS_S3_BUCKET.s3.amazonaws.com/create-hyperweb-app/$TARBALL_NAME" + env: + AWS_DEFAULT_REGION: 'us-east-1' + AWS_ACCESS_KEY_ID: ${{ secrets.S3_PLAYGROUND_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.S3_PLAYGROUND_SECRET_ACCESS_KEY }} + AWS_S3_BUCKET: 'hyperweb-playground' + + - name: Update latest.tar.gz (Only on Main) + if: github.ref == 'refs/heads/main' + run: | + aws s3 cp "$TARBALL_NAME" "s3://$AWS_S3_BUCKET/create-hyperweb-app/latest.tar.gz" --acl public-read + echo "Latest tarball updated: https://$AWS_S3_BUCKET.s3.amazonaws.com/create-hyperweb-app/latest.tar.gz" + env: + AWS_DEFAULT_REGION: 'us-east-1' + AWS_ACCESS_KEY_ID: ${{ secrets.S3_PLAYGROUND_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.S3_PLAYGROUND_SECRET_ACCESS_KEY }} + AWS_S3_BUCKET: 'hyperweb-playground' + From 72dae2496ae9ef3966839029d255a82913cc5697 Mon Sep 17 00:00:00 2001 From: Anmol1696 Date: Fri, 7 Mar 2025 19:42:15 +0530 Subject: [PATCH 2/8] try to not use the install aws cli --- .github/workflows/s3-action.yaml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/s3-action.yaml b/.github/workflows/s3-action.yaml index c68ca675..93d80ad3 100644 --- a/.github/workflows/s3-action.yaml +++ b/.github/workflows/s3-action.yaml @@ -28,13 +28,13 @@ jobs: aws-secret-access-key: ${{ secrets.S3_PLAYGROUND_SECRET_ACCESS_KEY }} aws-region: 'us-east-1' - - name: Install AWS CLI v2 - run: | - curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o /tmp/awscliv2.zip - unzip -q /tmp/awscliv2.zip -d /tmp - rm /tmp/awscliv2.zip - sudo /tmp/aws/install - rm -rf /tmp/aws/ +# - name: Install AWS CLI v2 +# run: | +# curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o /tmp/awscliv2.zip +# unzip -q /tmp/awscliv2.zip -d /tmp +# rm /tmp/awscliv2.zip +# sudo /tmp/aws/install +# rm -rf /tmp/aws/ - name: Install tar run: sudo apt-get update && sudo apt-get install -y tar From 1bfb49f1002a16d3b1be6f4747522dd8887f2c78 Mon Sep 17 00:00:00 2001 From: Anmol1696 Date: Fri, 7 Mar 2025 19:45:03 +0530 Subject: [PATCH 3/8] update command for creating a tarball --- .github/workflows/s3-action.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/s3-action.yaml b/.github/workflows/s3-action.yaml index 93d80ad3..e3fca1f2 100644 --- a/.github/workflows/s3-action.yaml +++ b/.github/workflows/s3-action.yaml @@ -53,7 +53,7 @@ jobs: - name: Create Tarball run: | - tar -czf "$TARBALL_NAME" ./ --exclude=".git" + tar --exclude=".git" --warning=no-file-changed -czf "$TARBALL_NAME" ./ - name: Upload Tarball to S3 run: | From 423c247f8731718485a5a640fa90eec7f7e1629b Mon Sep 17 00:00:00 2001 From: Anmol1696 Date: Fri, 7 Mar 2025 19:46:52 +0530 Subject: [PATCH 4/8] update tar command again to create the tar.gz file --- .github/workflows/s3-action.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/s3-action.yaml b/.github/workflows/s3-action.yaml index e3fca1f2..cd4a7cd4 100644 --- a/.github/workflows/s3-action.yaml +++ b/.github/workflows/s3-action.yaml @@ -53,7 +53,7 @@ jobs: - name: Create Tarball run: | - tar --exclude=".git" --warning=no-file-changed -czf "$TARBALL_NAME" ./ + tar --exclude="./.git" --exclude="./node_modules" --ignore-failed-read -czf "$TARBALL_NAME" ./ - name: Upload Tarball to S3 run: | From 53d68cc9485abc39b6f25a49f19e1d7758857f81 Mon Sep 17 00:00:00 2001 From: Anmol1696 Date: Fri, 7 Mar 2025 19:50:25 +0530 Subject: [PATCH 5/8] update create tar file using a temp dir --- .github/workflows/s3-action.yaml | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/.github/workflows/s3-action.yaml b/.github/workflows/s3-action.yaml index cd4a7cd4..6a2a8a15 100644 --- a/.github/workflows/s3-action.yaml +++ b/.github/workflows/s3-action.yaml @@ -53,11 +53,22 @@ jobs: - name: Create Tarball run: | - tar --exclude="./.git" --exclude="./node_modules" --ignore-failed-read -czf "$TARBALL_NAME" ./ + # Create a temporary directory + TEMP_DIR=$(mktemp -d) + + # Copy everything except .git and node_modules to the temp directory + rsync -a --exclude=".git" --exclude="node_modules" ./ "$TEMP_DIR/" + + # Navigate to the temp directory and create the tarball + cd "$TEMP_DIR" + tar --ignore-failed-read -czf "$GITHUB_WORKSPACE/$TARBALL_NAME" ./ + + # Clean up the temporary directory + rm -rf "$TEMP_DIR" - name: Upload Tarball to S3 run: | - aws s3 cp "$TARBALL_NAME" "s3://$AWS_S3_BUCKET/create-hyperweb-app/$TARBALL_NAME" --acl public-read + aws s3 cp "$GITHUB_WORKSPACE/$TARBALL_NAME" "s3://$AWS_S3_BUCKET/create-hyperweb-app/$TARBALL_NAME" --acl public-read echo "Tarball uploaded: https://$AWS_S3_BUCKET.s3.amazonaws.com/create-hyperweb-app/$TARBALL_NAME" env: AWS_DEFAULT_REGION: 'us-east-1' @@ -68,7 +79,7 @@ jobs: - name: Update latest.tar.gz (Only on Main) if: github.ref == 'refs/heads/main' run: | - aws s3 cp "$TARBALL_NAME" "s3://$AWS_S3_BUCKET/create-hyperweb-app/latest.tar.gz" --acl public-read + aws s3 cp "$GITHUB_WORKSPACE/$TARBALL_NAME" "s3://$AWS_S3_BUCKET/create-hyperweb-app/latest.tar.gz" --acl public-read echo "Latest tarball updated: https://$AWS_S3_BUCKET.s3.amazonaws.com/create-hyperweb-app/latest.tar.gz" env: AWS_DEFAULT_REGION: 'us-east-1' From f2c78e63f9e37c4d5e5db0bba5b0db507663fcd4 Mon Sep 17 00:00:00 2001 From: Anmol1696 Date: Fri, 7 Mar 2025 19:53:39 +0530 Subject: [PATCH 6/8] remove acl policy from s3 object --- .github/workflows/s3-action.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/s3-action.yaml b/.github/workflows/s3-action.yaml index 6a2a8a15..87a6dfcc 100644 --- a/.github/workflows/s3-action.yaml +++ b/.github/workflows/s3-action.yaml @@ -68,7 +68,7 @@ jobs: - name: Upload Tarball to S3 run: | - aws s3 cp "$GITHUB_WORKSPACE/$TARBALL_NAME" "s3://$AWS_S3_BUCKET/create-hyperweb-app/$TARBALL_NAME" --acl public-read + aws s3 cp "$GITHUB_WORKSPACE/$TARBALL_NAME" "s3://$AWS_S3_BUCKET/create-hyperweb-app/$TARBALL_NAME" echo "Tarball uploaded: https://$AWS_S3_BUCKET.s3.amazonaws.com/create-hyperweb-app/$TARBALL_NAME" env: AWS_DEFAULT_REGION: 'us-east-1' @@ -79,7 +79,7 @@ jobs: - name: Update latest.tar.gz (Only on Main) if: github.ref == 'refs/heads/main' run: | - aws s3 cp "$GITHUB_WORKSPACE/$TARBALL_NAME" "s3://$AWS_S3_BUCKET/create-hyperweb-app/latest.tar.gz" --acl public-read + aws s3 cp "$GITHUB_WORKSPACE/$TARBALL_NAME" "s3://$AWS_S3_BUCKET/create-hyperweb-app/latest.tar.gz" echo "Latest tarball updated: https://$AWS_S3_BUCKET.s3.amazonaws.com/create-hyperweb-app/latest.tar.gz" env: AWS_DEFAULT_REGION: 'us-east-1' From a0c17b0aef989629f79fa5eedaf26d293e83cbc6 Mon Sep 17 00:00:00 2001 From: Anmol1696 Date: Fri, 7 Mar 2025 20:00:35 +0530 Subject: [PATCH 7/8] remove debugging event trigger --- .github/workflows/s3-action.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/s3-action.yaml b/.github/workflows/s3-action.yaml index 87a6dfcc..3f310b70 100644 --- a/.github/workflows/s3-action.yaml +++ b/.github/workflows/s3-action.yaml @@ -5,7 +5,6 @@ on: branches: - main - 'v*.*.*' - - anmol/playground-s3 # debug branch workflow_dispatch: jobs: From b23569e79cda22f39467783dfcc359e8016aaeca Mon Sep 17 00:00:00 2001 From: Anmol1696 Date: Fri, 7 Mar 2025 20:00:57 +0530 Subject: [PATCH 8/8] fix file indent --- .github/workflows/s3-action.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/s3-action.yaml b/.github/workflows/s3-action.yaml index 3f310b70..210ea1a6 100644 --- a/.github/workflows/s3-action.yaml +++ b/.github/workflows/s3-action.yaml @@ -85,4 +85,3 @@ jobs: AWS_ACCESS_KEY_ID: ${{ secrets.S3_PLAYGROUND_ACCESS_KEY_ID }} AWS_SECRET_ACCESS_KEY: ${{ secrets.S3_PLAYGROUND_SECRET_ACCESS_KEY }} AWS_S3_BUCKET: 'hyperweb-playground' -