-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: split GitHub workflows (#528)
* Split build and deploy workflow for prod and staging * Created actions for repeated steps * Fixed concurrency groups * Added condition to not deploy staging on fork
- Loading branch information
Showing
7 changed files
with
167 additions
and
160 deletions.
There are no files selected for viewing
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
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- |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
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 }} |
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
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 }} |
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
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
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 |