Skip to content

Run R Script Monthly #27

Run R Script Monthly

Run R Script Monthly #27

Workflow file for this run

name: Run R Script Monthly
on:
schedule:
- cron: '0 0 1 * *' # Runs at midnight on the first day of every month
workflow_dispatch: # Allows manual trigger
env:
IMAGE_NAME: ghcr.io/sensingclues/rocker_shiny_custom:latest # Your GHCR Docker image
SCRIPT_PATH: ./automation.R # Path to your R script in the repository
OUTPUT_DIR: /deploy/risk-map # Path on the server to store the CSV output
jobs:
run-script:
runs-on: self-hosted # Ensure this runs on your self-hosted runner
environment: prod
steps:
- name: Checkout Repository
uses: actions/checkout@v3 # Ensures we have access to automation.R
- name: Set Deployment Path
run: echo "OUTPUT_DIR=/deploy/risk-map" >> $GITHUB_ENV
- name: Debug Environment Variables
run: |
echo "OUTPUT_DIR is: '$OUTPUT_DIR'"
ls -ld "$OUTPUT_DIR" || echo "Directory does not exist"
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Pull the Docker Image
run: |
docker pull ${{ env.IMAGE_NAME }}
- name: Run R Script in Docker
env:
SENSINGCLUES_USERNAME: ${{ secrets.SCA_USERNAME }}
SENSINGCLUES_PASSWORD: ${{ secrets.SCA_PASSWORD }}
run: |
sudo mkdir -p $OUTPUT_DIR
docker run --rm \
-e SENSINGCLUES_USERNAME="${{ secrets.SCA_USERNAME }}" \
-e SENSINGCLUES_PASSWORD="${{ secrets.SCA_PASSWORD }}" \
-v "${{ github.workspace }}/automation.R:/app/automation.R" \
-v "${{ env.OUTPUT_DIR }}:/output" \
${{ env.IMAGE_NAME }} Rscript /app/automation.R
- name: Verify Output
run: |
echo "Checking if CSV file was generated..."
ls -lh "$OUTPUT_DIR" || echo "No CSV files found!"
- name: Move CSV Output to Deployment Path
run: |
sudo mv "$OUTPUT_DIR"/charcoal_observations_*.csv "$OUTPUT_DIR"/ || echo "No files to move"
echo "CSV output saved in $OUTPUT_DIR"