Export MongoDB Collections #32
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: Export MongoDB Collections | |
| on: | |
| schedule: | |
| - cron: '0 0 * * *' # Runs every day at midnight UTC | |
| workflow_dispatch: # Allows manual triggering of the workflow | |
| jobs: | |
| export: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v2 | |
| - name: Set up MongoDB tools | |
| run: | | |
| wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add - | |
| echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list | |
| sudo apt-get update | |
| sudo apt-get install -y mongodb-org-tools | |
| - name: Export MongoDB collections | |
| env: | |
| MONGO_URI: ${{ secrets.MONGO_URI }} # Set this secret in your repository settings | |
| run: | | |
| mkdir -p gendercomics | |
| mongoexport --uri="$MONGO_URI" --collection=comics --out=gendercomics/comics.json | |
| mongoexport --uri="$MONGO_URI" --collection=keywords --out=gendercomics/keywords.json | |
| mongoexport --uri="$MONGO_URI" --collection=names --out=gendercomics/names.json | |
| mongoexport --uri="$MONGO_URI" --collection=persons --out=gendercomics/persons.json | |
| mongoexport --uri="$MONGO_URI" --collection=predicates --out=gendercomics/predicates.json | |
| mongoexport --uri="$MONGO_URI" --collection=publishers --out=gendercomics/publishers.json | |
| mongoexport --uri="$MONGO_URI" --collection=roles --out=gendercomics/roles.json | |
| mongoexport --uri="$MONGO_URI" --collection=texts --out=gendercomics/texts.json | |
| - name: Configure git | |
| run: | | |
| git config --global user.name 'github-actions[bot]' | |
| git config --global user.email 'github-actions[bot]@users.noreply.github.com' | |
| - name: Check for changes | |
| id: git_diff | |
| run: | | |
| git add gendercomics/*.json | |
| git diff-index --quiet HEAD || echo "changes" | |
| - name: Commit and push changes | |
| if: steps.git_diff.outputs.changes == 'changes' | |
| run: | | |
| git commit -m "Export MongoDB collections as JSON files" | |
| git push | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Automatically provided by GitHub Actions |