forked from jtquach1/installation-map
-
Notifications
You must be signed in to change notification settings - Fork 3
82 lines (80 loc) · 2.95 KB
/
update-waypoints.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
name: Update-Waypoints
# Run this workflow every hour
on:
workflow_dispatch:
schedule:
- cron: "0 9 * * *"
jobs:
create-json:
name: Creates or updates waypoints.json
runs-on: ubuntu-22.04
env:
DEFAULT_BRANCH: master
defaults:
run:
shell: bash
steps:
- name: Prepare environment
run: |
sudo apt-get --yes update
sudo apt-get --yes install python3-pip
sudo pip3 install --upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib
sudo pip3 install -U pip setuptools
sudo pip3 install -U googlemaps
# Checks out a copy of your repository on the ubuntu-latest machine
- name: Checkout code
uses: actions/checkout@v2
- name: Decrypt large secrets
run: ./.github/scripts/decrypt_secret.sh
env:
LARGE_SECRET_PASSPHRASE: ${{ secrets.LARGE_SECRET_PASSPHRASE }}
- name: Copy over decrypted secrets
run: |
cp $HOME/secrets/credentials.json .
cp $HOME/secrets/token.pickle .
- name: View current working directory
run: |
ls -ltra src/
- name: Check whether waypoints.json already exists
run: |
if ls src/waypoints.json; then
echo "already_exists=true" >> $GITHUB_ENV
cat src/waypoints.json
else
echo "already_exists=false" >> $GITHUB_ENV
fi
- name: Set environment variables and update waypoints.json
run: |
export SPREADSHEET_ID="$GOOGLE_SPREADSHEET_ID"
export GEOCODING_API_KEY="$GOOGLE_GEOCODING_API_KEY"
python3 update_waypoints.py
env:
GOOGLE_SPREADSHEET_ID: ${{ secrets.GOOGLE_SPREADSHEET_ID }}
GOOGLE_GEOCODING_API_KEY: ${{ secrets.GOOGLE_GEOCODING_API_KEY }}
- name: View current working directory and waypoints.json
run: |
ls -ltra src/
cat src/waypoints.json
cp src/waypoints.json public/static/waypoints.json
# Exit code of 0 means no changes, and 0 is true in the shell.
- name: Check for changes
run: |
if git diff --exit-code; then
echo "changes_exist=false" >> $GITHUB_ENV
else
echo "changes_exist=true" >> $GITHUB_ENV
fi
- name: Add and commit changes to waypoints.json
if: ${{ env.changes_exist == 'true' || env.already_exists == 'false' }}
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add src/waypoints.json
git add public/static/waypoints.json
git commit -m "Update waypoints.json with new rows"
- name: Push changes to repository
if: ${{ env.changes_exist == 'true' || env.already_exists == 'false' }}
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.ref }}