From 57700cd6f4607b9d1105f71cec32e78b3a33d638 Mon Sep 17 00:00:00 2001
From: Rishi Kumar <rsi.dev17@gmail.com>
Date: Thu, 24 Oct 2024 03:36:41 +0530
Subject: [PATCH] ci: Add .github config

---
 .github/ISSUE_TEMPLATE/bug_report.md          | 32 ++++++++
 .github/workflows/bot-automerge.yaml          | 17 ++++
 .../workflows/cleanup-after-pr-closed.yaml    | 17 ++++
 .github/workflows/fmt.yml                     | 15 ++++
 .github/workflows/tilt.yaml                   | 79 +++++++++++++++++++
 5 files changed, 160 insertions(+)
 create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md
 create mode 100644 .github/workflows/bot-automerge.yaml
 create mode 100644 .github/workflows/cleanup-after-pr-closed.yaml
 create mode 100644 .github/workflows/fmt.yml
 create mode 100644 .github/workflows/tilt.yaml

diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md
new file mode 100644
index 0000000..9b1edd8
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/bug_report.md
@@ -0,0 +1,32 @@
+---
+name: Bug report
+about: Create a report to help us improve
+title: ''
+labels: ''
+assignees: ''
+
+---
+
+**Describe the bug**
+A clear and concise description of what the bug is.
+
+**To Reproduce**
+Steps to reproduce the behavior:
+1. Go to '...'
+2. Click on '....'
+3. Scroll down to '....'
+4. See error
+
+**Expected behavior**
+A clear and concise description of what you expected to happen.
+
+**Screenshots**
+If applicable, add screenshots to help explain your problem.
+
+**Environment (please complete the following information):**
+ - OS: [e.g. Ubuntu/Windows/MacOS]
+ - Environment type [e.g. AWS/GCP/Minikube]
+ - k8s version [e.g. v1.21]
+
+**Additional context**
+Add any other context about the problem here.
diff --git a/.github/workflows/bot-automerge.yaml b/.github/workflows/bot-automerge.yaml
new file mode 100644
index 0000000..3750c42
--- /dev/null
+++ b/.github/workflows/bot-automerge.yaml
@@ -0,0 +1,17 @@
+name: automerge
+on:
+  pull_request_review:
+    types:
+      - submitted
+jobs:
+  automerge:
+    runs-on: ubuntu-latest
+    steps:
+      - name: automerge
+        uses: "pascalgn/automerge-action@v0.15.6"
+        env:
+          GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
+          MERGE_LABELS: galoybot
+          MERGE_FORKS: false
+          MERGE_METHOD: squash
+          MERGE_REQUIRED_APPROVALS: 1
diff --git a/.github/workflows/cleanup-after-pr-closed.yaml b/.github/workflows/cleanup-after-pr-closed.yaml
new file mode 100644
index 0000000..3bce317
--- /dev/null
+++ b/.github/workflows/cleanup-after-pr-closed.yaml
@@ -0,0 +1,17 @@
+name: cleanup-after-pr-closed
+on:
+  pull_request:
+    types: [closed]
+jobs:
+  cancel-runs:
+    name: Cleanup after PR closed
+    runs-on: ubuntu-latest
+    timeout-minutes: 3
+    steps:
+      - name: Checkout
+        uses: actions/checkout@v2
+      - name: Cancel build runs
+        uses: styfle/cancel-workflow-action@0.12.0
+        with:
+          ignore_sha: true
+          workflow_id: tilt.yaml
diff --git a/.github/workflows/fmt.yml b/.github/workflows/fmt.yml
new file mode 100644
index 0000000..94b7d03
--- /dev/null
+++ b/.github/workflows/fmt.yml
@@ -0,0 +1,15 @@
+name: Check formatting
+on:
+  pull_request:
+    branches: [main]
+
+jobs:
+  fmt:
+    runs-on: ubuntu-latest
+    steps:
+    - name: Checkout code into workspace directory
+      uses: actions/checkout@v2
+    - name: Terraform fmt
+      uses: hashicorp/setup-terraform@v2
+    - run: terraform fmt -recursive .
+    - run: git diff --exit-code
diff --git a/.github/workflows/tilt.yaml b/.github/workflows/tilt.yaml
new file mode 100644
index 0000000..1ca73cd
--- /dev/null
+++ b/.github/workflows/tilt.yaml
@@ -0,0 +1,79 @@
+name: "Tilt CI"
+on:
+  pull_request:
+    branches: [ main ]
+jobs:
+  tilt-ci:
+    runs-on: self-hosted
+    steps:
+    - uses: actions/checkout@v4
+    - name: Login to Docker Hub
+      uses: docker/login-action@v3
+      with:
+        username: ${{ secrets.DOCKERHUB_USERNAME }}
+        password: ${{ secrets.DOCKERHUB_TOKEN }}
+    - uses: AbsaOSS/k3d-action@v2
+      name: "Create Single Cluster"
+      with:
+        cluster-name: "k3s-default"
+        k3d-version: v5.7.4
+        args: >-
+          --image rancher/k3s:v1.30.4-k3s1
+          -v "$(pwd):/charts"
+          --k3s-arg --disable=traefik@server:0
+          --k3s-arg --disable=servicelb@server:0
+    - name: Tilt CI
+      run: |
+        pushd dev
+        for i in {1..5}; do
+          echo "Tilt CI attempt $i"
+          nix develop -c tilt ci && exit 0 || sleep 60
+        done
+        exit 1
+    - name: Galoy Smoketest
+      run: |
+        pushd dev
+        kubectl -n galoy-dev-smoketest exec smoketest -- bash -c "cd /charts/ci/tasks && \
+          CHART=galoy ./dev-smoketest-settings.sh && \
+          ./galoy-smoketest.sh && \
+          rm -rf smoketest-settings"
+    - name: Bitcoin Smoketest
+      run: |
+        pushd dev
+        kubectl -n galoy-dev-smoketest exec smoketest -- bash -c "cd /charts/ci/tasks && \
+          CHART=bitcoind ./dev-smoketest-settings.sh && \
+          ./bitcoind-smoketest.sh regtest && \
+          rm -rf smoketest-settings"
+    - name: LND Smoketest
+      run: |
+        pushd dev
+        kubectl -n galoy-dev-smoketest exec smoketest -- bash -c "cd /charts/ci/tasks && \
+          CHART=lnd ./dev-smoketest-settings.sh && \
+          ./lnd-smoketest.sh && \
+          rm -rf smoketest-settings"
+    - name: Monitoring Smoketest
+      run: |
+        pushd dev
+        kubectl -n galoy-dev-smoketest exec smoketest -- bash -c "cd /charts/ci/tasks && \
+          CHART=monitoring ./dev-smoketest-settings.sh && \
+          ./monitoring-smoketest.sh && \
+          rm -rf smoketest-settings"
+    - name: Galoy Pay Smoketest
+      run: |
+        pushd dev
+        kubectl -n galoy-dev-smoketest exec smoketest -- bash -c "cd /charts/ci/tasks && \
+          CHART=galoy-pay ./dev-smoketest-settings.sh && \
+          ./galoy-pay-smoketest.sh && \
+          rm -rf smoketest-settings"
+    - name: Mempool smoketest
+      run: |
+        pushd dev
+        kubectl -n galoy-dev-smoketest exec smoketest -- bash -c "cd /charts/ci/tasks && \
+          CHART=mempool ./dev-smoketest-settings.sh && \
+          ./mempool-smoketest.sh && \
+          rm -rf smoketest-settings"
+    - name: Clean Up
+      if: always()
+      run: |
+        rm -rf ci/tasks/smoketest-settings
+        k3d cluster delete --all