Skip to content

Commit

Permalink
Make the whole workflow dry-runnable
Browse files Browse the repository at this point in the history
  • Loading branch information
fingerartur committed Nov 28, 2023
1 parent e282c72 commit 9d94e8f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 6 deletions.
17 changes: 17 additions & 0 deletions .github/actions/upload-to-s3/action.yml
Original file line number Diff line number Diff line change
@@ -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'
21 changes: 21 additions & 0 deletions .github/actions/upload-to-s3/main.js
Original file line number Diff line number Diff line change
@@ -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.
14 changes: 8 additions & 6 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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: |
Expand Down

0 comments on commit 9d94e8f

Please sign in to comment.