Skip to content

add a way of warning users that localised docs might be out of date (… #190

add a way of warning users that localised docs might be out of date (…

add a way of warning users that localised docs might be out of date (… #190

name: Contributor Updater
on:
workflow_dispatch:
push:
paths: [ content/asciidoc-pages/** ]
branches: [ main ]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: write
pull-requests: write
jobs:
check_contributors:
if: github.repository_owner == 'adoptium'
name: Check Contributors
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
with:
persist-credentials: false
- id: files
uses: jitterbit/get-changed-files@b17fbb00bdc0c0f63fcf166580804b4d2cdc2a42 # v1
if: github.event_name == 'push'
- 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
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@dc1726cbf4dd3ce766af4ec29cfb660e0125e8ee # v1
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]>"