diff --git a/.github/workflows/readme-stars.yml b/.github/workflows/readme-stars.yml new file mode 100644 index 0000000..12137dd --- /dev/null +++ b/.github/workflows/readme-stars.yml @@ -0,0 +1,52 @@ +name: Update README ⭐ +on: + schedule: + - cron: "0 11 * 12 *" + push: + branches: + - main + workflow_dispatch: + +jobs: + update-readme: + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Check year for cron + if: github.event_name == 'schedule' + run: | + current_year=$(date +'%Y') + if [ "$current_year" -ne "2024" ]; then + echo "No longer 2024, delete this action's schedule." + exit 1 + fi + + - name: Check commit message for push + id: check_commit_message + if: github.event_name == 'push' + continue-on-error: true + run: | + COMMIT_MESSAGE=$(git log -1 --pretty=%B) + if ! [[ "$COMMIT_MESSAGE" =~ ^day\ [0-9]{2}$ ]]; then + echo "Commit message does not match solution pattern" + exit 1 + fi + + - name: Update README stars + id: update_readme_stars + if: steps.check_commit_message.outcome == 'success' || github.event_name != 'push' + uses: k2bd/advent-readme-stars@v1 + with: + userId: 4388690 + year: 2024 + sessionCookie: ${{ secrets.AOC_SESSION }} + + - name: Commit changes + if: steps.update_readme_stars.outcome == 'success' + uses: stefanzweifel/git-auto-commit-action@v5 + with: + commit_message: auto-update README stars diff --git a/README.md b/README.md index daa1424..0810e74 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,8 @@ Use the `test` task to run all tests against the sample data (mostly for CI): deno run test ``` + + ## Useful references - https://github.com/denoland/advent-of-code-2024