Skip to content

Commit 4601ea5

Browse files
Merge pull request #3 from olha-dev-fullstack/dev
Reusable workflows
2 parents c912394 + f91bf6f commit 4601ea5

File tree

3 files changed

+78
-98
lines changed

3 files changed

+78
-98
lines changed

.github/workflows/deployment.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Deployment flow
2+
on:
3+
workflow_call:
4+
inputs:
5+
environment:
6+
type: string
7+
required: true
8+
runner:
9+
type: string
10+
required: true
11+
env_file:
12+
type: string
13+
required: true
14+
jobs:
15+
checkout:
16+
runs-on: [self-hosted, "${{inputs.runner}}"]
17+
environment: ${{inputs.environment}}
18+
steps:
19+
- name: Get code
20+
uses: actions/checkout@v4
21+
- name: Cache dependencies
22+
id: cache
23+
uses: actions/cache@v4
24+
with:
25+
path: node_modules
26+
key: deps-node-modules-${{ hashFiles('**/package-lock.json') }}
27+
- name: Install dependencies
28+
if: steps.cache.outputs.cache-hit != 'true'
29+
run: npm ci
30+
create_env:
31+
needs: checkout
32+
runs-on: [self-hosted, "${{inputs.runner}}"]
33+
environment: ${{inputs.environment}}
34+
steps:
35+
- name: Create .env file
36+
run: |
37+
echo "DB_HOST=${{ secrets.DB_HOST }}" >> ${{inputs.env_file}}
38+
echo "DB_PORT=${{ secrets.DB_PORT }}" >> ${{inputs.env_file}}
39+
echo "DB_USER=${{ secrets.DB_USER }}" >> ${{inputs.env_file}}
40+
echo "DB_PASSWORD=${{ secrets.DB_PASSWORD }}" >> ${{inputs.env_file}}
41+
echo "DB_NAME=${{ secrets.DB_NAME }}" >> ${{inputs.env_file}}
42+
echo "DB_DROP_SCHEMA=${{ secrets.DB_DROP_SCHEMA }}" >> ${{inputs.env_file}}
43+
echo "AUTH_SECRET=${{ secrets.AUTH_SECRET }}" >> ${{inputs.env_file}}
44+
echo "JWT_EXPIRES_IN=${{ secrets.JWT_EXPIRES_IN }}" >> ${{inputs.env_file}}
45+
echo "PORT=${{ secrets.PORT }}" >> ${{inputs.env_file}}
46+
test:
47+
runs-on: [self-hosted, "${{inputs.runner}}"]
48+
needs: create_env
49+
steps:
50+
- name: Run tests
51+
run: npm run test
52+
build:
53+
needs: [create_env, test]
54+
runs-on: [self-hosted, "${{inputs.runner}}"]
55+
steps:
56+
- name: Build website
57+
id: build-website
58+
run: npm run build
59+
deploy:
60+
needs: build
61+
runs-on: [self-hosted, "${{inputs.runner}}"]
62+
steps:
63+
- name: Run deployment
64+
run: NODE_ENV=${{inputs.environment}} pm2 restart dist/main.js --name=events-api

.github/workflows/dev.yml

Lines changed: 7 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -5,53 +5,10 @@ on:
55
- dev
66
workflow_dispatch:
77
jobs:
8-
checkout:
9-
runs-on: [self-hosted, dev]
10-
environment: dev
11-
steps:
12-
- name: Get code
13-
uses: actions/checkout@v4
14-
- name: Cache dependencies
15-
id: cache
16-
uses: actions/cache@v4
17-
with:
18-
path: node_modules
19-
key: deps-node-modules-${{ hashFiles('**/package-lock.json') }}
20-
- name: Install dependencies
21-
if: steps.cache.outputs.cache-hit != 'true'
22-
run: npm ci
23-
create_env:
24-
needs: checkout
25-
runs-on: [self-hosted, dev]
26-
environment: dev
27-
steps:
28-
- name: Create .env file
29-
run: |
30-
echo "DB_HOST=${{ secrets.DB_HOST }}" >> dev.env
31-
echo "DB_PORT=${{ secrets.DB_PORT }}" >> dev.env
32-
echo "DB_USER=${{ secrets.DB_USER }}" >> dev.env
33-
echo "DB_PASSWORD=${{ secrets.DB_PASSWORD }}" >> dev.env
34-
echo "DB_NAME=${{ secrets.DB_NAME }}" >> dev.env
35-
echo "DB_DROP_SCHEMA=${{ secrets.DB_DROP_SCHEMA }}" >> dev.env
36-
echo "AUTH_SECRET=${{ secrets.AUTH_SECRET }}" >> dev.env
37-
echo "JWT_EXPIRES_IN=${{ secrets.JWT_EXPIRES_IN }}" >> dev.env
38-
echo "PORT=${{ secrets.PORT }}" >> dev.env
39-
test:
40-
runs-on: [self-hosted, dev]
41-
needs: create_env
42-
steps:
43-
- name: Run tests
44-
run: npm run test
45-
build:
46-
needs: [create_env, test]
47-
runs-on: [self-hosted, dev]
48-
steps:
49-
- name: Build website
50-
id: build-website
51-
run: npm run build
52-
deploy:
53-
needs: build
54-
runs-on: [self-hosted, dev]
55-
steps:
56-
- name: Run deployment
57-
run: NODE_ENV=dev pm2 restart dist/main.js --name=events-api
8+
run-deployment:
9+
uses: ./.github/workflows/deployment.yml
10+
with:
11+
environment: "dev"
12+
runner: "dev"
13+
env_file: "dev.env"
14+
secrets: inherit

.github/workflows/production.yml

Lines changed: 7 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,51 +2,10 @@ name: Production deployment
22
on:
33
workflow_dispatch:
44
jobs:
5-
checkout:
6-
runs-on: [self-hosted, prod]
7-
environment: production
8-
steps:
9-
- name: Get code
10-
uses: actions/checkout@v4
11-
- name: Cache dependencies
12-
id: cache
13-
uses: actions/cache@v4
14-
with:
15-
path: node_modules
16-
key: deps-node-modules-${{ hashFiles('**/package-lock.json') }}
17-
- name: Install dependencies
18-
if: steps.cache.outputs.cache-hit != 'true'
19-
run: npm ci
20-
create_env:
21-
needs: checkout
22-
runs-on: [self-hosted, prod]
23-
environment: production
24-
steps:
25-
- name: Create .env file
26-
run: |
27-
echo "DB_HOST=${{ secrets.DB_HOST }}" >> production.env
28-
echo "DB_PORT=${{ secrets.DB_PORT }}" >> production.env
29-
echo "DB_USER=${{ secrets.DB_USER }}" >> production.env
30-
echo "DB_PASSWORD=${{ secrets.DB_PASSWORD }}" >> production.env
31-
echo "DB_NAME=${{ secrets.DB_NAME }}" >> production.env
32-
echo "AUTH_SECRET=${{ secrets.AUTH_SECRET }}" >> production.env
33-
echo "JWT_EXPIRES_IN=${{ secrets.JWT_EXPIRES_IN }}" >> production.env
34-
echo "PORT=${{ vars.PORT }}" >> production.env
35-
test:
36-
runs-on: [self-hosted, prod]
37-
steps:
38-
- name: Run tests
39-
run: npm run test
40-
build:
41-
needs: [create_env, test]
42-
runs-on: [self-hosted, prod]
43-
steps:
44-
- name: Build website
45-
id: build-website
46-
run: npm run build
47-
deploy:
48-
needs: build
49-
runs-on: [self-hosted, prod]
50-
steps:
51-
- name: Run deployment
52-
run: NODE_ENV=production pm2 restart dist/main.js --name=events-api
5+
run-deployment:
6+
uses: ./.github/workflows/deployment.yml
7+
with:
8+
environment: "production"
9+
runner: "prod"
10+
env_file: "production.env"
11+
secrets: inherit

0 commit comments

Comments
 (0)