manage.get.gov/.github/workflows/daily-csv-upload.yaml
2023-11-24 13:09:51 -07:00

101 lines
3.3 KiB
YAML

name: Upload current-full.csv and current-federal.csv
run-name: Upload current-full.csv and current-federal.csv for branch ${{ github.head_ref }}
on:
pull_request:
workflow_dispatch:
inputs:
environment:
type: choice
description: Which environment load reports for?
options:
- stable
- staging
- development
- ky
- es
- nl
- rh
- za
- gd
- rb
- ko
- ab
- bl
- rjm
- dk
schedule:
# Runs every day at 5 AM UTC.
- cron: "0 5 * * *"
jobs:
variables:
outputs:
environment: ${{ steps.var.outputs.environment }}
runs-on: "ubuntu-latest"
steps:
- name: Setting global variables
uses: actions/github-script@v6
id: var
with:
script: |
const environment = (github && github.event && github.event.inputs) ? github.event.inputs.environment : 'za';
core.setOutput('environment', environment);
wait-for-deploy:
runs-on: ubuntu-latest
steps:
- name: Wait for deploy to complete
uses: fountainhead/action-wait-for-check@v1.0.0
id: wait-for-deploy
with:
token: ${{ secrets.GITHUB_TOKEN }}
checkName: "deploy"
ref: ${{ github.event.pull_request.head.sha }}
# the maximum time to wait for the check to complete, in seconds
timeoutSeconds: 600
# the time to wait between checks, in seconds
intervalSeconds: 10
upload-reports:
runs-on: ubuntu-latest
needs: [variables, wait-for-deploy]
env:
CF_USERNAME: CF_ZA_USERNAME
CF_PASSWORD: CF_ZA_PASSWORD
steps:
- name: Generate current-federal.csv
uses: 18f/cg-deploy-action@main
with:
cf_username: ${{ secrets[env.CF_USERNAME] }}
cf_password: ${{ secrets[env.CF_PASSWORD] }}
cf_org: cisa-dotgov
cf_space: ${{ needs.variables.outputs.environment }}
full_command: "cf run-task getgov-${{ needs.variables.outputs.environment }} --command 'python manage.py generate_current_federal_report' --name federal"
- name: Generate current-full.csv
uses: 18f/cg-deploy-action@main
with:
cf_username: ${{ secrets[env.CF_USERNAME] }}
cf_password: ${{ secrets[env.CF_PASSWORD] }}
cf_org: cisa-dotgov
cf_space: ${{ needs.variables.outputs.environment }}
full_command: "cf run-task getgov-${{ needs.variables.outputs.environment }} --command 'python manage.py generate_current_full_report' --name full"
comment:
runs-on: ubuntu-latest
needs: [variables, upload-reports]
steps:
- uses: actions/github-script@v6
env:
ENVIRONMENT: ${{ needs.variables.outputs.environment }}
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '🥳 Successfully uploaded current-full.csv and current-federal.csv to **[${{ env.ENVIRONMENT }}](https://getgov-${{ env.ENVIRONMENT }}.app.cloud.gov/)**.'
})