Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions .github/workflows/check-closed-preview-read.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Check closed website preview once

on:
schedule:
- cron: '11,26,41,56 * * * *'

permissions: {}

# Temporary read for #403. Remove after the first attempt is recorded.
jobs:
read:
if: >-
github.event_name == 'schedule' &&
github.repository == 'libtmux/docs' &&
github.repository_id == '1358425658' &&
github.ref == 'refs/heads/main' &&
github.run_number == '1' &&
github.run_attempt == '1'
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
id-token: write
environment:
name: docs-preview-cleanup
deployment: false
steps:
- uses: aws-actions/configure-aws-credentials@45666896f5d8e0f10ae255413f3a4cdd03bdc8f5 # v6.3.1
with:
role-to-assume: ${{ secrets.LIBTMUX_DOCS_PREVIEW_CLEANUP_ROLE_ARN }}
aws-region: us-east-1
role-duration-seconds: 900
mask-aws-account-id: true
inline-session-policy: >-
{"Version":"2012-10-17","Statement":[
{"Effect":"Allow","Action":"s3:ListBucket","Resource":"arn:aws:s3:::${{ secrets.LIBTMUX_DOCS_BUCKET }}","Condition":{"StringEquals":{"s3:prefix":"pr-383/","aws:RequestedRegion":"us-east-1"},"NumericEquals":{"s3:max-keys":1}}},
{"Effect":"Deny","NotAction":"s3:ListBucket","Resource":"*"},
{"Effect":"Deny","Action":"s3:ListBucket","NotResource":"arn:aws:s3:::${{ secrets.LIBTMUX_DOCS_BUCKET }}"},
{"Effect":"Deny","Action":"s3:ListBucket","Resource":"*","Condition":{"StringNotEqualsIfExists":{"s3:prefix":"pr-383/"}}},
{"Effect":"Deny","Action":"s3:ListBucket","Resource":"*","Condition":{"NumericNotEqualsIfExists":{"s3:max-keys":1}}},
{"Effect":"Deny","Action":"s3:ListBucket","Resource":"*","Condition":{"StringNotEqualsIfExists":{"aws:RequestedRegion":"us-east-1"}}}
]}

- name: Check whether pr-383/ contains objects
shell: bash
env:
BUCKET: ${{ secrets.LIBTMUX_DOCS_BUCKET }}
AWS_RETRY_MODE: standard
AWS_MAX_ATTEMPTS: '1'
AWS_ENDPOINT_URL_S3: https://s3.us-east-1.amazonaws.com
run: |
if ! count=$(aws s3api list-objects-v2 --bucket "$BUCKET" --prefix pr-383/ \
--max-keys 1 --no-paginate --query KeyCount --output text 2>/dev/null); then
echo '::error::Preview lookup failed' >&2
exit 1
fi
case "$count" in
0) echo false ;;
1) echo true ;;
*) echo '::error::Unexpected preview key count' >&2; exit 1 ;;
esac