Backend: Add debug print to command #69
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and lint Backend | |
on: | |
push: | |
branches: main | |
paths: | |
- "backend/**/*.ts" | |
- "backend/**/*.js" | |
- "backend/**/*.json" | |
- "backend/yarn.lock" | |
- "backend/prisma/schema.prisma" | |
defaults: | |
run: | |
shell: bash | |
working-directory: ./backend | |
env: | |
APP_PATH: /opt/MTB | |
APP_NAME: bot | |
jobs: | |
format: | |
name: Run Prettier | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out Git repository | |
uses: actions/checkout@v4 | |
- name: Set up Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 22 | |
cache: "yarn" | |
cache-dependency-path: backend/yarn.lock | |
- name: Install Node.js dependencies | |
run: yarn --immutable --prefer-offline | |
- name: Running Prettier | |
run: yarn run format | |
- name: Check for changes and push changes to repository | |
if: always() | |
id: check_changes | |
run: | | |
if [[ -n $(git status --porcelain) ]]; then | |
git config --global user.email "${GITHUB_ACTOR_ID}+${GITHUB_ACTOR}@users.noreply.github.com" | |
git config --global user.name "${GITHUB_ACTOR}" | |
git add . | |
git commit -m "Fixed Prettier issues" | |
git pull origin main --rebase | |
git push | |
fi | |
linting: | |
name: Run linter | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out Git repository | |
uses: actions/checkout@v4 | |
- name: Set up Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 22 | |
cache: "yarn" | |
cache-dependency-path: backend/yarn.lock | |
- name: Install Node.js dependencies | |
run: yarn --immutable --prefer-offline | |
- name: Running ESLint | |
run: yarn run lint | |
- name: Check for changes and push changes to repository | |
if: always() | |
id: check_changes | |
run: | | |
if [[ -n $(git status --porcelain) ]]; then | |
git config --global user.email "${GITHUB_ACTOR_ID}+${GITHUB_ACTOR}@users.noreply.github.com" | |
git config --global user.name "${GITHUB_ACTOR}" | |
git add . | |
git commit -m "Fixed ESLint issues" | |
git pull origin main --rebase | |
git push | |
fi | |
test: | |
name: Run tests | |
runs-on: ubuntu-latest | |
needs: [linting, format] | |
# For now we need to allow tests to fail | |
continue-on-error: true | |
steps: | |
- name: Check out Git repository | |
uses: actions/checkout@v4 | |
- name: Set up Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 22 | |
cache: "yarn" | |
cache-dependency-path: backend/yarn.lock | |
- name: Install Node.js dependencies and generate prisma client | |
run: yarn --frozen-lockfile --prefer-offline && yarn run prisma:generate | |
- name: Run tests | |
run: yarn run test | |
build: | |
name: Build docker image | |
runs-on: ubuntu-latest | |
needs: [test] | |
steps: | |
- name: Check out Git repository | |
uses: actions/checkout@v4 | |
- name: Set up Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 22 | |
cache: "yarn" | |
cache-dependency-path: backend/yarn.lock | |
- name: Setup buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to Github Packages | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Set short git commit SHA | |
id: vars | |
run: | | |
calculatedSha=$(git rev-parse --short ${{ github.sha }}) | |
echo "COMMIT_SHORT_SHA=$calculatedSha" >> $GITHUB_ENV | |
- name: Build image and push to GitHub Container Registry | |
uses: docker/build-push-action@v3 | |
with: | |
context: "{{defaultContext}}:backend" | |
platforms: linux/amd64 | |
push: true | |
tags: ghcr.io/89q12/mega-transformers-bot:${{ env.COMMIT_SHORT_SHA }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
deploy: | |
name: Deploy | |
runs-on: ubuntu-latest | |
# Later also tests | |
needs: [build] | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Set short git commit SHA | |
id: vars | |
run: | | |
calculatedSha=$(git rev-parse --short ${{ github.sha }}) | |
echo "COMMIT_SHORT_SHA=$calculatedSha" >> $GITHUB_ENV | |
- name: Set up SSH key | |
run: | | |
env | |
mkdir -p ~/.ssh | |
echo "${{ secrets.ARTIFACT_SSH_KEY }}" > ~/.ssh/id_rsa | |
chmod 600 ~/.ssh/id_rsa | |
ssh-keyscan -p 22 ${{ secrets.ARTIFACT_HOST }} >> ~/.ssh/known_hosts | |
- name: Deploy to server | |
run: | | |
ssh -i ~/.ssh/id_rsa -v -o StrictHostKeyChecking=no ${{ secrets.SSH_USER }}@${{ secrets.ARTIFACT_HOST }} <<'ENDSSH' | |
cd ${{ env.APP_PATH }} | |
sed -E -i'' "s/(.*mega-transformers-bot:).*/\1${{ env.COMMIT_SHORT_SHA }}/" 'docker-compose.yml' | |
docker compose pull ${{ env.APP_NAME }} | |
docker compose up -d | |
ENDSSH | |
docs: | |
name: Build and deploy documentation | |
runs-on: ubuntu-latest | |
# Reasoning: We dont want to deploy docs of broken code, therefore we depend on tests | |
needs: [test] | |
steps: | |
- name: Check out Git repository | |
uses: actions/checkout@v4 | |
- name: Set up Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 22 | |
cache: "yarn" | |
cache-dependency-path: backend/yarn.lock | |
- name: Install Node.js dependencies | |
run: yarn --immutable --prefer-offline | |
- name: Generate documentation | |
run: yarn run docs | |
- name: Deploy documentation | |
uses: peaceiris/actions-gh-pages@v3 | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
publish_dir: ./backend/docs | |
publish_branch: gh-pages |