Update README #959
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Update README | |
| # This workflow runs AFTER "Deploy Layers" completes successfully. | |
| # No version checking is needed here because: | |
| # 1. Deploy Layers already checks for new versions and skips if none exist | |
| # 2. Deploy Layers updates .tag_version before this workflow runs | |
| # 3. If this workflow is triggered, README should always be updated | |
| on: | |
| # push: | |
| # branches: | |
| # - master | |
| workflow_run: | |
| workflows: ["Deploy Layers"] | |
| types: | |
| - completed | |
| jobs: | |
| update_readme: | |
| runs-on: ubuntu-latest | |
| if: ${{ github.event.workflow_run.conclusion == 'success' }} | |
| env: | |
| AWS_REGIONS: "us-east-1 us-east-2 us-west-1 us-west-2 ca-central-1 eu-central-1 eu-west-1 eu-west-2 eu-west-3 eu-north-1 ap-northeast-1 ap-northeast-2 ap-southeast-1 ap-southeast-2 ap-south-1 sa-east-1" | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v2 | |
| - name: Setup AWS CLI | |
| uses: aws-actions/configure-aws-credentials@v1 | |
| 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: Get Latest Release Info | |
| run: | | |
| JSON_RESPONSE=$(curl -s https://api.github.com/repos/Sparticuz/chromium/releases/latest) | |
| TAG_VERSION=$(echo $JSON_RESPONSE | grep -Po '"tag_name": "\K[^"]+') | |
| # Get layer file sizes for both architectures and convert to MB | |
| # Use jq for more reliable JSON parsing | |
| X64_SIZE_BYTES=$(echo "$JSON_RESPONSE" | jq -r '.assets[] | select(.name | contains("layer") and contains(".x64.zip")) | .size' | head -1) | |
| ARM64_SIZE_BYTES=$(echo "$JSON_RESPONSE" | jq -r '.assets[] | select(.name | contains("layer") and contains(".arm64.zip")) | .size' | head -1) | |
| if [[ -n "$X64_SIZE_BYTES" && "$X64_SIZE_BYTES" != "null" ]]; then | |
| X64_SIZE_MB=$((X64_SIZE_BYTES / 1024 / 1024)) | |
| echo "X64_SIZE_MB=$X64_SIZE_MB" >> $GITHUB_ENV | |
| fi | |
| if [[ -n "$ARM64_SIZE_BYTES" && "$ARM64_SIZE_BYTES" != "null" ]]; then | |
| ARM64_SIZE_MB=$((ARM64_SIZE_BYTES / 1024 / 1024)) | |
| echo "ARM64_SIZE_MB=$ARM64_SIZE_MB" >> $GITHUB_ENV | |
| fi | |
| echo "TAG_VERSION=$TAG_VERSION" >> $GITHUB_ENV | |
| - name: Update README | |
| run: | | |
| TAG_VERSION=${{ env.TAG_VERSION }} | |
| X64_SIZE_MB=${{ env.X64_SIZE_MB }} | |
| ARM64_SIZE_MB=${{ env.ARM64_SIZE_MB }} | |
| ARN_BASE="arn:aws:lambda:" | |
| ACCOUNT_ID="764866452798" | |
| sed -i -e "s|> .*compressed with Brotli|> ${X64_SIZE_MB} MB (x64) / ${ARM64_SIZE_MB} MB (arm64) Chromium layer for AWS Lambda compressed with Brotli|g" readme.md | |
| sed -i -e "s|Has Chromium v[0-9\.]*|Has Chromium $TAG_VERSION|g" readme.md | |
| for REGION in ${{ env.AWS_REGIONS }}; do | |
| # Get only the first line, then trim whitespace to ensure single version number | |
| X64_VERSION=$(aws lambda list-layer-versions --layer-name chrome-aws-lambda --region $REGION --query 'LayerVersions[0].Version' --output text 2>/dev/null | head -1 | tr -d ' \t\n\r') | |
| if [[ -z "$X64_VERSION" ]]; then X64_VERSION="1"; fi | |
| ARM64_VERSION=$(aws lambda list-layer-versions --layer-name chrome-aws-lambda-arm64 --region $REGION --query 'LayerVersions[0].Version' --output text 2>/dev/null | head -1 | tr -d ' \t\n\r') | |
| if [[ -z "$ARM64_VERSION" ]]; then ARM64_VERSION="1"; fi | |
| echo "Region: $REGION, x64 Version: $X64_VERSION, arm64 Version: $ARM64_VERSION" | |
| X64_ARN="$ARN_BASE$REGION:$ACCOUNT_ID:layer:chrome-aws-lambda:$X64_VERSION" | |
| ARM64_ARN="$ARN_BASE$REGION:$ACCOUNT_ID:layer:chrome-aws-lambda-arm64:$ARM64_VERSION" | |
| sed -i -e "s|arn:aws:lambda:$REGION:[0-9]*:layer:chrome-aws-lambda:[0-9]*|$X64_ARN|g" readme.md | |
| sed -i -e "s|arn:aws:lambda:$REGION:[0-9]*:layer:chrome-aws-lambda-arm64:[0-9]*|$ARM64_ARN|g" readme.md | |
| done | |
| - name: Commit and Push | |
| run: | | |
| git config --local user.email "action@github.com" | |
| git config --local user.name "GitHub Action" | |
| if ! git diff --quiet readme.md; then | |
| git add readme.md | |
| git commit -m "Update README with new version details [ci skip]" | |
| git push | |
| echo "README updated and pushed" | |
| else | |
| echo "No changes to README, skipping commit" | |
| fi |