Repository navigation
App Usage Report #131
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: App Usage Report | |
| on: | |
| push: | |
| branches: | |
| - main | |
| schedule: | |
| - cron: '0 0 * * 1' # Run weekly on Mondays at midnight | |
| workflow_dispatch: # Allow manual triggering | |
| env: | |
| # MongoDB Connection | |
| MONGODB_CONNECTION_STRING_TRACKS: ${{ secrets.MONGODB_CONNECTION_STRING_TRACKS }} | |
| # Google Cloud Platform (for authentication if needed) | |
| GCP_SA_KEY: ${{ secrets.GCP_SA_KEY }} | |
| jobs: | |
| build-container: | |
| name: Build R container | |
| if: github.ref == 'refs/heads/main' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v6 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v4 | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v4 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v7 | |
| with: | |
| context: . | |
| file: Dockerfile.prod | |
| push: true | |
| tags: ghcr.io/worldfishcenter/peskas.coasts/r-runner-peskas-coasts:latest | |
| cache-from: type=registry,ref=ghcr.io/worldfishcenter/peskas.coasts/r-runner-peskas-coasts:buildcache | |
| cache-to: type=registry,ref=ghcr.io/worldfishcenter/peskas.coasts/r-runner-peskas-coasts:buildcache,mode=max | |
| generate-report: | |
| name: Generate App Usage Report | |
| needs: build-container | |
| if: github.ref == 'refs/heads/main' | |
| runs-on: ubuntu-latest | |
| container: | |
| image: ghcr.io/worldfishcenter/peskas.coasts/r-runner-peskas-coasts:latest | |
| credentials: | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| steps: | |
| - name: Set env to production | |
| if: endsWith(github.ref, '/main') | |
| run: echo "R_CONFIG_ACTIVE=production" >> $GITHUB_ENV | |
| - name: Generate and upload app usage report | |
| run: | | |
| Rscript -e ' | |
| conf <- coasts::read_config() | |
| # Generate report | |
| report_file <- coasts::generate_app_usage_report( | |
| conf = conf, | |
| output_file = "app_usage_report.html", | |
| countries = c("Kenya", "Zanzibar", "Mozambique"), | |
| top_n = 50 | |
| ) | |
| # Upload to Google Cloud Storage | |
| coasts::upload_cloud_file( | |
| file = report_file, | |
| name = "reports/app_usage_report.html", | |
| provider = conf$storage$google$key, | |
| options = conf$storage$google$options | |
| ) | |
| message("Report uploaded to Google Cloud Storage") | |
| ' | |
| - name: Upload report artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: app-usage-report-${{ github.run_number }} | |
| path: app_usage_report.html | |
| retention-days: 90 |