Download and Commit Files #91
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: Download and Commit Files | |
on: | |
schedule: | |
- cron: "0 19 * * *" # every day at 00:00 UTC | |
permissions: | |
contents: write # grant the workflow permission to push commits | |
jobs: | |
download_and_commit: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
with: | |
# Use a PAT if you need cross-repo access, otherwise GITHUB_TOKEN is fine | |
token: ${{ secrets.GH_PAT }} | |
# fetch full history so we can pull and push | |
fetch-depth: 0 | |
- name: Clean resources folder | |
run: | | |
mkdir -p resources | |
rm -rf resources/* | |
- name: Download CSV file | |
run: | | |
curl -o resources/bad_words.csv "${{ secrets.CSV_FILE_URL }}" | |
if [ ! -s resources/bad_words.csv ]; then | |
echo "CSV file download failed!" >&2 | |
exit 1 | |
fi | |
- name: Download JSON file | |
run: | | |
curl -o resources/bad_words.json "${{ secrets.JSON_FILE_URL }}" | |
if [ ! -s resources/bad_words.json ]; then | |
echo "JSON file download failed!" >&2 | |
exit 1 | |
fi | |
- name: Download XLSX file | |
run: | | |
curl -o resources/bad_words.xlsx "${{ secrets.XLSX_FILE_URL }}" | |
if [ ! -s resources/bad_words.xlsx ]; then | |
echo "XLSX file download failed!" >&2 | |
exit 1 | |
fi | |
- name: Configure Git user | |
run: | | |
git config user.name "GitHub Actions Bot" | |
git config user.email "actions@github.com" | |
- name: Commit & push changes | |
run: | | |
git add resources/ | |
# if nothing to commit, exit zero | |
if git diff --cached --quiet; then | |
echo "No changes to commit." | |
else | |
git commit -m "Auto‑update: $(date --utc +'%Y-%m-%d %H:%M:%S') UTC" | |
git push origin HEAD:main | |
fi | |
env: | |
# ensure your token has write:packages, contents, etc. | |
GITHUB_TOKEN: ${{ secrets.GH_PAT }} |