|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + pull_request: |
| 7 | + |
| 8 | +env: |
| 9 | + # app |
| 10 | + APP_PORT: 80 |
| 11 | + APP_ENV: 'development' |
| 12 | + APP_URL: 'localhost' |
| 13 | + |
| 14 | + # redis |
| 15 | + REDIS_HOST: 'redis' |
| 16 | + REDIS_PORT: 6379 |
| 17 | + REDIS_PASSWORD: 'password' |
| 18 | + |
| 19 | + # database |
| 20 | + DB_PORT: 5432 |
| 21 | + DB_HOST: 'postgres' |
| 22 | + DB_USERNAME: 'username' |
| 23 | + DB_PASSWORD: 'password' |
| 24 | + DB_DATABASE: 'database' |
| 25 | + |
| 26 | + # email |
| 27 | + EMAIL_HOST: 'mailhot' |
| 28 | + EMAIL_PORT: 1025 |
| 29 | + EMAIL_ALIAS: 'mail@jaw.dev' |
| 30 | + EMAIL_AUTH_EMAIL: 'name@email.com' |
| 31 | + EMAIL_AUTH_PASS: 'password' |
| 32 | + |
| 33 | + # twilio |
| 34 | + TWILIO_ACCOUNT_SID: '' |
| 35 | + TWILIO_AUTH_TOKEN: '' |
| 36 | + TWILIO_FROM_PHONE_NUMBER: '' |
| 37 | + TWILIO_PHONE_NUMBER: '' |
| 38 | + |
| 39 | +jobs: |
| 40 | + test: |
| 41 | + name: Unit tests |
| 42 | + runs-on: ubuntu-latest |
| 43 | + |
| 44 | + strategy: |
| 45 | + matrix: |
| 46 | + node-version: [22.x] |
| 47 | + |
| 48 | + steps: |
| 49 | + - uses: actions/checkout@v3 |
| 50 | + - name: Use Node.js ${{ matrix.node-version }} |
| 51 | + uses: actions/setup-node@v3 |
| 52 | + with: |
| 53 | + node-version: ${{ matrix.node-version }} |
| 54 | + cache: 'npm' |
| 55 | + |
| 56 | + - name: Create .env file from .env.example |
| 57 | + run: cp .env.example .env |
| 58 | + |
| 59 | + - name: Install dependencies |
| 60 | + run: npm i |
| 61 | + |
| 62 | + - name: Test codes |
| 63 | + run: npm run test:coverage |
| 64 | + |
| 65 | + lint: |
| 66 | + name: ESLint |
| 67 | + runs-on: ubuntu-latest |
| 68 | + |
| 69 | + strategy: |
| 70 | + matrix: |
| 71 | + node-version: [22.x] |
| 72 | + |
| 73 | + steps: |
| 74 | + - uses: actions/checkout@v3 |
| 75 | + - name: Use Node.js ${{ matrix.node-version }} |
| 76 | + uses: actions/setup-node@v3 |
| 77 | + with: |
| 78 | + node-version: ${{ matrix.node-version }} |
| 79 | + cache: 'npm' |
| 80 | + |
| 81 | + - name: Install dependencies |
| 82 | + run: npm i |
| 83 | + |
| 84 | + - name: Lint codes |
| 85 | + run: npm run lint |
| 86 | + |
| 87 | + format: |
| 88 | + needs: [lint, test] |
| 89 | + name: Prettier format |
| 90 | + runs-on: ubuntu-latest |
| 91 | + |
| 92 | + permissions: |
| 93 | + contents: write |
| 94 | + |
| 95 | + strategy: |
| 96 | + matrix: |
| 97 | + node-version: [22.x] |
| 98 | + |
| 99 | + steps: |
| 100 | + - uses: actions/checkout@v3 |
| 101 | + - name: Use Node.js ${{ matrix.node-version }} |
| 102 | + uses: actions/setup-node@v3 |
| 103 | + with: |
| 104 | + node-version: ${{ matrix.node-version }} |
| 105 | + cache: 'npm' |
| 106 | + |
| 107 | + - name: Install dependencies |
| 108 | + run: npm i |
| 109 | + |
| 110 | + - name: Format codes |
| 111 | + run: npm run format |
| 112 | + |
| 113 | + - name: Commit changes |
| 114 | + uses: stefanzweifel/git-auto-commit-action@v4 |
| 115 | + with: |
| 116 | + commit_message: 'style: format codes' |
| 117 | + env: |
| 118 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 119 | + |
| 120 | + # deploy: |
| 121 | + # needs: [test, lint, format] |
| 122 | + # name: Deploy to Production |
| 123 | + # runs-on: ubuntu-latest |
| 124 | + # if: github.event_name == 'push' && github.ref == 'refs/heads/main' |
| 125 | + |
| 126 | + # environment: |
| 127 | + # name: production |
| 128 | + # url: https://commit.jaw.dev/ |
| 129 | + |
| 130 | + # steps: |
| 131 | + # - name: Check out repository |
| 132 | + # uses: actions/checkout@v3 |
| 133 | + |
| 134 | + # - name: Set up Docker Buildx |
| 135 | + # uses: docker/setup-buildx-action@v2 |
| 136 | + |
| 137 | + # - name: Login to Container Registry |
| 138 | + # uses: docker/login-action@v2 |
| 139 | + # with: |
| 140 | + # registry: ghcr.io |
| 141 | + # username: ${{ github.repository_owner }} |
| 142 | + # password: ${{ secrets.GH_TOKEN }} |
| 143 | + |
| 144 | + # - name: Preset Image Name |
| 145 | + # run: echo "IMAGE_URL=$(echo ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:$(echo ${{ github.sha }} | cut -c1-7) | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV |
| 146 | + |
| 147 | + # - name: Build and push Docker Image |
| 148 | + # uses: docker/build-push-action@v4 |
| 149 | + # with: |
| 150 | + # context: . |
| 151 | + # file: ./Dockerfile.prod |
| 152 | + # push: true |
| 153 | + # tags: ${{ env.IMAGE_URL }} |
| 154 | + |
| 155 | + # - name: Deploy Image to Server |
| 156 | + # uses: caprover/deploy-from-github@v1.1.2 |
| 157 | + # with: |
| 158 | + # server: '${{ secrets.CAPROVER_SERVER }}' |
| 159 | + # app: '${{ secrets.APP_NAME }}' |
| 160 | + # token: '${{ secrets.APP_TOKEN }}' |
| 161 | + # image: ${{ env.IMAGE_URL }} |
0 commit comments