CI Build #1916
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: CI Build | |
on: | |
schedule: | |
- cron: 0 12 * * * | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v1 | |
- name: Run a one-line script | |
run: pwd | |
- name: Run a multi-line script | |
run: | | |
ls | |
git status | |
- name: Save current weather condition | |
env: | |
API_KEY: ${{ secrets.API_KEY }} | |
run: | | |
FILE=./docs/assets/data/`date +"%Y%m%d"`.json | |
if [ -f "$FILE" ]; then | |
echo "$FILE exists. Done for today." | |
else | |
echo "Begin to get today's weather condition." | |
url="http://api.openweathermap.org/data/2.5/weather?id=4862034&units=metric&APPID="$API_KEY | |
response=$(curl -f "$url") | |
status=$? | |
if [ $status -eq 0 ]; then | |
echo $response > $FILE | |
echo "$FILE saved." | |
echo `date +"%Y%m%d"` >> ./docs/assets/data.txt | |
else | |
echo "curl exit code: ($status) $response" | |
exit $status | |
fi | |
fi | |
- name: git check in | |
env: | |
GIT_OWNER_EMAIL: ${{ secrets.GIT_OWNER_EMAIL }} | |
PUSH_TOKEN: ${{ secrets.PUSH_TOKEN }} | |
run: | | |
git config user.email "$GIT_OWNER_EMAIL" | |
git config user.name "changhuixu" | |
if [[ `git status --porcelain` ]]; then | |
git add . | |
git commit -a -m "add weather data" | |
git remote rm origin | |
git remote add origin https://changhuixu:$PUSH_TOKEN@github.com/changhuixu/historical-weather-data.git | |
git push origin HEAD:master | |
else | |
echo 'unable to detech changes' | |
fi |