manage.get.gov/.github/workflows/daily-csv-upload.yaml
zandercymatics ff4773f8c7
Test command
2023-11-22 12:51:03 -07:00

99 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:
schedule:
# Runs every day at 5 AM UTC
# TODO: - cron: '0 5 * * *'
- cron: '*/2 * * * *'
jobs:
variables:
if: |
startsWith(github.head_ref, 'ab/')
|| startsWith(github.head_ref, 'bl/')
|| startsWith(github.head_ref, 'rjm/')
|| startsWith(github.head_ref, 'rb/')
|| startsWith(github.head_ref, 'ko/')
|| startsWith(github.head_ref, 'gd/')
|| startsWith(github.head_ref, 'za/')
|| startsWith(github.head_ref, 'rh/')
|| startsWith(github.head_ref, 'nl/')
|| startsWith(github.head_ref, 'dk/')
|| startsWith(github.head_ref, 'es/')
|| startsWith(github.head_ref, 'ky/')
outputs:
environment: ${{ steps.var.outputs.environment}}
runs-on: "ubuntu-latest"
steps:
- name: Setting global variables
uses: actions/github-script@v6
id: var
with:
script: |
core.setOutput('environment', '${{ github.head_ref }}'.split("/")[0]);
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 run-task getgov-${{ env.ENVIRONMENT }} --wait --command "python manage.py generate_current_full_report.py --name current_full"
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_federal_report.py'"
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 CSVs to **[${{ env.ENVIRONMENT }}](https://getgov-${{ env.ENVIRONMENT }}.app.cloud.gov/)**.'
})