-
-
Notifications
You must be signed in to change notification settings - Fork 118
81 lines (72 loc) · 3.35 KB
/
check-contributors.yml
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
name: Contributor Updater
on:
workflow_dispatch:
push:
paths: [ content/asciidoc-pages/** ]
branches: [ main ]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
check_contributors:
if: github.repository_owner == 'adoptium'
name: Check Contributors
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
with:
persist-credentials: false
fetch-depth: 0
- name: Get changed files
if: github.event_name == 'push'
id: files
run: |
changed_files=$(git diff --name-only "${{ github.event.before }}" "${{ github.sha }}")
echo "all=$changed_files" >> "$GITHUB_OUTPUT"
- run: pip3 install bs4
- run: |
# This function takes one argument, which is the path to a file.
# The function first checks if the file path matches a regular expression pattern for AsciiDoc files located in the "content/asciidoc" directory
# If the file path matches the pattern, the function extracts the current authors from the file using grep and sed. It then uses a Python script to determine the contributors to the file and loops through each contributor.
# For each contributor, the function checks if they are already listed as an author in the file. If not, it adds the contributor to the list of authors and updates the file using sed.
update_authors() {
local file=$1
if [[ ${file} =~ ^content/asciidoc.*.adoc ]]; then
# If page is in a _partials directory, skip it
if [[ ${file} =~ ^content/asciidoc.*_partials.*.adoc ]]; then
return
fi
current_authors=$(grep ':page-authors:' "${file}" | sed -n -e 's/^.*page-authors: //p')
contibutors=$(python3 .github/workflows/github-file-contributors.py --file "${file}")
for contibutor in ${contibutors}; do
if ! echo "${current_authors}" | grep "${contibutor}"; then
echo "adding ${contibutor}"
current_authors_replacement="${current_authors}, ${contibutor}"
echo "${current_authors_replacement}"
sed -i "s/${current_authors}/${current_authors_replacement}/g" "${file}"
fi
done
fi
}
# if workflow_dispatch, then we need to get all asciidoc files
if [[ -z "${{ steps.files.outputs.all }}" ]]; then
find content/asciidoc-pages -name '*.adoc' -type f | while read -r changed_file; do
update_authors "${changed_file}"
done
else
# shellcheck disable=2043
for changed_file in ${{ steps.files.outputs.all }}; do
update_authors "${changed_file}"
done
fi
- uses: gr2m/create-or-update-pull-request-action@86ec1766034c8173518f61d2075cc2a173fb8c97 # v1.9.4
env:
GITHUB_TOKEN: ${{ secrets.ADOPTIUM_BOT_TOKEN }}
with:
title: "Update Asciidoc Contributors"
body: "This is an automatically generated pull request, it will be automatically merged if all the CI tests pass."
path: "content/asciidoc-pages/"
branch: "contributor_bot"
commit-message: "contributors: update asciidoc contributors"
labels: automerge
author: "adoptium-bot <[email protected]>"