Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Добавляет экшен обновления ченджлога #5324

Merged
merged 6 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions .github/scripts/update-changelog.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
git fetch origin ${{ github.base_ref }}
git diff --name-status origin/${{ github.base_ref }} HEAD | grep '^A' | grep -E '^(html|css|js|tools|a11y|recipies)/.*/$' > added_dirs.txt

month_to_rus() {
case "$1" in
01) echo "января" ;;
02) echo "февраля" ;;
03) echo "марта" ;;
04) echo "апреля" ;;
05) echo "мая" ;;
06) echo "июня" ;;
07) echo "июля" ;;
08) echo "августа" ;;
09) echo "сентября" ;;
10) echo "октября" ;;
11) echo "ноября" ;;
12) echo "декабря" ;;
esac
}

merge_date=$(date -u +"%d %m")
day=$(echo $merge_date | cut -d ' ' -f 1)
month=$(echo $merge_date | cut -d ' ' -f 2)
rus_month=$(month_to_rus $month)
formatted_date="${day} ${rus_month}"

if [ -s added_dirs.txt ]; then
while IFS= read -r dir; do
path=${dir%/*}
new_folder="${dir##*/}"
if [ -f "${path}/${new_folder}/index.md" ]; then
title=$(sed -n 's/^title: \(.*\)/\1/p' "${path}/${new_folder}/index.md")
authors=$(sed -n 's/^authors: \[?\(.*\)\]?/\\1/p' "${path}/${new_folder}/index.md")
author_links=()
IFS=',' read -ra ADDR <<< "$authors"
for author in "${ADDR[@]}"; do
trimmed_author=$(echo $author | xargs)
if [ -d "people/$trimmed_author" ] && [ -f "people/$trimmed_author/index.md" ]; then
author_name=$(sed -n 's/^name: \(.*\)/\1/p' "people/$trimmed_author/index.md")
author_links+=("[${author_name}](https://doka.guide/people/${trimmed_author}/)")
else
author_links+=("[${trimmed_author}](https://doka.guide/people/${trimmed_author}/)")
fi
done
authors_string=$(IFS=, ; echo "${author_links[*]}")
echo "- ${formatted_date}, [${title}](https://doka.guide/${path#*/}/${new_folder}/), ${authors_string}" >> CHANGELOG.md
solarrust marked this conversation as resolved.
Show resolved Hide resolved
fi
done < added_dirs.txt
git config --local user.email "<hi@doka.guide>"
git config --local user.name "Doka Dog"
git add CHANGELOG.md
git commit -m "Обновляет CHANGELOG"
git push
fi
25 changes: 25 additions & 0 deletions .github/workflows/update-changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Update CHANGELOG

on:
pull_request:
branches:
- main
types: [closed]

jobs:
update_changelog:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '20'

- name: Ищет новые материалы и обновляет CHANGELOG
run: sh .github/scripts/update-changelog.sh
Loading