wip: add .nvmrc #267
Workflow file for this run
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 pipeline | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: ${{ github.repository }} | |
IMPAAS_APP_NAME: cpp-connect | |
on: [push] | |
# push: | |
# branches: | |
# - main | |
# - 'feat-*' | |
# pull_request: | |
# branches: | |
# - main | |
jobs: | |
changes: | |
runs-on: ubuntu-latest | |
outputs: | |
migrations: ${{ steps.filter.outputs.migrations }} | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: dorny/paths-filter@v3 | |
id: filter | |
with: | |
filters: | | |
migrations: | |
- 'prisma/migrations/**' | |
install-dependencies: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version-file: '.nvmrc' | |
cache: 'npm' | |
- name: Cache node_modules | |
uses: actions/cache@v4 | |
id: cache-primes | |
with: | |
path: node_modules | |
key: ${{ runner.os }}-nextjs-${{ hashFiles('package-lock.json') }} | |
- name: Install dependencies | |
run: npm ci | |
type-check: | |
runs-on: ubuntu-latest | |
needs: install-dependencies | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version-file: '.nvmrc' | |
cache: 'npm' | |
- name: Load cached node_modules | |
uses: actions/cache@v4 | |
id: cache-primes | |
with: | |
path: node_modules | |
key: ${{ runner.os }}-nextjs-${{ hashFiles('package-lock.json') }} | |
- name: Prisma generate | |
run: npx prisma generate | |
- name: Check types | |
run: npm run type-check | |
style-check: | |
runs-on: ubuntu-latest | |
needs: install-dependencies | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version-file: '.nvmrc' | |
cache: 'npm' | |
- name: Load cached node_modules | |
uses: actions/cache@v4 | |
id: cache-primes | |
with: | |
path: node_modules | |
key: ${{ runner.os }}-nextjs-${{ hashFiles('package-lock.json') }} | |
- name: Run Prettier | |
run: npm run format -- --check | |
lint: | |
runs-on: ubuntu-latest | |
needs: install-dependencies | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Use Node.js 20.x | |
uses: actions/setup-node@v4 | |
- uses: actions/cache@v4 # From https://nextjs.org/docs/pages/building-your-application/deploying/ci-build-caching#github-actions | |
with: | |
# See here for caching with `yarn` https://github.com/actions/cache/blob/main/examples.md#node---yarn or you can leverage caching with actions/setup-node https://github.com/actions/setup-node | |
path: | | |
${{ github.workspace }}/.next/cache | |
# Generate a new cache whenever packages or source files change. | |
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**/*.js', '**/*.jsx', '**/*.ts', '**/*.tsx') }} | |
# If source files changed but packages didn't, rebuild from a prior cache. | |
restore-keys: | | |
${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}- | |
- run: npm run lint | |
build-and-push-image: | |
needs: | |
- type-check | |
- style-check | |
- lint | |
# if: github.ref == 'refs/heads/main' | |
runs-on: ubuntu-latest | |
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job. | |
permissions: | |
contents: read | |
packages: write | |
attestations: write | |
id-token: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Log in to the Container registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels. | |
- name: Extract metadata (tags, labels) for Docker | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
tags: | | |
type=ref,event=branch | |
type=ref,event=tag | |
type=ref,event=pr | |
type=sha | |
type=raw,value=latest,enable={{is_default_branch}} | |
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages. | |
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository. | |
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step. | |
- name: Build and push Docker image | |
id: push | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
no-cache: true | |
deploy-impaas: | |
needs: build-and-push-image | |
# if: github.ref == 'refs/heads/main' | |
runs-on: ubuntu-latest | |
env: | |
TSURU_TOKEN: ${{ secrets.IMPAAS_DEPLOY_TOKEN }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Install tsuru CLI | |
run: curl -fsSL "https://tsuru.io/get" | bash | |
- name: Add impaas target | |
run: tsuru target add impaas https://impaas.uk -s | |
- name: Deploy app | |
run: tsuru app deploy -i ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest -a ${{ env.IMPAAS_APP_NAME }} | |
- name: Create upload directories | |
run: | | |
tsuru app run "mkdir -p \$UPLOAD_DIR && cd \$UPLOAD_DIR && mkdir -p banners cvs avatars logos attachments" -a cpp-connect | |
- name: Set environment variables | |
run: | | |
tsuru env set -a cpp-connect \ | |
NEXTAUTH_URL=${{ vars.NEXTAUTH_URL }} \ | |
EMAIL_SERVER_USER=${{ secrets.EMAIL_SERVER_USER }} \ | |
EMAIL_SERVER_PASSWORD=${{ secrets.EMAIL_SERVER_PASSWORD }} \ | |
EMAIL_SERVER_HOST=${{ secrets.EMAIL_SERVER_HOST }} \ | |
EMAIL_SERVER_PORT=${{ secrets.EMAIL_SERVER_PORT }} \ | |
EMAIL_FROM=${{ secrets.EMAIL_FROM }} \ | |
AUTH_SECRET=${{ secrets.AUTH_SECRET }} \ | |
AUTH_TRUST_HOST=true \ | |
MS_ENTRA_CLIENT_ID=${{ secrets.MS_ENTRA_CLIENT_ID }} \ | |
MS_ENTRA_CLIENT_SECRET=${{ secrets.MS_ENTRA_CLIENT_SECRET }} \ | |
MS_ENTRA_TENANT_ID=${{ secrets.MS_ENTRA_TENANT_ID }} | |
apply-db-migrations: | |
runs-on: ubuntu-latest | |
needs: | |
- changes | |
- deploy-impaas | |
# if: github.ref == 'refs/heads/main' && needs.changes.outputs.migrations == 'true' | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version-file: '.nvmrc' | |
cache: 'npm' | |
- name: Load cached node_modules | |
uses: actions/cache@v4 | |
id: cache-primes | |
with: | |
path: node_modules | |
key: ${{ runner.os }}-nextjs-${{ hashFiles('package-lock.json') }} | |
- name: Apply all pending migrations to the database | |
run: npx prisma migrate deploy | |
env: | |
DATABASE_URL: ${{ secrets.DATABASE_URL }} |