Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split GitHub workflows #528

Merged
merged 8 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/actions/setup-pnpm/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Setup pnpm
runs:
using: composite
steps:
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 20

- uses: pnpm/action-setup@v3
name: Install pnpm
with:
version: 9
run_install: false

- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV

- uses: actions/cache@v4
name: Setup pnpm cache
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
74 changes: 0 additions & 74 deletions .github/workflows/build-and-deploy.yml

This file was deleted.

61 changes: 0 additions & 61 deletions .github/workflows/clean-up-pr.yml

This file was deleted.

46 changes: 46 additions & 0 deletions .github/workflows/deploy-prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Deploy production

on:
push:
branches:
- main

# do not cancel in progress, SST will be stuck in a "locked" state if cancelled mid-deployment
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}

jobs:
build_and_deploy:
name: Build and deploy
runs-on: ubuntu-latest
environment:
name: production
url: https://peterportal.org
steps:
- name: Checkout repo
uses: actions/checkout@v4

- name: Setup pnpm
uses: ./.github/actions/setup-pnpm

- name: Install dependencies
run: pnpm install
env:
HUSKY: 0

- name: Build and deploy
run: pnpm sst deploy --stage prod
env:
DATABASE_URL: ${{ secrets.PROD_DATABASE_URL }}
NODE_ENV: production

PUBLIC_API_URL: ${{ secrets.PUBLIC_API_URL }}
SESSION_SECRET: ${{ secrets.SESSION_SECRET }}
GOOGLE_CLIENT: ${{ secrets.GOOGLE_CLIENT }}
GOOGLE_SECRET: ${{ secrets.GOOGLE_SECRET }}
GRECAPTCHA_SECRET: ${{ secrets.GRECAPTCHA_SECRET }}
ADMIN_EMAILS: ${{ secrets.ADMIN_EMAILS }}
PRODUCTION_DOMAIN: ${{ secrets.PRODUCTION_DOMAIN }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
ANTEATER_API_KEY: ${{ secrets.ANTEATER_API_KEY }}
50 changes: 50 additions & 0 deletions .github/workflows/deploy-staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Deploy staging

on:
pull_request:
types:
- opened
- reopened
- synchronize

# do not cancel in progress, SST will be stuck in a "locked" state if cancelled mid-deployment
concurrency:
group: staging-${{ github.event.pull_request.number }}

jobs:
build_and_deploy:
name: Build and deploy
runs-on: ubuntu-latest
# don't run if labeled "no deploy" && don't run on PRs from forks
if: (!contains(github.event.pull_request.labels.*.name, 'no deploy')) && github.event.pull_request.head.repo.full_name == github.repository
environment:
name: staging-${{ github.event.pull_request.number }}
url: https://staging-${{ github.event.pull_request.number }}.peterportal.org
steps:
- name: Checkout repo
uses: actions/checkout@v4

- name: Setup pnpm
uses: ./.github/actions/setup-pnpm

- name: Install dependencies
run: pnpm install
env:
HUSKY: 0

- name: Build and deploy
run: pnpm sst deploy --stage staging-${{ github.event.pull_request.number }}
env:
DATABASE_URL: ${{ secrets.DEV_DATABASE_URL }}
NODE_ENV: staging

PUBLIC_API_URL: ${{ secrets.PUBLIC_API_URL }}
SESSION_SECRET: ${{ secrets.SESSION_SECRET }}
GOOGLE_CLIENT: ${{ secrets.GOOGLE_CLIENT }}
GOOGLE_SECRET: ${{ secrets.GOOGLE_SECRET }}
GRECAPTCHA_SECRET: ${{ secrets.GRECAPTCHA_SECRET }}
ADMIN_EMAILS: ${{ secrets.ADMIN_EMAILS }}
PRODUCTION_DOMAIN: ${{ secrets.PRODUCTION_DOMAIN }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
ANTEATER_API_KEY: ${{ secrets.ANTEATER_API_KEY }}
28 changes: 3 additions & 25 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,12 @@ jobs:
lint:
name: Lint and check formatting
runs-on: ubuntu-latest

steps:
- name: Check Out Repo
- name: Checkout repo
uses: actions/checkout@v4

- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 20

- uses: pnpm/action-setup@v3
name: Install pnpm
with:
version: 9
run_install: false

- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV

- uses: actions/cache@v4
name: Setup pnpm cache
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Setup pnpm
uses: ./.github/actions/setup-pnpm

- name: Install Dependencies
run: pnpm install
Expand Down
41 changes: 41 additions & 0 deletions .github/workflows/remove-staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Remove staging

on:
pull_request:
types:
- closed

# use pr number for group instead of github.ref because ref will be main branch when the PR closes which is not a unique group for the PR
# group should match with deploy-staging workflow so those don't run concurrently (if someone closes/reopens a PR)
concurrency:
group: staging-${{ github.event.pull_request.number }}

jobs:
clean-up-pr:
runs-on: ubuntu-latest
# don't run on PRs from forks
if: github.event.pull_request.head.repo.full_name == github.repository
steps:
- name: Checkout repo
uses: actions/checkout@v4

- name: Setup pnpm
uses: ./.github/actions/setup-pnpm

- name: Install Dependencies
run: pnpm install
env:
HUSKY: 0

- name: Remove staging
run: pnpm sst remove --stage staging-${{ github.event.pull_request.number }}
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

- name: Deactivate deployment
uses: strumwolf/[email protected]
with:
environment: staging-${{ github.event.pull_request.number }}
token: ${{ secrets.GITHUB_TOKEN }}
onlyDeactivateDeployments: true
Loading