Run R Script Monthly #9
This file contains hidden or 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: 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: 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 \ # Mount script | |
| -v $OUTPUT_DIR:/output \ # Mount output directory | |
| ${{ env.IMAGE_NAME }} \ | |
| Rscript /app/automation.R # Execute script inside container | |
| - name: Verify Output | |
| run: ls -l $OUTPUT_DIR | |
| - name: Commit and Push CSV File to Repo (Optional) | |
| run: | | |
| cd $OUTPUT_DIR | |
| git config --global user.name "github-actions" | |
| git config --global user.email "github-actions@github.com" | |
| git add charcoal_observations_*.csv || echo "No new files to commit" | |
| git diff --cached --exit-code || git commit -m "Add monthly charcoal observations" | |
| git push || echo "No changes to push" |