manage.get.gov/.github/workflows/daily-csv-upload.yaml
2023-11-24 11:30:12 -07:00

109 lines
3.5 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 do you wish 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]
steps:
- uses: actions/checkout@v3
- name: Install CF CLI
run: |
curl -L "https://packages.cloudfoundry.org/stable?release=linux64-binary&source=github" | tar -zx
sudo mv cf /usr/local/bin
- name: Set login credentials
run: |
cf api https://api.fr.cloud.gov
cf auth ${{ secrets[env.CF_USERNAME] }} ${{ secrets[env.CF_PASSWORD] }}
cf target -o cisa-dotgov -s ${{ env.ENVIRONMENT }}
env:
ENVIRONMENT: ${{ needs.variables.outputs.environment }}
CF_USERNAME: CF_${{ needs.variables.outputs.environment }}_USERNAME
CF_PASSWORD: CF_${{ needs.variables.outputs.environment }}_PASSWORD
- name: Generate current-federal.csv
run: |
cf ssh getgov-${{ env.ENVIRONMENT }}
/tmp/lifecycle/shell
./manage.py generate_current_federal_report
env:
ENVIRONMENT: ${{ needs.variables.outputs.environment }}
- name: Generate current-full.csv
run: cf run-task getgov-${{ env.ENVIRONMENT }} "/tmp/lifecycle/shell -c './manage.py generate_current_full_report'"
env:
ENVIRONMENT: ${{ needs.variables.outputs.environment }}
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/)**.'
})