Skip to content

Commit 5eb2aa8

Browse files
committed
build: add workflow to cleanup coverage directories
1 parent 4dbd1db commit 5eb2aa8

File tree

1 file changed

+166
-0
lines changed

1 file changed

+166
-0
lines changed

Diff for: .github/workflows/cleanup_coverage.yml

+166
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
#/
2+
# @license Apache-2.0
3+
#
4+
# Copyright (c) 2025 The Stdlib Authors.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#/
18+
19+
# Workflow name:
20+
name: cleanup_coverage
21+
22+
# Workflow triggers:
23+
on:
24+
# Run the workflow on the first day of each week:
25+
schedule:
26+
- cron: '0 0 * * 1'
27+
28+
# Allow the workflow to be manually run:
29+
workflow_dispatch:
30+
31+
# Global permissions:
32+
permissions:
33+
# Allow read-only access to the repository contents:
34+
contents: read
35+
36+
# Workflow jobs:
37+
jobs:
38+
39+
# Define a job for cleaning up unneeded coverage reports:
40+
coverage:
41+
42+
# Define a display name:
43+
name: 'Clean up unneeded coverage reports'
44+
45+
# Define the type of virtual host machine:
46+
runs-on: ubuntu-latest
47+
48+
# Define the sequence of job steps...
49+
steps:
50+
# Checkout the repository:
51+
- name: 'Checkout repository'
52+
# Pin action to full length commit SHA
53+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
54+
with:
55+
# Specify whether to remove untracked files before checking out the repository:
56+
clean: true
57+
58+
# Limit clone depth to the most recent commit:
59+
fetch-depth: 1
60+
61+
# Specify whether to download Git-LFS files:
62+
lfs: false
63+
64+
# Avoid storing GitHub token in local Git configuration:
65+
persist-credentials: false
66+
timeout-minutes: 10
67+
68+
# Checkout development repository:
69+
- name: 'Checkout development repository'
70+
# Pin action to full length commit SHA
71+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
72+
with:
73+
# Code development repository:
74+
repository: 'stdlib-js/stdlib'
75+
76+
# Branch to checkout:
77+
ref: 'develop'
78+
79+
# File path to checkout to:
80+
path: './tmp'
81+
82+
# Specify whether to remove untracked files before checking out the repository:
83+
clean: false
84+
85+
# Limit clone depth to the most recent commit:
86+
fetch-depth: 1
87+
88+
# Token for accessing the repository:
89+
token: ${{ secrets.STDLIB_BOT_FGPAT_REPO_READ }}
90+
91+
# Avoid storing GitHub token in local Git configuration:
92+
persist-credentials: false
93+
94+
# Find and delete unneeded coverage directories:
95+
- name: 'Find and delete unneeded coverage directories'
96+
run: |
97+
# Find all coverage directories:
98+
find . \
99+
\( -name .git -prune \) -o \
100+
\( -name .github -prune \) -o \
101+
\( -name etc -prune \) -o \
102+
\( -name lib -prune \) -o \
103+
\( -name public -prune \) -o \
104+
\( -name server -prune \) -o \
105+
\( -name src -prune \) -o \
106+
\( -name tmp -prune \) -o \
107+
\( -name tools -prune \) -o -type d -print | \
108+
sed "s|^.\/||" | \
109+
sed "s|^.$||" | \
110+
sed -E 's/\/(benchmark|bin|data|docs|etc|examples|include|lib|scripts|src|test)(\/.*)?$//' | \
111+
sort -u > coverage_dirs.txt
112+
113+
# Path to main package directory in development repository:
114+
pkg_dir='./tmp/lib/node_modules/@stdlib'
115+
116+
# Extract all packages currently residing in `pkg_dir`:
117+
find $pkg_dir -type d -print | \
118+
sed "s|^$pkg_dir/||" | \
119+
sed -E 's/\/(benchmark|bin|data|docs|etc|examples|include|lib|scripts|src|test)(\/.*)?$//' | \
120+
sort -u > package_dirs.txt
121+
122+
# Find entries present in `coverage_dir` but not in `package_dirs`:
123+
comm -23 coverage_dirs.txt package_dirs.txt > dirs_to_remove.txt
124+
125+
# Delete directories:
126+
while IFS= read -r dir; do
127+
rm -r -- "$dir"
128+
done < dirs_to_remove.txt
129+
130+
# Perform clean-up:
131+
rm coverage_dirs.txt
132+
rm package_dirs.txt
133+
rm dirs_to_remove.txt
134+
135+
# Import GPG key to sign commits:
136+
- name: 'Import GPG key to sign commits'
137+
# Pin action to full length commit SHA
138+
uses: crazy-max/ghaction-import-gpg@cb9bde2e2525e640591a934b1fd28eef1dcaf5e5 # v6.2.0
139+
with:
140+
gpg_private_key: ${{ secrets.STDLIB_BOT_GPG_PRIVATE_KEY }}
141+
passphrase: ${{ secrets.STDLIB_BOT_GPG_PASSPHRASE }}
142+
git_user_signingkey: true
143+
git_commit_gpgsign: true
144+
145+
# Create a pull request with the changes:
146+
- name: 'Create pull request'
147+
id: cpr
148+
# Pin action to full length commit SHA
149+
uses: peter-evans/create-pull-request@67ccf781d68cd99b580ae25a5c18a1cc84ffff1f # v7.0.6
150+
with:
151+
title: 'chore: cleanup coverage directories'
152+
body: |
153+
This PR
154+
155+
- removes all coverage directories that do not correspond anymore to packages in the main development repository.
156+
157+
commit-message: 'chore: cleanup coverage directories'
158+
committer: 'stdlib-bot <[email protected]>'
159+
signoff: true
160+
token: ${{ secrets.STDLIB_BOT_PAT_REPO_WRITE }}
161+
labels: |
162+
automated-pr
163+
team-reviewers: |
164+
reviewers
165+
branch: cleanup-coverage-directories
166+
delete-branch: true

0 commit comments

Comments
 (0)