Skip to content

Merge pull request #218 from rstcheck/pre-commit-ci-update-config #195

Merge pull request #218 from rstcheck/pre-commit-ci-update-config

Merge pull request #218 from rstcheck/pre-commit-ci-update-config #195

---
name: Update AUTHORS.rst
# What this workflow does:
# 1. Update the AUTHORS.rst file
# 2. Git commit and push the file if there are changes.
on: # yamllint disable-line rule:truthy
workflow_dispatch:
push:
tags:
- "!*"
branches:
- main
- "test-me-*"
jobs:
update-authors:
name: Update AUTHORS.rst file
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Update AUTHORS.rst file
shell: python
run: |
import subprocess
git_authors = subprocess.run(
["git", "log", "--format=%aN <%aE>"], capture_output=True, check=True
).stdout.decode()
skip_list = (
"Steven Myint",
"dependabot",
"pre-commit-ci",
"github-action",
"GitHub Actions",
)
authors = [
author
for author in set(git_authors.strip().split("\n"))
if not author.startswith(skip_list)
]
authors.sort()
file_head = (
".. This file is automatically generated/updated by a github actions workflow.\n"
".. Every manual change will be overwritten on push to main.\n"
".. You can find it here: ``.github/workflows/update-authors.yaml``\n"
".. For more information see "
"`https://github.com/rstcheck/rstcheck/graphs/contributors`\n\n"
"Author\n"
"------\n"
"Steven Myint <git@stevenmyint.com>\n\n"
"Additional contributions by (sorted by name)\n"
"--------------------------------------------\n"
)
with open("AUTHORS.rst", "w") as authors_file:
authors_file.write(file_head)
authors_file.write("- ")
authors_file.write("\n- ".join(authors))
authors_file.write("\n")
- name: Check if diff
continue-on-error: true
run: >
git diff --exit-code AUTHORS.rst &&
(echo "### No update" && exit 1) || (echo "### Commit update")
- uses: EndBug/add-and-commit@v9
name: Commit and push if diff
if: success()
with:
add: AUTHORS.rst
message: Update AUTHORS.rst file with new author(s)
author_name: GitHub Actions
author_email: action@github.com
committer_name: GitHub Actions
committer_email: actions@github.com
push: true