-
Notifications
You must be signed in to change notification settings - Fork 37
85 lines (67 loc) · 2.59 KB
/
clean-up-unused-images.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
name: Clean Up Unused Images
on:
schedule:
# On the first of every month at 2 am
- cron: '0 2 1 * *'
workflow_dispatch:
push:
branches: ['clean-up-images-doc-1232']
concurrency:
group: clean-up-images-${{ github.ref }}
cancel-in-progress: true
jobs:
find_unused_images:
runs-on: ubuntu-latest
steps:
- name: Retrieve Credentials
id: import-secrets
uses: hashicorp/[email protected]
with:
url: https://vault.prism.spectrocloud.com
method: approle
roleId: ${{ secrets.VAULT_ROLE_ID }}
secretId: ${{ secrets.VAULT_SECRET_ID }}
secrets: /providers/github/organizations/spectrocloud/token?org_name=spectrocloud token | VAULT_GITHUB_TOKEN
- id: checkout
name: Checkout Repository
uses: actions/checkout@v4
with:
token: ${{ steps.import-secrets.outputs.VAULT_GITHUB_TOKEN }}
- name: Setup Nodejs
uses: actions/setup-node@v4
with:
node-version: "20"
- run: npm ci
- name: Find unused images
run: make find-unused-images
- name: Set Git User
# see: https://github.com/actions/checkout/issues/13#issuecomment-724415212
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Create PR with unused images
run: |
# Ensure that we are on master.
git checkout master
# Create a new branch.
branch_name="clean-up-unused-images-$(date +%Y%m%d%H%M%S)"
git checkout -b "$branch_name"
# Remove all the images identified as unused.
for img in $(cat unused_images.json); do
rm static/assets/docs/images/$img
done
# Clean up results file.
rm unused_images.json
# Commit and push branch
git add .
git commit -m "docs: clean up unused images"
git push origin $branch_name
# Create the pull request
echo -e '
## Describe the Change \n
This PR removes images identified as unused across all our branches.\n
The images are identified using `scripts/find-unused-images.sh` script.\n
Please review this PR carefully before merging it.\n' > pr_body
export pr_body=$(cat pr_body) ; gh pr create --base master --title "docs: clean up librarium unused images " --body "$pr_body"
env:
GH_TOKEN: ${{ steps.import-secrets.outputs.VAULT_GITHUB_TOKEN }}