diff --git a/.github/workflows/publish-to-aws.yaml b/.github/workflows/publish-to-aws.yaml index 6234b8a..ce28d28 100644 --- a/.github/workflows/publish-to-aws.yaml +++ b/.github/workflows/publish-to-aws.yaml @@ -50,11 +50,48 @@ jobs: - name: Create package directory structure run: | mkdir -p upload/simple/${{ env.PACKAGE_NAME }} + mkdir -p upload/versions/${{ steps.get_version.outputs.VERSION }} - - name: Copy package files + - name: Copy package files to version-specific folder run: | + cp dist/* upload/versions/${{ steps.get_version.outputs.VERSION }}/ + + - name: List existing versions from S3 + id: list_versions + run: | + # Get existing versions from S3 (ignore errors if bucket is empty) + aws s3 ls s3://${{ secrets.S3_BUCKET_NAME }}/versions/ || true > existing_versions.txt + + # Extract version numbers and add current version + VERSIONS=$(awk '{print $2}' existing_versions.txt | sed 's/\///g' | sort -V) + CURRENT_VERSION="${{ steps.get_version.outputs.VERSION }}" + + # Combine existing and current versions, remove duplicates, and sort + ALL_VERSIONS=$(echo -e "$VERSIONS\n$CURRENT_VERSION" | sort -V | uniq) + + echo "Available versions:" + echo "$ALL_VERSIONS" + + # Save for use in HTML generation + echo "$ALL_VERSIONS" > all_versions.txt + + # Format for JSON array (for potential future use) + VERSIONS_JSON=$(echo "$ALL_VERSIONS" | jq -R . | jq -s .) + echo "VERSIONS_JSON=$VERSIONS_JSON" >> $GITHUB_OUTPUT + + - name: Copy package files to simple index (all versions) + run: | + # Copy current version to simple index cp dist/* upload/simple/${{ env.PACKAGE_NAME }}/ + # Download and copy existing versions from S3 + while IFS= read -r version; do + if [ ! -z "$version" ] && [ "$version" != "${{ steps.get_version.outputs.VERSION }}" ]; then + echo "Downloading version $version" + aws s3 sync s3://${{ secrets.S3_BUCKET_NAME }}/versions/$version/ upload/simple/${{ env.PACKAGE_NAME }}/ || echo "Version $version not found in S3" + fi + done < all_versions.txt + - name: Generate package index HTML run: | cat > upload/simple/${{ env.PACKAGE_NAME }}/index.html << EOF @@ -65,6 +102,7 @@ jobs: