Skip to content

Commit

Permalink
Initial configuration to handle S3 deployments.
Browse files Browse the repository at this point in the history
  • Loading branch information
srm985 committed Apr 3, 2024
1 parent b338860 commit d2f33e7
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 194 deletions.
1 change: 0 additions & 1 deletion .git-ftp-include

This file was deleted.

162 changes: 145 additions & 17 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,39 +1,167 @@
name: CI/CD - Master
name: Deploy to production

on:
push:
branches: [master]
branches: [main]
pull_request:
branches: [master]
branches: [main]
workflow_dispatch:
branches: [master]
branches: [main]

jobs:
lint-js:
name: Lint JavaScript
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 2

- name: Use NodeJS 20.x
uses: actions/setup-node@v3
with:
node-version: '20.x'

- name: Cache dependencies
uses: actions/cache@v3
with:
path: ~/.npm
key: npm-${{ hashFiles('package-lock.json') }}
restore-keys: npm-

# Install Node Modules
- name: Install
run: npm ci

# Lint JavaScript
- name: Lint JavaScript
run: npm run lint:js

lint-css:
name: Lint CSS
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 2

- name: Use NodeJS 20.x
uses: actions/setup-node@v3
with:
node-version: '20.x'

- name: Cache dependencies
uses: actions/cache@v3
with:
path: ~/.npm
key: npm-${{ hashFiles('package-lock.json') }}
restore-keys: npm-

# Install Node Modules
- name: Install
run: npm ci

# Lint CSS
- name: Lint CSS
run: npm run lint:scss

test:
name: Test
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 2

- name: Use NodeJS 20.x
uses: actions/setup-node@v3
with:
node-version: '20.x'

- name: Cache dependencies
uses: actions/cache@v3
with:
path: ~/.npm
key: npm-${{ hashFiles('package-lock.json') }}
restore-keys: npm-

# Install Node Modules
- name: Install
run: npm ci

# Test
- name: Test
run: npm run test

build:
name: Build
runs-on: ubuntu-latest
needs: [lint-css, lint-js]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 2

- name: Use NodeJS 16.x
uses: actions/setup-node@v1
- name: Use NodeJS 20.x
uses: actions/setup-node@v3
with:
node-version: '16.x'
node-version: '20.x'

# Install Packages
- name: Cache dependencies
uses: actions/cache@v3
with:
path: ~/.npm
key: npm-${{ hashFiles('package-lock.json') }}
restore-keys: npm-

# Install Node Modules
- name: Install
run: npm install
run: npm ci

# Build the website
- name: Build
run: npm run build:deploy
run: npm run build

# Zip artifacts
- name: Zip artifacts
run: zip -r public.zip ./public

# Upload artifacts
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: public.zip
path: ./public.zip

deploy:
name: Deploy
needs: build
runs-on: ubuntu-latest
environment: production

steps:
- uses: actions/checkout@v3

- name: FTP Deploy
uses: SamKirkland/FTP-Deploy-Action@3.1.1
# Download artifacts
- name: Download artifacts
uses: actions/download-artifact@v3

# Unzip artifacts
- name: Unzip artifacts
run: unzip -o ./public.zip -d ./public

# Prepare AWS SDK
- name: Prepare AWS SDK
uses: aws-actions/configure-aws-credentials@v4
with:
ftp-server: ${{ secrets.FTP_HOST }}
ftp-username: ${{ secrets.FTP_USERNAME }}
ftp-password: ${{ secrets.FTP_PASSWORD }}
local-dir: public
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ var.AWS_REGION }}

# Deploy portfolio website
- name: Deploy
run: aws s3 sync ./public s3://${{ vars.S3_BUCKET_NAME }} --delete
1 change: 0 additions & 1 deletion .node-version

This file was deleted.

6 changes: 1 addition & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-react": "^7.23.2",
"eslint-plugin-sort-destructure-keys": "^1.3.5",
"ftp": "^0.3.10",
"gatsby-plugin-sitemap": "^6.12.0",
"husky": "^8.0.3",
"identity-obj-proxy": "^3.0.0",
Expand Down Expand Up @@ -90,15 +89,12 @@
"name": "portfolio-website",
"private": false,
"scripts": {
"build": "concurrently --raw \"npm:lint:fix --silent\" \"npm:test\" && gatsby build",
"build:deploy": "npm run build && npm run migrate:artifacts",
"deploy": " node -r dotenv/config ./scripts/deploy.js",
"build": "gatsby build",
"develop": "cross-env NODE_ENV=development cross-env GATSBY_GRAPHQL_IDE=playground concurrently --raw \"npm:lint --silent\" \"gatsby develop --port 3000\" \"npm:watch --silent\"",
"lint": "concurrently --raw \"npm:lint:js --silent\" \"npm:lint:scss --silent\"",
"lint:fix": "concurrently --raw \"eslint ./*.js src/**/*.js .storybook/*.js --fix\" \"stylelint src/**/*.scss --color --allow-empty-input --fix\"",
"lint:js": "eslint ./*.js src/**/*.js .storybook/*.js --ignore-pattern /src/vendor/*",
"lint:scss": "stylelint src/**/*.scss --color --allow-empty-input",
"migrate:artifacts": "node ./scripts/migrateArtifacts.js",
"pre-commit": "cross-env FORCE_COLOR=true concurrently --raw \"npm:test\" \"lint-staged\"",
"pre-push": "node ./scripts/branchCheck.js",
"prepare": "husky install",
Expand Down
170 changes: 0 additions & 170 deletions scripts/deploy.js

This file was deleted.

0 comments on commit d2f33e7

Please sign in to comment.