-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_file_headers.sh
More file actions
executable file
·55 lines (47 loc) · 1.8 KB
/
update_file_headers.sh
File metadata and controls
executable file
·55 lines (47 loc) · 1.8 KB
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
#!/bin/bash
# Manually set fields
PROJECT_START="2025"
COPYRIGHT_OWNER="eVAL Agency"
# Fields retrieved from package.json
VERSION="$(grep "version" package.json | awk -F: '{ print $2 }' | sed 's/[",]//g' | tr -d '[[:space:]]')"
LICENSE="$(grep "license" package.json | awk -F: '{ print $2 }' | sed 's/[",]//g' | tr -d '[[:space:]]')"
LINK="$(grep "homepage" package.json | sed 's/^.*: //' | sed 's/[",]//g' | tr -d '[[:space:]]')"
PACKAGE="$(grep "title" package.json | awk -F: '{ print $2 }' | sed 's/[",]//g' | tr -d '[[:space:]]')"
# Calculated fields
YEAR_NOW=$(date +"%Y")
if [ "$YEAR_NOW" != "$PROJECT_START" ]; then
COPYRIGHT="$PROJECT_START-$YEAR_NOW $COPYRIGHT_OWNER"
else
COPYRIGHT="$PROJECT_START $COPYRIGHT_OWNER"
fi
if [ -n "$GITHUB_OUTPUT" ]; then
# If running in a git workflow environment, update file headers
# Skip this when in development, so as to not overwrite local changes
find dist -type f -name '*.php' | grep -v 'vendor/' | while read FILE; do
if ! egrep -q '^ \* @version' "$FILE"; then
echo "$FILE missing required attribute: @version"
else
sed -i "s/^ \* @version.*/ \* @version $VERSION/" "$FILE"
fi
if ! egrep -q '^ \* @copyright' "$FILE"; then
echo "$FILE missing required attribute: @copyright"
else
sed -i "s/^ \* @copyright.*/ \* @copyright $COPYRIGHT/" "$FILE"
fi
if ! egrep -q '^ \* @license' "$FILE"; then
echo "$FILE missing required attribute: @license"
else
sed -i "s/^ \* @license.*/ \* @license $LICENSE/" "$FILE"
fi
if ! egrep -q '^ \* @link' "$FILE"; then
echo "$FILE missing required attribute: @link"
else
sed -i "s#^ \* @link.*# \* @link $LINK#" "$FILE"
fi
if ! egrep -q '^ \* @package' "$FILE"; then
echo "$FILE missing required attribute: @package"
else
sed -i "s/^ \* @package.*/ \* @package $PACKAGE/" "$FILE"
fi
done
fi