From 5cf6a8733d339f5ae4ba6f1e897ff92cf32263c8 Mon Sep 17 00:00:00 2001 From: Patrick Housley Date: Fri, 1 Dec 2023 15:36:22 -0600 Subject: [PATCH] chore: fix dry run automation --- .github/actions/s3-upload/args.js | 1 + .github/actions/update-current/args.js | 1 + .github/actions/update-current/index.js | 10 ++++++- .github/workflows/publish-internal.yml | 35 ++++++++++++++++++++++--- 4 files changed, 42 insertions(+), 5 deletions(-) diff --git a/.github/actions/s3-upload/args.js b/.github/actions/s3-upload/args.js index a83d41777..1d0d627b8 100644 --- a/.github/actions/s3-upload/args.js +++ b/.github/actions/s3-upload/args.js @@ -21,6 +21,7 @@ export const args = yargs(hideBin(process.argv)) .boolean('dry') .default('dry', false) .describe('dry', 'Runs the action script without actually uploading files.') + .alias('dry', 'dry-run') .string('dir') .describe('dir', 'Bucket sub-directory name. Leave empty to upload to the root of the bucket.') diff --git a/.github/actions/update-current/args.js b/.github/actions/update-current/args.js index 449cf6814..4b7624deb 100644 --- a/.github/actions/update-current/args.js +++ b/.github/actions/update-current/args.js @@ -21,6 +21,7 @@ export const args = yargs(hideBin(process.argv)) .boolean('dry') .default('dry', false) .describe('dry', 'Runs the action script without actually uploading files.') + .alias('dry', 'dry-run') .demandOption(['bucket', 'role', 'loader-version']) .argv diff --git a/.github/actions/update-current/index.js b/.github/actions/update-current/index.js index c17062d5b..b072b94f9 100644 --- a/.github/actions/update-current/index.js +++ b/.github/actions/update-current/index.js @@ -36,6 +36,14 @@ const results = await Promise.all( TaggingDirective: 'COPY' } + if (args.dry) { + console.log('running in dry mode, file not uploaded, params:', JSON.stringify({ + ...commandOpts, + Body: '[file stream]' + })) + return Promise.resolve() + } + const result = await s3Client.send(new CopyObjectCommand(commandOpts)) return ({ ...result, @@ -73,4 +81,4 @@ Output example: */ core.setOutput('results', JSON.stringify(results)) -console.log(`Successfully copied ${results.length} files in S3`) +console.log(`Successfully ${args.dry ? 'simulated' : ''} copy of ${results.length} files in S3`) diff --git a/.github/workflows/publish-internal.yml b/.github/workflows/publish-internal.yml index a98ec1c6f..8c4d3fd75 100644 --- a/.github/workflows/publish-internal.yml +++ b/.github/workflows/publish-internal.yml @@ -36,16 +36,43 @@ jobs: - uses: actions/setup-node@v3 with: node-version: lts/* + - name: Prepare target environment + id: target-environment + run: | + if [[ "${{ inputs.nr_environment }}" == "prod" ]]; then + echo "nrba_app_id=${{ secrets.INTERNAL_PRODUCTION_APPLICATION_ID }}" >> $GITHUB_OUTPUT + echo "nrba_license_key=${{ secrets.INTERNAL_LICENSE_KEY }}" >> $GITHUB_OUTPUT + echo "nrba_ab_app_id=" >> $GITHUB_OUTPUT + echo "nrba_ab_license_key=" >> $GITHUB_OUTPUT + elif [[ "${{ inputs.nr_environment }}" == "eu-prod" ]]; then + echo "nrba_app_id=${{ secrets.INTERNAL_EU_PRODUCTION_APPLICATION_ID }}" >> $GITHUB_OUTPUT + echo "nrba_license_key=${{ secrets.INTERNAL_LICENSE_KEY }}" >> $GITHUB_OUTPUT + echo "nrba_ab_app_id=" >> $GITHUB_OUTPUT + echo "nrba_ab_license_key=" >> $GITHUB_OUTPUT + elif [[ "${{ inputs.nr_environment }}" == "staging" ]]; then + echo "nrba_app_id=${{ secrets.INTERNAL_STAGING_APPLICATION_ID }}" >> $GITHUB_OUTPUT + echo "nrba_license_key=${{ secrets.INTERNAL_LICENSE_KEY }}" >> $GITHUB_OUTPUT + echo "nrba_ab_app_id=${{ secrets.INTERNAL_AB_STAGING_APPLICATION_ID }}" >> $GITHUB_OUTPUT + echo "nrba_ab_license_key=${{ secrets.INTERNAL_AB_LICENSE_KEY }}" >> $GITHUB_OUTPUT + elif [[ "${{ inputs.nr_environment }}" == "dev" ]]; then + echo "nrba_app_id=${{ secrets.INTERNAL_DEV_APPLICATION_ID }}" >> $GITHUB_OUTPUT + echo "nrba_license_key=${{ secrets.INTERNAL_LICENSE_KEY }}" >> $GITHUB_OUTPUT + echo "nrba_ab_app_id=${{ secrets.INTERNAL_AB_DEV_APPLICATION_ID }}" >> $GITHUB_OUTPUT + echo "nrba_ab_license_key=${{ secrets.INTERNAL_AB_LICENSE_KEY }}" >> $GITHUB_OUTPUT + else + echo "Invalid environment select" + exit 1 + fi - name: Deploy prod a/b script uses: ./.github/actions/internal-ab with: nr_environment: ${{ inputs.nr_environment }} nrba_released_script_url: ${{ inputs.nrba_released_script_url }} nrba_latest_script_url: ${{ inputs.nrba_latest_script_url }} - nrba_app_id: ${{ secrets.INTERNAL_PRODUCTION_APPLICATION_ID }} - nrba_license_key: ${{ secrets.INTERNAL_LICENSE_KEY }} - nrba_ab_app_id: ${{ secrets.INTERNAL_AB_DEV_APPLICATION_ID }} - nrba_ab_license_key: ${{ secrets.INTERNAL_AB_LICENSE_KEY }} + nrba_app_id: ${{ steps.target-environment.outputs.nrba_app_id }} + nrba_license_key: ${{ steps.target-environment.outputs.nrba_license_key }} + nrba_ab_app_id: ${{ steps.target-environment.outputs.nrba_ab_app_id }} + nrba_ab_license_key: ${{ steps.target-environment.outputs.nrba_ab_license_key }} aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }} aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} aws_role: ${{ secrets.AWS_ROLE_ARN }}