From bba153e656b1d186f3f35c3db122fdce2ee4ee8b Mon Sep 17 00:00:00 2001 From: zkldi Date: Thu, 4 Apr 2024 15:52:54 +0100 Subject: [PATCH] ci: first attempt at general bits and bobs... Obviously given the state of github yaml-engineering there's no way I'm going to get this right on the first try but hey ho. things *should* work. --- .github/workflows/bot.yml | 37 +++++++++++ .github/workflows/common.yml | 38 ++++++++++++ .github/workflows/database-seeds.yml | 40 ++++++++++++ .github/workflows/github-bot.yml | 39 ++++++++++++ .github/workflows/server.yml | 93 ++++++++++++++++++++++++++++ 5 files changed, 247 insertions(+) create mode 100644 .github/workflows/bot.yml create mode 100644 .github/workflows/common.yml create mode 100644 .github/workflows/database-seeds.yml create mode 100644 .github/workflows/github-bot.yml create mode 100644 .github/workflows/server.yml diff --git a/.github/workflows/bot.yml b/.github/workflows/bot.yml new file mode 100644 index 000000000..e29714b73 --- /dev/null +++ b/.github/workflows/bot.yml @@ -0,0 +1,37 @@ +name: Bot CI/CD + +on: + push: + branches: + - "main" + paths: + - "bot/**" + - "common/**" + workflow_dispatch: + +jobs: + docker-push: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Docker Hub login + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_TOKEN }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Build and push + id: docker_build + uses: docker/build-push-action@v3 + with: + context: ./ + push: true + tags: ${{ secrets.DOCKER_USERNAME }}/tachi-bot:stable + file: ./Dockerfile.bot + cache-from: type=gha,scope=$GITHUB_REF_NAME-bot + cache-to: type=gha,mode=max,scope=$GITHUB_REF_NAME-bot diff --git a/.github/workflows/common.yml b/.github/workflows/common.yml new file mode 100644 index 000000000..3847b45de --- /dev/null +++ b/.github/workflows/common.yml @@ -0,0 +1,38 @@ +name: Common CI/CD + +on: + push: + branches: + - "main" + paths: + - "common/**" + pull_request: + branches: + - "main" + paths: + - "common/**" + workflow_dispatch: + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + + - uses: pnpm/action-setup@v2 + with: + version: 7.20.0 + + - uses: actions/setup-node@v3 + with: + node-version: 16 + cache: pnpm + + - name: Install dependencies + run: pnpm --filter tachi-common... --filter . install + + - name: Run Tests + run: pnpm --filter tachi-common test + env: + NODE_ENV: "test" diff --git a/.github/workflows/database-seeds.yml b/.github/workflows/database-seeds.yml new file mode 100644 index 000000000..52524fbc3 --- /dev/null +++ b/.github/workflows/database-seeds.yml @@ -0,0 +1,40 @@ +name: Database-Seeds CI/CD + +on: + push: + branches: + - "main" + paths: + - "database-seeds/**" + - "common/**" + pull_request: + branches: + - "main" + paths: + - "database-seeds/**" + - "common/**" + workflow_dispatch: + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + + - uses: pnpm/action-setup@v2 + with: + version: 7.20.0 + + - uses: actions/setup-node@v3 + with: + node-version: 16 + cache: pnpm + + - name: Install dependencies + run: pnpm --filter tachi-database-seeds-scripts... --filter . install + + - name: Run Tests + run: pnpm --filter tachi-database-seeds-scripts test + env: + NODE_ENV: "test" diff --git a/.github/workflows/github-bot.yml b/.github/workflows/github-bot.yml new file mode 100644 index 000000000..8672ed9be --- /dev/null +++ b/.github/workflows/github-bot.yml @@ -0,0 +1,39 @@ +name: GitHub Bot CI/CD + +on: + push: + branches: + - "main" + paths: + - "github-bot/**" + workflow_dispatch: + +jobs: + docker-push: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Docker Hub login + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_TOKEN }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Build and push + id: docker_build + uses: docker/build-push-action@v3 + with: + context: ./ + push: true + tags: ${{ secrets.DOCKER_USERNAME }}/tachi-gh-bot:stable + file: ./Dockerfile.ghbot + cache-from: type=gha,scope=$GITHUB_REF_NAME-github-bot + cache-to: type=gha,mode=max,scope=$GITHUB_REF_NAME-github-bot + + - name: Image digest + run: echo ${{ steps.docker_build.outputs.digest }} diff --git a/.github/workflows/server.yml b/.github/workflows/server.yml new file mode 100644 index 000000000..7024b5080 --- /dev/null +++ b/.github/workflows/server.yml @@ -0,0 +1,93 @@ +name: Server CI/CD + +on: + push: + branches: + - "main" + paths: + - "server/**" + - "common/**" + pull_request: + branches: + - "main" + paths: + - "server/**" + - "common/**" + workflow_dispatch: + +jobs: + test: + runs-on: ubuntu-latest + env: + NODE_ENV: "test" + steps: + - uses: actions/checkout@v3 + + - uses: pnpm/action-setup@v2 + with: + version: 7.20.0 + + - uses: actions/setup-node@v3 + with: + node-version: 16 + cache: pnpm + + - name: Install dependencies + run: pnpm --filter tachi-server... --filter . install + + - name: Lint code + run: pnpm --filter tachi-server lint + + - name: Typecheck code + run: pnpm --filter tachi-server typecheck + + # configure external dbs + - uses: supercharge/mongodb-github-action@1.4.1 + - uses: supercharge/redis-github-action@1.1.0 + + - name: Run tests + run: pnpm --filter tachi-server test + env: + NODE_ENV: "test" + PORT: 8080 + MONGO_URL: "127.0.0.1" + REDIS_URL: "127.0.0.1" + + docker-push: + runs-on: ubuntu-latest + needs: [test] + defaults: + run: + working-directory: ./server + if: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' }} + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Docker Hub login + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_TOKEN }} + + - name: Commit Hash + run: 'echo "SHORT_SHA=$(git rev-parse --short HEAD)" >> $GITHUB_ENV' + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Build and push + id: docker_build + uses: docker/build-push-action@v3 + with: + context: ./ + push: true + tags: ${{ secrets.DOCKER_USERNAME }}/tachi-server:${{ env.BRANCH_TAG }} + file: ./Dockerfile.server + build-args: | + COMMIT_HASH=${{ env.SHORT_SHA }} + cache-from: type=gha,scope=$GITHUB_REF_NAME-server + cache-to: type=gha,mode=max,scope=$GITHUB_REF_NAME-server + + - name: Image digest + run: echo ${{ steps.docker_build.outputs.digest }}