Added Prime number Checker in Java #68
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Update snippets index | |
| on: | |
| push: | |
| branches: [ main ] | |
| pull_request: | |
| types: [closed] | |
| # allow pushes | |
| permissions: | |
| contents: write | |
| jobs: | |
| generate-index: | |
| # Run on pushes or when a PR is merged — but skip runs triggered by the bot itself | |
| if: > | |
| (github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.merged == true)) | |
| && github.actor != 'github-actions[bot]' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository (full history & credentials) | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| persist-credentials: true | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.x' | |
| - name: Install requirements (if needed) | |
| run: | | |
| python -m pip install --upgrade pip | |
| # Install any minimal deps needed by tools/generate_index.py | |
| pip install PyGithub || true | |
| - name: Generate index | |
| run: python tools/generate_index.py | |
| - name: Commit and push index (safe, merges remote if necessary) | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| set -e | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add snippets/README.md | |
| # If nothing staged -> nothing to do | |
| if git diff --cached --quiet; then | |
| echo "No changes to commit" | |
| exit 0 | |
| fi | |
| git commit -m "chore: update snippets index" | |
| # Ensure we have the latest remote main to avoid non-fast-forward | |
| git fetch origin main | |
| # Try to rebase onto the latest remote main. If rebase fails, fall back to a merge. | |
| if git rebase origin/main; then | |
| echo "Rebase successful" | |
| else | |
| echo "Rebase failed; aborting rebase and trying merge" | |
| git rebase --abort || true | |
| git merge --no-edit origin/main | |
| fi | |
| # Push to the current branch (HEAD) explicitly | |
| git push origin HEAD:${{ github.ref_name }} |