diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..2f89742 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,95 @@ +name: web-ci + +on: + push: + branches: + - '**' + pull_request: + branches: + - dev + - main + +concurrency: + group: web-ci-${{ github.ref }} + cancel-in-progress: true + +jobs: + ci: + runs-on: ubuntu-latest + permissions: + contents: read + packages: read + outputs: + image_tag: ${{ steps.meta.outputs.image_tag }} + should_deploy: ${{ steps.meta.outputs.should_deploy }} + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup pnpm + uses: pnpm/action-setup@v4 + with: + version: 10.27.0 + + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: '20' + cache: 'pnpm' + + - name: Install + run: pnpm install --frozen-lockfile + + - name: Test + run: pnpm test --if-present + + - name: Build + run: pnpm build + + - name: Set deploy metadata + id: meta + shell: bash + run: | + if [[ "${GITHUB_EVENT_NAME}" == "push" && "${GITHUB_REF_NAME}" == "main" ]]; then + echo "should_deploy=true" >> "$GITHUB_OUTPUT" + echo "image_tag=main-${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT" + else + echo "should_deploy=false" >> "$GITHUB_OUTPUT" + echo "image_tag=" >> "$GITHUB_OUTPUT" + fi + + - name: Set up Docker Buildx + if: steps.meta.outputs.should_deploy == 'true' + uses: docker/setup-buildx-action@v3 + + - name: Login to Docker Hub + if: steps.meta.outputs.should_deploy == 'true' + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build and push image + if: steps.meta.outputs.should_deploy == 'true' + uses: docker/build-push-action@v6 + with: + context: . + file: ./Dockerfile + push: true + tags: | + ${{ secrets.DOCKERHUB_USERNAME }}/withrun-web:${{ steps.meta.outputs.image_tag }} + ${{ secrets.DOCKERHUB_USERNAME }}/withrun-web:main + + notify-infra: + if: needs.ci.outputs.should_deploy == 'true' + needs: ci + runs-on: ubuntu-latest + steps: + - name: Trigger infra deploy + uses: peter-evans/repository-dispatch@v3 + with: + token: ${{ secrets.INFRA_REPO_DISPATCH_TOKEN }} + repository: with-run/infra + event-type: deploy-web + client-payload: >- + {"service":"web","image":"${{ secrets.DOCKERHUB_USERNAME }}/withrun-web:${{ needs.ci.outputs.image_tag }}","sha":"${{ github.sha }}","source_repo":"${{ github.repository }}"} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index eb0abcf..21527ce 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,7 +10,6 @@ WORKDIR /app RUN ln -s /app/web/node_modules /app/node_modules COPY web ./web -COPY mobile/src/bridge ./mobile/src/bridge WORKDIR /app/web ARG VITE_MODE=production