Daily Data Update #179
This file contains 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: Daily Data Update | |
on: | |
schedule: | |
- cron: "0 0 * * *" | |
workflow_dispatch: | |
inputs: | |
debug_enabled: | |
type: boolean | |
description: 'Run the build with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)' | |
required: false | |
default: false | |
force_update: | |
type: boolean | |
description: 'Force update the data even if there are no changes' | |
required: false | |
default: false | |
permissions: | |
contents: write | |
jobs: | |
update_data: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.11' | |
- name: Install Dependencies | |
run: | | |
pip install bonbast jdatetime | |
- name: Install Proxy | |
if: github.repository == 'SamadiPour/rial-exchange-rates-archive' | |
run: | | |
sudo snap install opera-proxy | |
opera-proxy -country EU >/dev/null 2>&1 & | |
sleep 10 | |
- name: Run get_next.py and aggregator.py | |
if: github.repository == 'SamadiPour/rial-exchange-rates-archive' | |
run: | | |
export http_proxy="http://127.0.0.1:18080" | |
export https_proxy="http://127.0.0.1:18080" | |
python get_next.py | |
python aggregator.py | |
- name: Setup tmate session | |
if: ${{ github.event_name == 'workflow_dispatch' && inputs.debug_enabled }} | |
uses: mxschmitt/action-tmate@v3 | |
- name: Check if there are any changes | |
id: verify_diff | |
run: | | |
git diff --quiet . || echo "changed=true" >> $GITHUB_OUTPUT | |
- name: Commit and Push Changes | |
if: steps.verify_diff.outputs.changed == 'true' | |
run: | | |
git config --local user.email "action@github.com" | |
git config --local user.name "GitHub Action" | |
git add gregorian/* jalali/* | |
git commit -m "Update data - $(date +'%Y/%m/%d')" | |
git push | |
- name: Generate artifacts | |
if: steps.verify_diff.outputs.changed == 'true' || inputs.force_update | |
run: | | |
echo "TAG_NAME=$(date +%Y%m%d%H%M)" >> $GITHUB_ENV | |
echo "RELEASE_NAME=$(date +%Y%m%d%H%M)" >> $GITHUB_ENV | |
python artifact_generator.py | |
- name: Upload result as release | |
if: steps.verify_diff.outputs.changed == 'true' || inputs.force_update | |
uses: ncipollo/release-action@v1 | |
with: | |
artifacts: "artifact/*.*" | |
token: ${{ secrets.GITHUB_TOKEN }} | |
tag: ${{ env.TAG_NAME }} | |
name: ${{ env.RELEASE_NAME }} | |
- name: Delete old releases | |
if: steps.verify_diff.outputs.changed == 'true' || inputs.force_update | |
uses: dev-drprasad/delete-older-releases@v0.3.2 | |
with: | |
keep_latest: 10 | |
delete_tags: true | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Push artifacts to data branch | |
if: steps.verify_diff.outputs.changed == 'true' || inputs.force_update | |
run: | | |
mv artifact/ ../ | |
git config --local user.email "action@github.com" | |
git config --local user.name "GitHub Action" | |
git fetch origin | |
git push origin --delete data || true | |
git checkout --orphan data | |
git reset --hard | |
cp -r ../artifact/* . | |
git add . | |
git commit -m "Generate and update data" | |
git push origin data |