From f40e71ca8b8fd966b4658b5c7cbbada2b214f6de Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Mon, 27 Nov 2023 12:41:26 -0700 Subject: [PATCH] Script cleanup / prepare for PR --- .github/workflows/daily-csv-upload.yaml | 49 +++---------------- src/api/views.py | 1 + .../generate_current_federal_report.py | 5 +- .../commands/generate_current_full_report.py | 5 +- 4 files changed, 11 insertions(+), 49 deletions(-) diff --git a/.github/workflows/daily-csv-upload.yaml b/.github/workflows/daily-csv-upload.yaml index 2772e51ac..cb2467319 100644 --- a/.github/workflows/daily-csv-upload.yaml +++ b/.github/workflows/daily-csv-upload.yaml @@ -7,7 +7,7 @@ on: inputs: environment: type: choice - description: Which environment load reports for? + description: Which environment do you wish to load reports for? options: - stable - staging @@ -24,9 +24,10 @@ on: - bl - rjm - dk - schedule: + # TODO - uncomment after #1403 is finished + #schedule: # Runs every day at 5 AM UTC. - - cron: "0 5 * * *" + # - cron: "0 5 * * *" jobs: variables: @@ -42,31 +43,13 @@ jobs: 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] + needs: [variables] env: - CF_USERNAME: CF_ZA_USERNAME - CF_PASSWORD: CF_ZA_PASSWORD + CF_USERNAME: CF_{{ needs.variables.outputs.environment }}_USERNAME + CF_PASSWORD: CF_{{ needs.variables.outputs.environment }}_PASSWORD steps: - - name: Wait for a few seconds - run: sleep 20 - - name: Generate current-federal.csv uses: 18f/cg-deploy-action@main with: @@ -84,20 +67,4 @@ jobs: 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/)**.' - }) + diff --git a/src/api/views.py b/src/api/views.py index 55c506b3f..9bf0cf95f 100644 --- a/src/api/views.py +++ b/src/api/views.py @@ -107,6 +107,7 @@ def get_current_federal(request): def serve_file(file_path): """Downloads a file based on a given filepath. Returns a 404 if not found.""" + # TODO - #1403, grab from the S3 instance instead if os.path.exists(file_path): # Serve the CSV file response = FileResponse(open(file_path, "rb")) diff --git a/src/registrar/management/commands/generate_current_federal_report.py b/src/registrar/management/commands/generate_current_federal_report.py index 1a013603e..237f00681 100644 --- a/src/registrar/management/commands/generate_current_federal_report.py +++ b/src/registrar/management/commands/generate_current_federal_report.py @@ -21,15 +21,12 @@ class Command(BaseCommand): directory = os.path.join(options.get("directory"), "") logger.info("Generating report...") - # TODO - Delete - current_directory = os.getcwd() - logger.info(f"Current working directory: {current_directory}") - self.generate_current_federal_report(directory) logger.info(f"Success! Created {directory}current-federal.csv") def generate_current_federal_report(self, directory): """Creates a current-full.csv file under the migrationdata/ directory""" + # TODO - #1403, push to the S3 instance instead file_path = os.path.join(directory, "current-federal.csv") with open(file_path, "w") as file: csv_export.export_data_federal_to_csv(file) diff --git a/src/registrar/management/commands/generate_current_full_report.py b/src/registrar/management/commands/generate_current_full_report.py index 838e2d40d..b6915c397 100644 --- a/src/registrar/management/commands/generate_current_full_report.py +++ b/src/registrar/management/commands/generate_current_full_report.py @@ -21,15 +21,12 @@ class Command(BaseCommand): directory = os.path.join(options.get("directory"), "") logger.info("Generating report...") - # TODO - Delete - current_directory = os.getcwd() - logger.info(f"Current working directory: {current_directory}") - self.generate_current_full_report(directory) logger.info(f"Success! Created {directory}current-full.csv") def generate_current_full_report(self, directory): """Creates a current-full.csv file under the migrationdata/ directory""" + # TODO - #1403, push to the S3 instance instead file_path = os.path.join(directory, "current-full.csv") with open(file_path, "w") as file: csv_export.export_data_full_to_csv(file)