Skip to content

.github/workflows/main.yml #578

.github/workflows/main.yml

.github/workflows/main.yml #578

Workflow file for this run

on:
schedule:
- cron: '0 10 * * *'
workflow_dispatch:
jobs:
update-index-html:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install jq to parse JSON
run: sudo apt install jq -y
- name: Get new data from API
run: |
DATE_MONTH_AGO=$(date -d "1 month ago" +"%F")
QUERY_MONTH_AGO=$(curl "http://apilayer.net/api/historical?access_key=$ACCESS_KEY&date=$DATE_MONTH_AGO&currencies=TRY&source=USD")
QUERY_CURRENT=$(curl "http://apilayer.net/api/live?access_key=$ACCESS_KEY&currencies=TRY&source=USD")
- name: Set the rate environment variables
run: |
RATE_MONTH_AGO=$(echo $QUERY_MONTH_AGO | jq .quotes.USDTRY)
RATE_CURRENT=$(echo $QUERY_CURRENT | jq .quotes.USDTRY )
- name: Update index.html
run: |
# easiest way to update the entire file
rm index.html
if [ "echo $RATE_CURRENT'<'$RATE_MONTH_AGO | bc -l" ]; then
cp hayir.html index.html
else
cp evet.html index.html
fi
DATE_TODAY=$(date +"%F")
# add date to line 49 (hacky solution)
# TODO: Use sed here with smt like s/DATE_TODAY/$DATE_TODAY
ex index.html <<eof
49 insert
$DATE_TODAY
.
xit
eof
- name: Push new index.html
run: |
git config user.name github-actions
git config user.email [email protected]
git add index.html
git commit -m "Auto generate"
git push