diff --git a/.github/workflows/sync-progress.yml b/.github/workflows/sync-progress.yml index 928df82c..7e2650bb 100644 --- a/.github/workflows/sync-progress.yml +++ b/.github/workflows/sync-progress.yml @@ -1,32 +1,33 @@ 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 @@ -34,15 +35,15 @@ jobs: 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 \ No newline at end of file