diff --git a/.github/workflows/publish-to-aws.yaml b/.github/workflows/publish-to-aws.yaml new file mode 100644 index 0000000..70f9c70 --- /dev/null +++ b/.github/workflows/publish-to-aws.yaml @@ -0,0 +1,120 @@ +name: Deploy Python Package to AWS + +on: + workflow_dispatch: + +env: + PACKAGE_NAME: layerlens-atlas-sdk + +jobs: + deploy: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: "3.9" + + - name: Install build dependencies + run: | + python -m pip install --upgrade pip + pip install build twine setuptools wheel + + - name: Build package + run: | + python -m build + + - name: Get package version + id: get_version + run: | + VERSION=$(./scripts/get_version.sh) + echo "VERSION=$VERSION" >> $GITHUB_OUTPUT + echo "Package version: $VERSION" + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v4 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: us-east-1 + + - name: Create package directory structure + run: | + mkdir -p upload/simple/${{ env.PACKAGE_NAME }} + + - name: Copy package files + run: | + cp dist/* upload/simple/${{ env.PACKAGE_NAME }}/ + + - name: Generate package index HTML + run: | + cat > upload/simple/${{ env.PACKAGE_NAME }}/index.html << EOF + + +
+Custom Python package repository for ${{ env.PACKAGE_NAME }}
+ +pip install ${{ env.PACKAGE_NAME }} --index-url https://${{ secrets.CLOUDFRONT_DOMAIN }}/simple/
+
+
+ EOF
+
+ - name: Upload to S3
+ run: |
+ aws s3 sync upload/ s3://${{ secrets.S3_BUCKET_NAME }}/ --delete
+
+ - name: Invalidate CloudFront cache
+ run: |
+ aws cloudfront create-invalidation \
+ --distribution-id ${{ secrets.CLOUDFRONT_DISTRIBUTION_ID }} \
+ --paths "/*"
+
+ - name: Output installation command
+ run: |
+ echo "Package deployed successfully!"
+ echo "Install with: pip install ${{ env.PACKAGE_NAME }} --index-url https://${{ secrets.CLOUDFRONT_DOMAIN }}/simple/"
diff --git a/scripts/get_version.sh b/scripts/get_version.sh
new file mode 100644
index 0000000..14ce950
--- /dev/null
+++ b/scripts/get_version.sh
@@ -0,0 +1,10 @@
+#!/bin/bash
+# Extract and print the version number from _version.py
+
+ROOT_DIR=$(git rev-parse --show-toplevel)
+
+VERSION_FILE="$ROOT_DIR/src/_version.py"
+
+VERSION=$(grep -E '^VERSION\s*=' "$VERSION_FILE" | grep -o '".*"' | tr -d '"')
+
+echo "$VERSION"
\ No newline at end of file