-
Notifications
You must be signed in to change notification settings - Fork 5
110 lines (95 loc) · 3.43 KB
/
daily_update.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
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