1
0
mirror of synced 2026-01-05 21:04:17 -05:00
Files
docs/.github/workflows/orphaned-assets-check.yml
Peter Bengtsson 5d7973b928 make PR about deletable orphan assets (#26484)
* warn on orphan images

* oops

* temporarily adding orphan image

* fix the bug

* permission

* better comment

* try this

* try this

* debugging

* debugging

* using fs

* cjs

* remove experiment image

* debugging

* debugging

* try that

* try that

* git config

* cleaning

* token

* body

* label

* try that

* try that

* try that

* not upstream

* try that

* token twice

* try again

* cleaning up

* fix unit test

* one more exception

* feedbacked
2022-03-30 11:56:18 -04:00

64 lines
2.0 KiB
YAML

name: 'Orphaned assets check'
# **What it does**: Checks that there are no files in ./assets/ that aren't mentioned in any source file.
# **Why we have it**: To avoid orphans into the repo.
# **Who does it impact**: Docs content.
on:
workflow_dispatch:
schedule:
- cron: '13 10 * * *' # Once a day at 10:13 UTC
permissions:
contents: read
jobs:
orphaned-assets-check:
if: ${{ github.repository == 'github/docs-internal' }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579
with:
# Using a PAT is necessary so that the new commit will trigger the
# CI in the PR. (Events from GITHUB_TOKEN don't trigger new workflows.)
token: ${{ secrets.DOCUBOT_REPO_PAT }}
- name: Setup node
uses: actions/setup-node@1f8c6b94b26d0feae1e387ca63ccbdc44d27b561
with:
node-version: 16.14.x
cache: npm
- name: Install
run: npm ci
- name: Check for orphaned assets
env:
# Needed for gh
GITHUB_TOKEN: ${{ secrets.DOCUBOT_REPO_PAT }}
run: |
set -e
./script/find-orphaned-assets.mjs | xargs git rm
# If nothing to commit, exit now. It's fine. No orphans.
git status | grep 'nothing to commit' && exit 0
# Replicated from the translation pipeline PR-maker Action
git config --global user.name "docubot"
git config --global user.email "67483024+docubot@users.noreply.github.com"
date=$(date '+%Y-%m-%d-%H-%M')
branchname=orphaned-assets-$date-$GITHUB_RUN_ID
git checkout -b $branchname
git commit -m "Delete orphaned assets $date"
git push origin $branchname
gh pr create \
--title "Delete orphaned assets ($date)" \
--body "Found with the find-orphaned-assets.mjs script" \
--repo github/docs-internal \
--label docs-content-fr