Skip to content

Commit

Permalink
ci: sync progress by manual trigger (#632)
Browse files Browse the repository at this point in the history
  • Loading branch information
ParanoidUser authored Aug 18, 2024
1 parent 88d4d88 commit b2c448b
Showing 1 changed file with 22 additions and 21 deletions.
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

0 comments on commit b2c448b

Please sign in to comment.