Skip to content

buildvespaPiemonte #655

buildvespaPiemonte

buildvespaPiemonte #655

on:
push:
branches: [master]
schedule:
- cron: '30 4 * * *'
# - cron: '30 19 * * *'
release:
types: [published]
workflow_dispatch:
name: buildvespaPiemonte
jobs:
build-website:
runs-on: ubuntu-latest
env:
# GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
GOOGLE_APPLICATION_CREDENTIALS: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}
QFIELD_CLOUD_PASSWORD: ${{ secrets.QFIELD_CLOUD_PASSWORD }}
QFIELD_CLOUD_USERNAME: ${{ secrets.QFIELD_CLOUD_USERNAME }}
QFIELD_CLOUD_PROJECTNAME: ${{ secrets.QFIELD_CLOUD_PROJECTNAME }}
concurrency:
group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }}
permissions:
contents: write
steps:
- name: "Check out repository"
uses: actions/checkout@v4
- name: Install dependencies on Linux
if: runner.os == 'Linux'
run: sudo apt-get update -y && sudo apt-get install -y libproj-dev libgdal-dev libgeos-dev libudunits2-dev language-pack-it
- name: "Setup R"
uses: r-lib/actions/setup-r@v2
- name: Install R Dependencies
uses: r-lib/actions/setup-renv@v2
- name: Ensure cache directory exists
run: mkdir -p cache
- name: Ensure cache/pubdata directory exists
run: mkdir -p cache/pubdata
- name: Check if today is Sunday
id: check-sunday
run: |
day_of_week=$(date +%u)
if [ "$day_of_week" -eq 7 ]; then
echo "is_sunday=true" >> $GITHUB_ENV
else
echo "is_sunday=false" >> $GITHUB_ENV
fi
- name: Cache built data
id: cache-data-all
uses: actions/cache@v2
with:
path: cache
key: build-data-${{ hashFiles('cache/**/*') }}
restore-keys: |
build-data-
- name: Cache data
id: cache-data
uses: actions/cache@v2
with:
path: cache
key: shapefile-${{ runner.os }}-${{ env.is_sunday }}
restore-keys: |
shapefile-
- name: Download shapefile if needed
if: env.is_sunday == 'true'
run: |
curl -L -o cache/pubdata/AMBITI_AMMINISTRATIVI_COMUNI1.zip "https://www.datigeo-piem-download.it/direct/Geoportale/RegionePiemonte/Limiti_amministrativi/AMBITI_AMMINISTRATIVI_COMUNI1.zip"
echo "Downloaded new file"
#
# - name: Check if cache was hit
# id: check-cache
# run: |
# if [ -f "cache/pubdata/AMBITI_AMMINISTRATIVI_COMUNI1.zip" ]; then
# local_hash=$(md5sum cache/pubdata/AMBITI_AMMINISTRATIVI_COMUNI1.zip | awk '{print $1}')
# echo "local_hash=$local_hash"
# echo "local_hash=$local_hash" >> $GITHUB_ENV
# if [ "$local_hash" = "$remote_hash" ]; then
# echo "Cache hit, file is up to date"
# echo "cache_hit=true" >> $GITHUB_ENV
# else
# echo "Cache miss, file is outdated"
# echo "cache_hit=false" >> $GITHUB_ENV
# fi
# else
# echo "Cache miss, file does not exist"
# echo "cache_hit=false" >> $GITHUB_ENV
# fi
#
# - name: Debug cache hit
# run: echo "cache_hit=$cache_hit"
#
# - name: Download shapefile if needed
# if: env.cache_hit != 'true'
# run: |
# curl -L -o cache/pubdata/AMBITI_AMMINISTRATIVI_COMUNI1.zip "https://www.datigeo-piem-download.it/direct/Geoportale/RegionePiemonte/Limiti_amministrativi/AMBITI_AMMINISTRATIVI_COMUNI1.zip"
# echo "Downloaded new file"
#
- name: Cache downloaded file
uses: actions/cache@v2
with:
path: cache/pubdata/AMBITI_AMMINISTRATIVI_COMUNI1.zip
key: shapefile-${{ env.remote_hash }}
restore-keys: |
shapefile-
- name: Check if cache was hit
run: |
if [ -f "cache/nidi.rds" ] && [ -f "cache/trap.rds" ]; then
echo "Cache hit, data files exist"
else
echo "Cache miss, data files do not exist"
fi
- name: Check and update geographical data
run: |
Rscript scripts/start_script_v2.R
- name: Cache updated data
uses: actions/cache@v2
with:
path: cache
key: build-data-${{ hashFiles('cache/**/*') }}
# - name: Other calculations
# run: Rscript -e 'source("scripts/complete_script_v2.R")'
- name: "Set up Quarto"
uses: quarto-dev/quarto-actions/setup@v2
- name: "Render and Publish"
uses: quarto-dev/quarto-actions/publish@v2
with:
target: gh-pages
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}