Skip to content

Do you need something like unpkg.com but hosted on your own S3 account? This action will build and upload your code to S3 using the package@latest or package@1.2.3 approach just like unpkg.

License

Foxy/foxy-github-action-s3cdn

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

S3CDN: An unpkg clone using S3 and CloudFront

This action runs when tags are created, and will upload your code to an S3 bucket to multiple directories for @latest and @major, @major.minor and @major.minor.patch, for access similar to how unpkg.com works. For example, for first release, for release version v1.2.3-beta.1 the dist content will be uploaded to 1, 1.2, 1.2.3-beta.1 directores.

In general, 4 new directories will be created or updated in S3 for latest and the different versions. Though it's possible in S3 to do some redirects (which could in theory reduce the number of folders and files created), there are limitations there, and S3 storage space for things like npm packages should generally be very negligible.

Note that it doesn't allow for tilde (~) or caret (^) ranges, nor for asterisks (*), though as with unpkg.com, you you can get the latest of any major or minor release by simply not including the minor or patch version, such as package@1 (which will serve the latest 1.x.x release) or package@1.1 (which will serve the latest 1.1.x release). Unlike unpkg, which redirects, it will serve the files in the corresponding directories in S3.

This package relies on your tags using semantic versioning.

We'd recommend putting CloudFront in front of your S3 bucket, but that's up to you.

Usages

Create workflow YAML file in .github/workflows/ directory of your app.

Go to Project's settings in GitHub, Click Secret, create the Secret key/values as mentioned in the docs below. On every release, this action should run.

Example of the workflow is given below:

s3-package-release.yml Example

name: S3CDN upload

on:
  push:
    tags:
      - "*"
jobs:
  s3cdn:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Foxy/foxy-elements
        uses: actions/checkout@v2
      - name: Install & Build # Update this section with your own build commands
        run: |
          npm install
          npm run prepack
      - uses: Foxy/foxy-github-action-s3cdn@main
        # with:
        #   package-name: elements # optional: defaults to the repo name
        env:
          AWS_S3_CDN_BUCKET_NAME: ${{ secrets.AWS_S3_CDN_BUCKET_NAME }}
          AWS_S3_CDN_KEY_ID: ${{ secrets.AWS_S3_CDN_KEY_ID }}
          AWS_S3_CDN_KEY_SECRET: ${{ secrets.AWS_S3_CDN_KEY_SECRET }}
          SOURCE_DIR: "dist"
          # AWS_REGION: "us-west-1" # optional: defaults to us-east-1
Key Value Suggested Type Required Default
AWS_S3_CDN_KEY_ID Your AWS Access Key. More info here. secret env Yes N/A
AWS_S3_CDN_KEY_SECRET Your AWS Secret Access Key. More info here. secret env Yes N/A
AWS_S3_CDN_BUCKET_NAME The name of the bucket you're syncing to. For example, my-app-releases. secret env Yes N/A
AWS_REGION The region where you created your bucket. Set to us-east-1 by default. Full list of regions here. env No us-east-1
SOURCE_DIR The local directory (or build directory) you wish to sync/upload to S3 against those release version. For example, dist, public. env Yes If nothing is passed, dist will be considered your app/build directory
package-name Name of the package that will be appended to package version to make directory name. For example, MyPackage. arg No If nothing is passed, project's repo name will be used

License

This project is distributed under the MIT license.

About

Do you need something like unpkg.com but hosted on your own S3 account? This action will build and upload your code to S3 using the package@latest or package@1.2.3 approach just like unpkg.

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published