.github/workflows/main.yml #574
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
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¤cies=TRY&source=USD") | |
QUERY_CURRENT=$(curl "http://apilayer.net/api/live?access_key=$ACCESS_KEY¤cies=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 |