Skip to content
You're viewing an older version of this GitHub Action. Do you want to see the latest version instead?
upload-cloud

GitHub Action

Upload S3

v1.0.0

Upload S3 ☁️

This action upload directory to AWS S3 by public read and output key that generated by shortid

Usage

workflow.yml Example

Place in a .yml file such as this one in your .github/workflows folder. Refer to the documentation on workflow YAML syntax here.

name: Upload to S3

on: [pull_request]

jobs:
  upload:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@master
    - uses: shallwefootball/s3-upload-action@master
      with:
        aws_key_id: ${{ secrets.AWS_KEY_ID }}
        aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY}}
        aws_bucket: ${{ secrets.AWS_BUCKET }}
        source_dir: 'dirname'

Recommend using with deployment-action in pull request.

name: Deploy for preview

on: [pull_reqeust]

jobs:
  preview:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@master
      - uses: chrnorm/deployment-action@releases/v1
        name: Create GitHub deployment
        id: test
        with:
          token: ${{ secrets.GITHUB_TOKEN}}
          description: 'Preview my app'
          environment: preview

      - uses: shallwefootball/s3-upload-action@master
        name: Upload S3
        id: S3
        with:
          aws_key_id: ${{ secrets.AWS_KEY_ID }}
          aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY}}
          aws_bucket: ${{ secrets.AWS_BUCKET }}
          source_dir: 'static'

      - name: Update deployment status (success)
        if: success()
        uses: chrnorm/deployment-status@releases/v1
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          target_url: https://aws-bucket.s3.ap-northeast-2.amazonaws.com/${{steps.S3.outputs.object_key}}/index.html
          state: 'success'
          deployment_id: ${{ steps.test.outputs.deployment_id }}

Configuration

The following settings must be passed as environment variables as shown in the example. Sensitive information, especially aws_key_id and aws_secret_access_key, should be set as encrypted secrets — otherwise, they'll be public to anyone browsing your repository's source code

| Key | Value | Suggested Type | Required | | --- | --- | --- | --- | --- | | aws_key_id | Your AWS Access Key. More info here. | secret env | Yes | | aws_secret_access_key | Your AWS Secret Access Key. More info here. | secret env | Yes | N/A | | aws_bucket | The name of the bucket you're upload to. | secret env | Yes | | source_dir | The local directory (or file) you wish to upload to S3. | env | Yes |