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

ci: sync progress by manual trigger #632

Merged
merged 1 commit into from
Aug 18, 2024
Merged
Changes from all 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
43 changes: 22 additions & 21 deletions .github/workflows/sync-progress.yml
Original file line number Diff line number Diff line change
@@ -1,48 +1,49 @@
name: Sync Progress

on:
workflow_run:
workflows: [ Build CI ]
branches-ignore: [ main ]
types: [ completed ]
on: [ workflow_dispatch ]

jobs:
update-progress:
sync-progress:
runs-on: ubuntu-24.04
timeout-minutes: 1
if: ${{ github.event.workflow_run.conclusion == 'success' && contains(github.event.workflow_run.head_branch, 'kata/') }}
steps:
- name: Checkout repository
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
fetch-depth: 0
ref: ${{ github.event.workflow_run.head_branch }}

- name: Update README progress
- name: Sync progress
id: progress
run: |
TOTAL=$(curl https://www.codewars.com/kata/search/java | grep -Eo ".{5} Kata Found" | sed "s/[Kat Found,]//g")
echo "total=$TOTAL" >> $GITHUB_OUTPUT
COMPLETED=$(find ./kata -mindepth 2 -maxdepth 2 -not -empty -type d -not -path "./kata/retired/*" | wc -l)
PROGRESS=$(bc <<< "scale=1 ; 100 * $COMPLETED / $TOTAL")
sed -i -r "s/(completed%20kata-).*(%25-red.svg)/\1$PROGRESS\2/g" ./docs/README.md
echo "🎉 Current progress $PROGRESS% ($COMPLETED out of $TOTAL)" >> $GITHUB_STEP_SUMMARY
echo "completed=$COMPLETED" >> $GITHUB_OUTPUT
PERCENT=$(bc <<< "scale=1 ; 100 * $COMPLETED / $TOTAL")
echo "percent=$PERCENT" >> $GITHUB_OUTPUT
echo "🎉 Current progress $PERCENT% ($COMPLETED out of $TOTAL)" >> $GITHUB_STEP_SUMMARY

- name: Update README statistics
- name: Update progress
env:
PERCENT: ${{ steps.progress.outputs.percent }}
run: |
sed -i -r "s/(completed%20kata-).*(%25-red.svg)/\1$PERCENT\2/g" ./docs/README.md

- name: Update statistics
run: |
STATS="|"
for rank in ./kata/*; do
STATS+=" $(find $rank -mindepth 1 -maxdepth 1 -not -empty -type d | wc -l) |"
done
sed -i "28s/.*/$STATS/" ./docs/README.md

- name: Update Git repository
- name: Commit changes
run: |
git config user.name "$(git log -n 1 --pretty=format:%an)"
git config user.email "$(git log -n 1 --pretty=format:%ae)"
git add -A
if ! git diff-index --quiet HEAD; then
git commit --amend --no-edit
git push --force
echo "☑️ Codewars progress has been updated." >> $GITHUB_STEP_SUMMARY
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git commit -m "docs: sync progress"
git push
echo "⬆️ Codewars progress has been updated." >> $GITHUB_STEP_SUMMARY
else
echo "✅ Codewars progress is up to date." >> $GITHUB_STEP_SUMMARY
fi