update status page with results #38
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: Preview on PR | |
| on: | |
| pull_request: | |
| branches: [main] | |
| permissions: | |
| contents: read | |
| pull-requests: write # needed to comment on PR | |
| jobs: | |
| build-and-preview: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # Zola sometimes benefits from full history | |
| - name: Cache Zola binary | |
| id: cache-zola | |
| uses: actions/cache@v4 | |
| with: | |
| path: /usr/local/bin/zola | |
| key: zola-binary-v0.22.1-${{ runner.os }} | |
| - name: Install Zola (if not cached) | |
| if: steps.cache-zola.outputs.cache-hit != 'true' | |
| run: | | |
| wget -q https://github.com/getzola/zola/releases/download/v0.22.1/zola-v0.22.1-x86_64-unknown-linux-gnu.tar.gz | |
| tar xf zola-v0.22.1-x86_64-unknown-linux-gnu.tar.gz | |
| chmod +x zola | |
| sudo mv zola /usr/local/bin/zola | |
| - name: Determine preview path prefix | |
| id: vars | |
| run: | | |
| echo "prefix=pr-${{ github.event.number }}" >> $GITHUB_OUTPUT | |
| echo "short_sha=${GITHUB_SHA::8}" >> $GITHUB_OUTPUT | |
| - name: Generate version file | |
| run: | | |
| mkdir -p ./static/data | |
| TZ=UTC git show -s --date=iso-local --format='%h %cd' HEAD > ./static/data/version | |
| - name: Build Zola site | |
| run: zola build --base-url="https://${{ vars.LIBP2P_DOMAIN }}/preview/${{ steps.vars.outputs.prefix }}/" | |
| - name: Set up Node.js for ipfs-car | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| - name: Cache ipfs-car (global node_modules) | |
| id: cache-ipfs-car | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.npm/_npx | |
| key: ipfs-car-npx-${{ runner.os }}-node20 | |
| - name: Install ipfs-car (if not cached) | |
| if: steps.cache-ipfs-car.outputs.cache-hit != 'true' | |
| run: npm install -g ipfs-car | |
| - name: Create CAR archive of public folder | |
| run: ipfs-car pack ./public --output preview.car | |
| - name: Configure AWS credentials for Filebase | |
| env: | |
| AWS_ACCESS_KEY_ID: ${{ secrets.FILEBASE_ACCESS_KEY }} | |
| AWS_SECRET_ACCESS_KEY: ${{ secrets.FILEBASE_SECRET_KEY }} | |
| AWS_DEFAULT_REGION: us-east-1 # Filebase ignores region, but required | |
| run: | | |
| echo "AWS credentials exported as env vars" | |
| aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID | |
| aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY | |
| aws configure set default.region $AWS_DEFAULT_REGION | |
| aws configure list | |
| - name: Upload CAR to preview bucket (with import=car) | |
| id: upload | |
| env: | |
| AWS_EC2_METADATA_DISABLED: true | |
| run: | | |
| aws --endpoint https://s3.filebase.com \ | |
| s3 cp preview.car \ | |
| s3://${{ vars.FILEBASE_BUCKET_PROD }}/preview/${{ steps.vars.outputs.prefix }}/ \ | |
| --metadata 'import=car' | |
| aws --endpoint https://s3.filebase.com \ | |
| s3api head-object \ | |
| --bucket ${{ vars.FILEBASE_BUCKET_PROD }} \ | |
| --key preview/${{ steps.vars.outputs.prefix }}/preview.car > head-object.log 2>&1 | |
| # Extract CID from debug log (x-amz-meta-cid header) | |
| CID=$(jq -r .Metadata.cid head-object.log | tr -d '\r') | |
| if [ -z "$CID" ]; then | |
| echo "Failed to extract CID from upload response" | |
| cat head-object.log | |
| exit 1 | |
| fi | |
| echo "cid=$CID" >> $GITHUB_OUTPUT | |
| - name: Comment preview URL on PR | |
| uses: thollander/actions-comment-pull-request@v3 | |
| with: | |
| message: | | |
| **Preview ready!** | |
| View the preview build here: | |
| https://libp2p.myfilebase.com/ipfs/${{ steps.upload.outputs.cid }}/ | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| comment_tag: preview-url # avoids duplicate comments on rebuilds |