From 9d94e8f2115d1d8b69038204cf74382a7bd10e82 Mon Sep 17 00:00:00 2001 From: Artur Finger Date: Tue, 28 Nov 2023 15:53:46 +0200 Subject: [PATCH] Make the whole workflow dry-runnable --- .github/actions/upload-to-s3/action.yml | 17 +++++++++++++++++ .github/actions/upload-to-s3/main.js | 21 +++++++++++++++++++++ .github/workflows/publish.yml | 14 ++++++++------ 3 files changed, 46 insertions(+), 6 deletions(-) create mode 100644 .github/actions/upload-to-s3/action.yml create mode 100644 .github/actions/upload-to-s3/main.js diff --git a/.github/actions/upload-to-s3/action.yml b/.github/actions/upload-to-s3/action.yml new file mode 100644 index 0000000..3d6b526 --- /dev/null +++ b/.github/actions/upload-to-s3/action.yml @@ -0,0 +1,17 @@ +name: 'Upload to S3' +description: 'Upload the contents of a directory to an S3 bucket' + +inputs: + directory: + description: Directory to upload + required: true + destination: + description: S3 destination path URI + required: true + dry-run: + description: If true, run the commands but don't actually upload + required: false + +runs: + using: 'node20' + main: './main.js' diff --git a/.github/actions/upload-to-s3/main.js b/.github/actions/upload-to-s3/main.js new file mode 100644 index 0000000..e2a531d --- /dev/null +++ b/.github/actions/upload-to-s3/main.js @@ -0,0 +1,21 @@ +const execSync = require('child_process').execSync +const core = require('@actions/core') + +/** + * @fileoverview Upload a directory to S3. + */ + +const directory = core.getInput('directory', {required: true}) +const destination = core.getInput('destination', {required: true}) +const dryRun = core.getBooleanInput('dry-run') + +const args = ['--recursive'] +if (dryRun) { + args.push('--dryrun') +} + +core.info(`Uploading ${directory} to S3.`) +execSync(`aws s3 cp ${args.join(' ')} "${directory}" "${destination}"`, { stdio: 'inherit' }) +// Note: the default cache policy is 1 day, I think that's OK for now. +// In the future if traffic increases we can increase the expiration +// as much as we want. diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index d2391ff..0efe8d0 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -7,6 +7,7 @@ on: env: VERSION: ${{ github.event.release.tag_name }} WEB_PATH: "react-dom/${{ github.event.release.tag_name }}/docs/" + DRY_RUN: false permissions: contents: read # Permission for actions/checkout @@ -45,11 +46,12 @@ jobs: role-to-assume: ${{ secrets.AWS_UPLOADER_ROLE_PLAYERS }} aws-region: us-east-1 - - name: Upload to S3 - run: aws s3 cp --recursive "./dist/storybook" "${{ secrets.AWS_WEB_BUCKET }}/${{ env.WEB_PATH }}" - # Note: the default cache policy is 1 day, I think that's OK for now. - # In the future if traffic increases we can increase the expiration - # as much as we want. + - name: Publish to NPM + uses: ./.github/actions/upload-to-s3 + with: + directory: "./dist/storybook" + destination: "${{ secrets.AWS_WEB_BUCKET }}/${{ env.WEB_PATH }}" + dry-run: ${{ env.DRY_RUN }} ## Publish the NPM package @@ -61,7 +63,7 @@ jobs: with: version: ${{ env.VERSION }} npm-token: ${{ secrets.CLPLAYERS_NPM_TOKEN_RW }} - dry-run: false + dry-run: ${{ env.DRY_RUN }} - name: Add Job summary run: |