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

out-of-sync main and staging #67

Merged
merged 18 commits into from
Jan 25, 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
36 changes: 12 additions & 24 deletions .github/workflows/CI-CD.yml → .github/workflows/main-pipeline.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
name: CI/CD
name: main-pipeline

on: [push]
on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:

jobs:
test:
Expand Down Expand Up @@ -46,12 +53,10 @@ jobs:
- name: Run tests
run: npm run test



publish:
if: github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/main' || github.ref == 'refs/heads/staging'
needs: test
runs-on: ubuntu-latest
if: github.event_name == 'push'
steps:
- name: Check out the repo
uses: actions/checkout@v2
Expand All @@ -69,32 +74,15 @@ jobs:
tag_with_sha: true

deploy:
if: github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/main'|| github.ref == 'refs/heads/staging'
needs: publish
runs-on: ubuntu-latest
steps:
- name: Staging deploy
if: github.ref == 'refs/heads/staging'
uses: appleboy/[email protected]
with:
host: ${{ secrets.STAGING_HOST_ALL }}
username: ${{ secrets.STAGING_USERNAME_ALL }}
key: ${{ secrets.STAGING_PRIVATE_KEY_ALL}}
port: ${{ secrets.SSH_PORT }}
script: |
cd giveth-all
docker compose stop notification-center
docker compose pull notification-center
docker compose up -d notification-center
docker image prune -a --force

- name: Production deploy
if: github.ref == 'refs/heads/main'
- name: SSH and Redeploy
uses: appleboy/[email protected]
with:
host: ${{ secrets.PROD_HOST_ALL }}
username: ${{ secrets.PROD_USERNAME_ALL }}
key: ${{ secrets.PROD_PRIVATE_KEY_ALL}}
key: ${{ secrets.PROD_PRIVATE_KEY_ALL }}
port: ${{ secrets.SSH_PORT }}
script: |
cd giveth-all
Expand Down
90 changes: 90 additions & 0 deletions .github/workflows/staging-pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: staging-pipeline

on:
push:
branches:
- staging
pull_request:
branches:
- staging
jobs:
test:
runs-on: ubuntu-latest
services:
# Label used to access the service container
redis:
# Docker Hub image
image: redis
# Set health checks to wait until redis has started
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 6490:6379
postgres:
image: postgres:14
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: givethio
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5446:5432
steps:
- uses: actions/checkout@v1
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: 18.14.0
- name: Install dependencies
run: npm ci
- name: Run linter
run: npm run lint
- name: Run migrations
run: npm run db:migrate:run:test
- name: Run tests
run: npm run test

publish:
needs: test
runs-on: ubuntu-latest
if: github.event_name == 'push'
steps:
- name: Check out the repo
uses: actions/checkout@v2
- name: Build image and push to GitHub Packages
uses: docker/build-push-action@v1
with:
username: ${{ github.actor }}
password: ${{ github.token }}
registry: ghcr.io
repository: giveth/notification-center
add_git_labels: true
# Add branch name to docker image tag @see{@link https://github.com/docker/build-push-action/tree/releases/v1#tag_with_ref}
tag_with_ref: true
# Add commit hash to docker image tag @see{@link https://github.com/docker/build-push-action/tree/releases/v1#tag_with_sha}
tag_with_sha: true

deploy:
needs: publish
runs-on: ubuntu-latest
steps:
- name: SSH and Redeploy
uses: appleboy/[email protected]
with:
host: ${{ secrets.STAGING_HOST_ALL }}
username: ${{ secrets.STAGING_USERNAME_ALL }}
key: ${{ secrets.STAGING_PRIVATE_KEY_ALL }}
port: ${{ secrets.SSH_PORT }}
script: |
cd giveth-all
docker-compose stop notification-center
docker-compose pull notification-center
docker-compose up -d notification-center
docker image prune -a --force
91 changes: 91 additions & 0 deletions migrations/1692698983844-changeNotificationCopies.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
import { getNotificationTypeByEventName } from '../src/repositories/notificationTypeRepository';
import { NOTIFICATION_TYPE_NAMES } from '../src/types/general';

export class changeNotificationCopies1692698983844
implements MigrationInterface
{
private async updateNotificationType(
eventName: string,
data: {
htmlTemplate?: any;
content?: string;
},
) {
const notificationType = await getNotificationTypeByEventName(eventName);
if (!notificationType) {
return;
}
notificationType.htmlTemplate = data.htmlTemplate;
notificationType.content = data.content;
await notificationType.save();
}

public async up(queryRunner: QueryRunner): Promise<void> {
if (
process.env.NODE_ENV === 'test' ||
process.env.NODE_ENV === 'development'
) {
// Running these migrations in test and development environments would make the tests fail
// because the notification types are not created in the test database
// In future we should use raw SQL queries to update the notification types
return;
}

const notificationTypesArray = [
{
eventName: NOTIFICATION_TYPE_NAMES.PROJECT_LISTED_OWNER,
data: {
content:
'Your project {project name} has been listed on the projects page.',
htmlTemplate: [
{
type: 'p',
content: 'Your project ',
},
{
type: 'a',
content: '$projectTitle',
href: '$projectLink',
},
{
type: 'p',
content: ' has been listed on the projects page.',
},
],
},
},
{
eventName: NOTIFICATION_TYPE_NAMES.PROJECT_UNLISTED_OWNER,
data: {
content:
'Your project {project name} has been unlisted from the projects page.',
htmlTemplate: [
{
type: 'p',
content: 'Your project ',
},
{
type: 'a',
content: '$projectTitle',
href: '$projectLink',
},
{
type: 'p',
content: ' has been unlisted from the projects page.',
},
],
},
},
];
await Promise.all(
notificationTypesArray.map(item =>
this.updateNotificationType(item.eventName, item.data),
),
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
//
}
}
Loading
Loading