Update CI/CD Maintenance Tasks #70
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI/CD | |
on: | |
push: | |
branches: [ main, documentation-updates ] | |
pull_request: | |
branches: [ main, documentation-updates ] | |
jobs: | |
lint: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Set up Node.js | |
uses: actions/setup-node@v2 | |
with: | |
node-version: '18.x' | |
- name: Cache node modules | |
uses: actions/cache@v2 | |
env: | |
cache-name: cache-node-modules | |
with: | |
path: ~/.npm | |
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-build-${{ env.cache-name }}- | |
${{ runner.os }}-build- | |
${{ runner.os }}- | |
- name: Install dependencies | |
run: | | |
cd src/growers-gate-frontend | |
npm ci | |
- name: Run linter | |
env: | |
NODE_ENV: production | |
BABEL_ENV: production | |
run: | | |
cd src/growers-gate-frontend | |
npm run lint | |
- name: Run Prettier | |
run: | | |
cd src/growers-gate-frontend | |
npm run format:check | |
test-frontend: | |
runs-on: ubuntu-latest | |
needs: lint | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Set up Node.js | |
uses: actions/setup-node@v2 | |
with: | |
node-version: '18.x' | |
- name: Cache node modules | |
uses: actions/cache@v2 | |
env: | |
cache-name: cache-node-modules | |
with: | |
path: ~/.npm | |
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-build-${{ env.cache-name }}- | |
${{ runner.os }}-build- | |
${{ runner.os }}- | |
- name: Install dependencies | |
run: | | |
cd src/growers-gate-frontend | |
npm ci | |
- name: Run frontend tests | |
env: | |
NODE_ENV: test | |
BABEL_ENV: test | |
run: | | |
cd src/growers-gate-frontend | |
npm test -- --coverage | |
- name: Upload coverage to Codecov | |
uses: codecov/codecov-action@v1 | |
test-backend: | |
runs-on: ubuntu-latest | |
needs: lint | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Set up Node.js | |
uses: actions/setup-node@v2 | |
with: | |
node-version: '18.x' | |
- name: Cache node modules | |
uses: actions/cache@v2 | |
env: | |
cache-name: cache-node-modules | |
with: | |
path: ~/.npm | |
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-build-${{ env.cache-name }}- | |
${{ runner.os }}-build- | |
${{ runner.os }}- | |
- name: Start MongoDB | |
uses: supercharge/[email protected] | |
with: | |
mongodb-version: '6.0' | |
- name: Install backend dependencies | |
run: | | |
cd src/growers-gate-backend | |
npm ci | |
- name: Run backend tests | |
env: | |
MONGODB_URI: mongodb://localhost:27017/growers_gate_test | |
JWT_SECRET: ${{ secrets.JWT_SECRET }} | |
OTP_SECRET: ${{ secrets.OTP_SECRET }} | |
run: | | |
cd src/growers-gate-backend | |
npm test -- --coverage | |
- name: Upload coverage to Codecov | |
uses: codecov/codecov-action@v1 | |
build: | |
runs-on: ubuntu-latest | |
needs: [test-frontend, test-backend] | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Set up Node.js | |
uses: actions/setup-node@v2 | |
with: | |
node-version: '18.x' | |
- name: Cache node modules | |
uses: actions/cache@v2 | |
env: | |
cache-name: cache-node-modules | |
with: | |
path: ~/.npm | |
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-build-${{ env.cache-name }}- | |
${{ runner.os }}-build- | |
${{ runner.os }}- | |
- name: Install dependencies | |
run: | | |
cd src/growers-gate-frontend | |
npm ci | |
- name: Build frontend | |
run: | | |
cd src/growers-gate-frontend | |
npm run build | |
- name: Run Lighthouse CI | |
uses: treosh/lighthouse-ci-action@v8 | |
with: | |
configPath: './lighthouserc.json' | |
uploadArtifacts: true | |
temporaryPublicStorage: true | |
deploy: | |
needs: build | |
runs-on: ubuntu-latest | |
if: github.ref == 'refs/heads/main' | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Deploy Frontend to Netlify | |
uses: nwtgck/[email protected] | |
with: | |
publish-dir: './src/growers-gate-frontend/build' | |
production-branch: main | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
deploy-message: "Deploy from GitHub Actions" | |
enable-pull-request-comment: false | |
enable-commit-comment: true | |
overwrites-pull-request-comment: true | |
env: | |
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} | |
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} | |
- name: Deploy Backend to Heroku | |
uses: akhileshns/[email protected] | |
with: | |
heroku_api_key: ${{ secrets.HEROKU_API_KEY }} | |
heroku_app_name: ${{ secrets.HEROKU_APP_NAME }} | |
heroku_email: ${{ secrets.HEROKU_EMAIL }} | |
appdir: "src/growers-gate-backend" | |
- name: Slack Notification | |
uses: 8398a7/action-slack@v3 | |
with: | |
status: ${{ job.status }} | |
text: Deployment ${{ job.status == 'success' && 'succeeded' || 'failed' }}! | |
fields: repo,message,commit,author,action,eventName,ref,workflow | |
env: | |
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} | |
if: always() |