Update-Waypoints #24911
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: 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 }} |