Skip to content

Commit

Permalink
Add ci-cd.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
Draikth committed Jul 8, 2024
1 parent 3eccd1f commit 2b77a01
Show file tree
Hide file tree
Showing 2 changed files with 185 additions and 2 deletions.
87 changes: 87 additions & 0 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: CI
on: push

jobs:
ci:
name: Jest Unit Tests, Type Checking, Linting, Playwright End to End Tests
runs-on: ubuntu-latest # or macos-latest, windows-latest
timeout-minutes: 30
# TODO: Update environment variables with your own database credentials
env:
PGHOST: localhost
PGDATABASE: next_js_example_spring_2024
PGUSERNAME: next_js_example_spring_2024
PGPASSWORD: next_js_example_spring_2024
steps:
- name: Start preinstalled PostgreSQL on Ubuntu
run: |
sudo systemctl start postgresql.service
pg_isready
- name: Create database user
run: |
sudo -u postgres psql --command="CREATE USER $PGUSERNAME PASSWORD '$PGPASSWORD'" --command="\du"
- name: Create database and allow user
run: |
sudo -u postgres createdb --owner=$PGUSERNAME $PGDATABASE
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4

# Use the official setup-node action (sets up Node.js):
# https://github.com/actions/setup-node
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: 'lts/*'
cache: 'pnpm'

- name: Install dependencies
run: pnpm install
- name: Jest unit tests
run: pnpm jest
- name: Run database migrations
run: pnpm migrate up
- name: Build Next.js app (types needed for TSC and ESLint)
run: pnpm build
- name: Check TypeScript Types
run: pnpm tsc
- name: Lint with ESLint
run: pnpm eslint . --max-warnings 0
- name: Lint with Stylelint
run: pnpm stylelint '**/*.{css,scss,less,js,tsx}'

# Cache and install Playwright browser binaries, modified version of:
# https://github.com/microsoft/playwright/issues/7249#issuecomment-1154603556
# https://github.com/microsoft/playwright/issues/7249#issuecomment-1385567519
# https://playwrightsolutions.com/playwright-github-action-to-cache-the-browser-binaries/
- name: Get installed Playwright version for cache key
run: echo "PLAYWRIGHT_VERSION=$(yq eval '.version' --output-format=yaml ./node_modules/@playwright/test/package.json)" >> $GITHUB_ENV
- name: Cache Playwright browser binaries
uses: actions/cache@v4
id: playwright-browser-cache
with:
path: |
~/.cache/ms-playwright
key: ${{ runner.os }}-playwright-${{ env.PLAYWRIGHT_VERSION }}
- name: Install Playwright browsers only on cache miss
run: pnpm playwright install --with-deps chromium
if: steps.playwright-browser-cache.outputs.cache-hit != 'true'

- name: Run tests
run: pnpm playwright test
- uses: actions/upload-artifact@v4
if: failure()
with:
name: playwright-screenshots-videos
path: playwright/test-results/
cd:
name: Deploy to Fly.io
runs-on: ubuntu-latest
timeout-minutes: 30
needs: ci
if: github.ref == 'refs/heads/main'
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
steps:
- uses: actions/checkout@v4
- uses: superfly/flyctl-actions/setup-flyctl@master
- run: flyctl deploy --remote-only
100 changes: 98 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,100 @@
This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/create-next-app).
# Next.js Event Network Project

The main idea is that this is a site you go to for seeing what kind of various events are happening around the city, is there a concert? a large festival, a small festival, a renaissance fair, that one performance of McBeth happening in the local graveyard? you should be able to go to this site and find out without having to hope you see the poster on some random lamppost or stumble upon something that looks interesting and you maybe would've liked to attend, already happening when you are out and about.

The site is supposed to act as a collective reference point for all these various events happening in and around the city, a marketing point even, though the site itself is not intended to be a point of sale for tickets... at least not within the scope of the project (If i have time, then maybe I can look at making it something like that in the future...)

## Technologies

- Next.js
- Postgres.js
- Jest
- Playwright

## Database Setup

If you don't have PostgreSQL installed yet, follow the instructions from the PostgreSQL step in [UpLeveled's System Setup Instructions](https://github.com/upleveled/system-setup/blob/master/readme.md).

Copy the `.env.example` file to a new file called `.env` (ignored from Git) and fill in the necessary information.

Then, connect to the built-in `postgres` database as administrator in order to create the database:

**Windows**

If it asks for a password, use `postgres`.

```bash
psql -U postgres
```

**macOS**

```bash
psql postgres
```

**Linux**

```bash
sudo -u postgres psql
```

Once you have connected, run the following to create the database:

```sql
CREATE DATABASE <database name>;
CREATE USER <user name> WITH ENCRYPTED PASSWORD '<user password>';
GRANT ALL PRIVILEGES ON DATABASE <database name> TO <user name>;
\connect <database name>
CREATE SCHEMA <schema name> AUTHORIZATION <user name>;
```

Quit `psql` using the following command:

```bash
\q
```

On Linux, you will also need to create a Linux system user with a name matching the user name you used in the database. It will prompt you to create a password for the user - choose the same password as for the database above.

```bash
sudo adduser <user name>
```

Once you're ready to use the new user, reconnect using the following command.

**Windows and macOS:**

```bash
psql -U <user name> <database name>
```

**Linux:**

```bash
sudo -u <user name> psql -U <user name> <database name>
```

## Run Tests

To run unit tests with Jest, use the following command:

```bash
pnpm jest
```

To run end-to-end tests with Playwright, use the following command:

```bash
pnpm playwright test
```

## Deployment

- Fly.io
- Docker

<!-- This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/create-next-app).
## Getting Started
Expand Down Expand Up @@ -33,4 +129,4 @@ You can check out [the Next.js GitHub repository](https://github.com/vercel/next
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details.
Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details. -->

0 comments on commit 2b77a01

Please sign in to comment.