Skip to content

Instantly share code, notes, and snippets.

@ChristianRich
Created January 31, 2020 12:36
Show Gist options
  • Save ChristianRich/9c94fb7477a444d2ba9a02890d229633 to your computer and use it in GitHub Desktop.
Save ChristianRich/9c94fb7477a444d2ba9a02890d229633 to your computer and use it in GitHub Desktop.
Github action: Build and deploy static website to AWS S3
name: Build and deploy
on:
push:
branches:
- master
jobs:
build:
name: Build
runs-on: ubuntu-18.04
strategy:
matrix:
node-version: [10.x]
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Install packages, test and build artifacts
run: |
npm i -D
npm test --if-present
npm run build:prod
env:
CI: true
- name: Upload artifacts
uses: actions/upload-artifact@master
with:
name: build
path: build
deploy:
name: Deploy
needs: build
runs-on: ubuntu-18.04
steps:
- name: Checkout
uses: actions/checkout@master
- name: Download artifacts
uses: actions/download-artifact@master
with:
name: build
path: build
- name: Remove existing artifacts from AWS S3
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
run: |
aws s3 rm \
s3://<<YOUR_BUCKET_NAME>> \
--recursive \
--region ap-southeast-2
- name: Deploy artifacts to AWS S3
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
run: |
aws s3 cp \
./build s3://<<YOUR_BUCKET_NAME>> \
--recursive \
--acl public-read \
--region ap-southeast-2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment