|
| 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 |
0 commit comments