Prune Previews #832
This file contains 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: Prune Previews | |
on: | |
push: | |
paths: | |
- '.github/workflows/prune_previews.yml' | |
schedule: | |
- cron: '05 2 * * *' | |
jobs: | |
remove: | |
name: Remove Stale Previews | |
runs-on: ubuntu-latest | |
steps: | |
- name: Find PRs | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.CROSSBOW_DOCS_AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.CROSSBOW_DOCS_AWS_SECRET_ACCESS_KEY }} | |
AWS_DEFAULT_REGION: ${{ secrets.CROSSBOW_DOCS_S3_BUCKET_REGION }} | |
BUCKET: ${{ secrets.CROSSBOW_DOCS_S3_BUCKET }} | |
run: | | |
echo "PRs=$(aws s3 ls $BUCKET/pr_docs/ | sed 's/PRE//g' | tr -d '/' | tr '\n' ' ')" >> $GITHUB_ENV | |
- name: Find open PRs | |
uses: actions/github-script@v5 | |
id: find | |
with: | |
script: | | |
let prs = "${{ env.PRs }}".split(" ").filter(x => x) | |
async function not_open(id) { | |
let pr; | |
try { | |
pr = await github.rest.pulls.get({ | |
"owner": "apache", | |
"repo": "arrow", | |
"pull_number": id | |
}) | |
} | |
catch(err) { | |
//In case of error retrieving PR try to clean it. | |
//Example manually triggered job with different naming. | |
return(id) | |
} | |
if(pr.data.state !== "open") { | |
return(id) | |
} | |
return("") | |
} | |
let del_prs = await Promise.all(prs.map(not_open)) | |
del_prs = del_prs.filter(x => x).join(" ") | |
console.log(`::set-output name=del_prs::${del_prs}`) | |
- name: Delete Dirs and Commit | |
if: steps.find.outputs.del_prs != '' | |
env: | |
pr_ids: ${{ steps.find.outputs.del_prs }} | |
AWS_ACCESS_KEY_ID: ${{ secrets.CROSSBOW_DOCS_AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.CROSSBOW_DOCS_AWS_SECRET_ACCESS_KEY }} | |
AWS_DEFAULT_REGION: ${{ secrets.CROSSBOW_DOCS_S3_BUCKET_REGION }} | |
BUCKET: ${{ secrets.CROSSBOW_DOCS_S3_BUCKET }} | |
run: | | |
for id in ${pr_ids[@]} | |
do | |
aws s3 rm $BUCKET/pr_docs/$id --recursive | |
done | |