1
0
mirror of synced 2026-01-16 18:01:39 -05:00

Update orphaned-actions-check.yml to work with reusables too (#52325)

This commit is contained in:
Ashish Keshan
2024-09-24 10:02:59 -07:00
committed by GitHub
parent 096c6daa4e
commit a041d79ec6

View File

@@ -1,6 +1,6 @@
name: 'Orphaned assets check'
name: 'Orphaned files check'
# **What it does**: Checks that there are no files in ./assets/ that aren't mentioned in any source file.
# **What it does**: Checks that there are no files in ./assets/ and ./data/reusables that aren't mentioned in any source file.
# **Why we have it**: To avoid orphans into the repo.
# **Who does it impact**: Docs content.
@@ -14,6 +14,7 @@ on:
# In case any of the dependencies affect the script
- 'package*.json'
- src/assets/scripts/find-orphaned-assets.js
- src/content-render/scripts/reusables-cli/find/unused.ts
- src/workflows/walk-files.js
- src/languages/lib/languages.js
- .github/actions/clone-translations/action.yml
@@ -44,7 +45,7 @@ jobs:
- uses: ./.github/actions/node-npm-setup
- name: Check for orphaned assets
- name: Check for orphaned assets and reusables
env:
# Needed for gh
GITHUB_TOKEN: ${{ secrets.DOCS_BOT_PAT_READPUBLICKEY }}
@@ -54,10 +55,16 @@ jobs:
# The `-s` is to make npm run silent and not print verbose
# information about the npm script alias.
filesToRemove=`npm run -s find-orphaned-assets`
[ -z "$filesToRemove" ] && exit 0
assetFilesToRemove=$(npm run -s find-orphaned-assets)
reusableFilesToRemove=$(npm run -s reusables -- find unused | grep '^data/reusables')
[ -z "$assetFilesToRemove" ] && [ -z "$reusableFilesToRemove" ] && exit 0
echo $filesToRemove | xargs git rm
if [ -n "$assetFilesToRemove" ]; then
echo $assetFilesToRemove | xargs git rm
fi
if [ -n "$reusableFilesToRemove" ]; then
echo $reusableFilesToRemove | xargs git rm
fi
git status
@@ -76,25 +83,26 @@ jobs:
git config --global user.email "77750099+docs-bot@users.noreply.github.com"
date=$(date '+%Y-%m-%d-%H-%M')
branchname=orphaned-assets-$date-$GITHUB_RUN_ID
branchname=orphaned-files-$date-$GITHUB_RUN_ID
git checkout -b $branchname
git commit -m "Delete orphaned assets $date"
git commit -m "Delete orphaned files $date"
git push origin $branchname
body=$(cat <<-EOM
Found with the npm run find-orphaned-assets script.
The orphaned assets workflow file .github/workflows/orphaned-assets-check.yml
The orphaned files workflow file .github/workflows/orphaned-files-check.yml
runs every Monday at 16:20 UTC / 8:20 PST.
The first responder should just spot-check some of the unused assets
to make sure they aren't referenced anywhere
and then approve and merge the pull request.
For more information, see [Doc: Orphaned Assets](https://github.com/github/docs-engineering/blob/main/docs/orphaned-assets.md).
For more information, see [Doc: Orphaned Assets](https://github.com/github/docs-engineering/blob/main/docs/orphaned-assets.md)
and [Doc: Reusables CLI](https://github.com/github/docs-internal/tree/main/src/content-render/scripts/reusables-cli).
EOM
)
gh pr create \
--title "Delete orphaned assets ($date)" \
--title "Delete orphaned files ($date)" \
--body "$body" \
--repo github/docs-internal \
--label docs-content-fr