forked from Euro-Office/DocumentServer
-
Notifications
You must be signed in to change notification settings - Fork 0
145 lines (135 loc) · 5.48 KB
/
Copy pathstrip-logo-clause.yml
File metadata and controls
145 lines (135 loc) · 5.48 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
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
name: Strip Section 7(b) trademark clause
run-name: "Strip Section 7(b) clause (${{ inputs.project }})"
on:
workflow_dispatch:
inputs:
project:
description: 'Project to strip (or "all")'
required: true
type: choice
options:
- all
- web-apps
- sdkjs
- sdkjs-forms
- core
- server
- fork
auto-merge:
description: 'Trigger auto bot merge'
required: false
type: boolean
default: false
jobs:
prepare:
runs-on: self-hosted
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Build matrix
id: set-matrix
run: |
if [ "${{ inputs.project }}" = "all" ]; then
echo 'matrix=["web-apps","sdkjs","sdkjs-forms","core","server","fork"]' >> "$GITHUB_OUTPUT"
else
echo 'matrix=["${{ inputs.project }}"]' >> "$GITHUB_OUTPUT"
fi
strip:
needs: prepare
runs-on: self-hosted
strategy:
fail-fast: false
matrix:
repo: ${{ fromJson(needs.prepare.outputs.matrix) }}
env:
PATTERN: "Pursuant to Section 7(b)"
BRANCH_NAME: chore/strip-logo-clause-${{ github.run_id }}
GIT_AUTHOR_NAME: Euro-Office Robot
GIT_AUTHOR_EMAIL: eo-robot@users.noreply.github.com
GIT_COMMITTER_NAME: Euro-Office Robot
GIT_COMMITTER_EMAIL: eo-robot@users.noreply.github.com
steps:
- name: Fetch templates
env:
GH_TOKEN: ${{ secrets.EURO_OFFICE_MIRROR_TOKEN }}
run: |
mkdir -p /tmp/templates
for f in strip-logo-clause-commit.txt strip-logo-clause-pr-body.txt; do
curl -sfH "Authorization: token $GH_TOKEN" \
"https://raw.githubusercontent.com/Euro-Office/fork/main/scripts/$f" \
-o "/tmp/templates/$f"
done
- name: Checkout ${{ matrix.repo }}
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
with:
repository: Euro-Office/${{ matrix.repo }}
token: ${{ secrets.EURO_OFFICE_MIRROR_TOKEN }}
ref: main
- name: Check for clause
id: check
run: |
EXCLUDE_PATHS=(! -path "*/node_modules/*" ! -path "*/vendor/*")
# When running on fork, skip submodule directories to avoid double-processing
if [ "${{ matrix.repo }}" = "fork" ]; then
EXCLUDE_PATHS+=(! -path "*/web-apps/*" ! -path "*/sdkjs/*" ! -path "*/core/*" ! -path "*/server/*")
fi
count=$(find . -type f \( -name "*.js" -o -name "*.less" -o -name "*.css" \
-o -name "*.html" -o -name "*.htm" -o -name "*.py" -o -name "*.sh" \
-o -name "*.json" -o -name "*.ts" -o -name "*.cpp" -o -name "*.h" \
-o -name "*.c" \) \
"${EXCLUDE_PATHS[@]}" \
-exec grep -l "$PATTERN" {} + 2>/dev/null | wc -l | tr -d ' ')
echo "count=$count" >> "$GITHUB_OUTPUT"
if [ "$count" -eq 0 ]; then
echo "No files contain the clause in ${{ matrix.repo }}. Skipping."
else
echo "Found $count files with the clause in ${{ matrix.repo }}."
fi
- name: Strip clause
if: steps.check.outputs.count != '0'
run: |
EXCLUDE_PATHS=(! -path "*/node_modules/*" ! -path "*/vendor/*")
if [ "${{ matrix.repo }}" = "fork" ]; then
EXCLUDE_PATHS+=(! -path "*/web-apps/*" ! -path "*/sdkjs/*" ! -path "*/core/*" ! -path "*/server/*")
fi
find . -type f \( -name "*.js" -o -name "*.less" -o -name "*.css" \
-o -name "*.html" -o -name "*.htm" -o -name "*.py" -o -name "*.sh" \
-o -name "*.json" -o -name "*.ts" -o -name "*.cpp" -o -name "*.h" \
-o -name "*.c" \) \
"${EXCLUDE_PATHS[@]}" \
-exec sed -i \
-e '/Pursuant to Section 7(b)/,/grant you any rights under trademark law/d' \
-e '/You can contact Ascensio System SIA/,/street, Riga, Latvia/d' \
-e '/^ \*$/{N;s/^ \*\n \*$/ */;}' \
-e '/^[[:space:]]*$/{N;/^[[:space:]]*\n[[:space:]]*$/d;}' {} +
- name: Create branch and commit
if: steps.check.outputs.count != '0'
id: commit
run: |
git checkout -b "$BRANCH_NAME"
git add -u
if git diff --cached --quiet; then
echo "No changes after stripping. Skipping."
echo "has_changes=false" >> "$GITHUB_OUTPUT"
exit 0
fi
echo "has_changes=true" >> "$GITHUB_OUTPUT"
git commit -F /tmp/templates/strip-logo-clause-commit.txt
git push origin "$BRANCH_NAME"
- name: Create pull request
if: steps.check.outputs.count != '0' && steps.commit.outputs.has_changes == 'true'
env:
GH_TOKEN: ${{ secrets.EURO_OFFICE_MIRROR_TOKEN }}
run: |
sed 's/__COUNT__/${{ steps.check.outputs.count }}/g' /tmp/templates/strip-logo-clause-pr-body.txt > /tmp/pr-body.txt
PR_URL=$(gh pr create \
--repo "Euro-Office/${{ matrix.repo }}" \
--base main \
--head "$BRANCH_NAME" \
--title "chore(license): Remove non-obligatory Section 7 additions" \
--body-file /tmp/pr-body.txt)
echo "PR created: $PR_URL"
if [ "${{ inputs.auto-merge }}" = "true" ]; then
gh pr merge "$PR_URL" --merge --delete-branch
echo "PR bot-merged and branch deleted."
fi