|
| 1 | +name: Update README from JSON |
| 2 | +# This workflow automatically updates the README file whenever the JSON file or the script changes. |
| 3 | +on: |
| 4 | + push: |
| 5 | + paths: |
| 6 | + - "awesome_open_geoscience.json" # JSON file in root directory |
| 7 | + - "scripts/json_to_readme.py" # Python script |
| 8 | + - "scripts/order.txt" # Order file |
| 9 | + - "media/**" # Anything in 'media' folder |
| 10 | + workflow_dispatch: # Allows manual triggering in GitHub Actions UI |
| 11 | + schedule: |
| 12 | + - cron: "0 0 * * 0" # Weekly on Sundays at midnight UTC |
| 13 | + |
| 14 | +jobs: |
| 15 | + update-readme: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + # Grant write permissions to the GITHUB_TOKEN |
| 18 | + permissions: |
| 19 | + contents: write |
| 20 | + steps: |
| 21 | + - name: Checkout repository |
| 22 | + uses: actions/checkout@v4 |
| 23 | + with: |
| 24 | + fetch-depth: 0 |
| 25 | + |
| 26 | + - name: Set up Python |
| 27 | + uses: actions/setup-python@v4 |
| 28 | + with: |
| 29 | + python-version: "3.10" |
| 30 | + |
| 31 | + - name: Install dependencies |
| 32 | + run: pip install pyyaml |
| 33 | + |
| 34 | + - name: Generate README |
| 35 | + run: python scripts/json_to_readme.py awesome_open_geoscience.json scripts/order.txt |
| 36 | + |
| 37 | + - name: Check for changes |
| 38 | + id: git-check |
| 39 | + run: | |
| 40 | + git diff --quiet README.md || echo "changes=true" >> $GITHUB_OUTPUT |
| 41 | +
|
| 42 | + - name: Commit and push changes |
| 43 | + if: steps.git-check.outputs.changes == 'true' |
| 44 | + run: | |
| 45 | + git config --global user.name "github-actions[bot]" |
| 46 | + git config --global user.email "github-actions[bot]@users.noreply.github.com" |
| 47 | + git add README.md |
| 48 | + git commit -m "Auto-update README from JSON [skip ci]" || echo "No changes to commit" |
| 49 | + # Use GITHUB_TOKEN for authentication |
| 50 | + git push "https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git" HEAD:main |
0 commit comments