Skip to content

ci deploy

ci deploy #3

name: ci
on:
push:
branches:
- "main"
paths-ignore:
- "*.md"
pull_request:
branches:
- "main"
paths-ignore:
- "*.md"
jobs:
build_svelte:
name: Build and lint Svelte
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: '22.2.0'
check-latest: true
- name: yarn install
working-directory: ./svelte
run: yarn install --frozen-lockfile
- name: svelte-check
working-directory: ./svelte
run: yarn check
- name: lint
working-directory: ./svelte
run: yarn lint
- name: build
working-directory: ./svelte
run: yarn build
build_test_rust:
name: Build and test Rust code
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4
# Enable only if you use nektos/act
# - name: Install curl & build essential
# run: sudo apt-get update && sudo apt-get install -y curl build-essential
- uses: actions-rust-lang/[email protected]
- name: Install clippy
run: rustup update && rustup component add clippy
- name: Build
working-directory: ./rust
run: cargo build
- name: Run clippy
working-directory: ./rust
run: cargo clippy --all-targets --all-features
- name: Run tests
working-directory: ./rust
run: cargo test --all-targets --all-features
build_test_golang:
name: Build and test Golang code
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: 1.22.3
- name: Build
working-directory: ./golang
run: go build
- name: Run format check
working-directory: ./golang
run: gofmt -l .
- name: Run tests
working-directory: ./golang
run: go test ./...
build_and_publish:
name: Build and publish image
needs: [build_svelte, build_test_rust, build_test_golang]
if: github.event_name != 'pull_request'
permissions:
contents: read
packages: write
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Get commit short
id: vars
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
# platforms: linux/amd64
push: true
tags: |
ghcr.io/tbmc/brainfuck_interpreter:latest
ghcr.io/tbmc/brainfuck_interpreter:${{ steps.vars.outputs.sha_short }}
deploy:
name: Deploy to server
runs-on: ubuntu-22.04
needs: [build_and_publish]
if: github.event_name != 'pull_request'
steps:
- name: Run docker pull and up commands
# If using nektos/act, use appleboy/[email protected]
uses: appleboy/[email protected]
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USERNAME }}
password: ${{ secrets.SERVER_PASSWORD }}
port: ${{ secrets.SERVER_PORT || 22 }}
script: |
cd ${{ secrets.SERVER_FOLDER_PATH }}
docker compose pull ${{ secrets.DOCKER_SERVICE_NAME }}
docker compose up -d ${{ secrets.DOCKER_SERVICE_NAME }}