Format #33
Workflow file for this run
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: pipe | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
env: | |
DOCKERHUB_USERNAME: veetik | |
DOCKER_IMAGE: veetik/tasks-backend | |
FRONT_API_URL: https://tasks-api.veetik.com/api/v1 | |
FRONT_VAPID_PUBLIC_KEY: BMvRTtdBaxw8nWOkVbBOH_mC7sPHTkgVbbtrYqEek05-iupcxgkLUksERHvFsBIE5xytDaNzxeuLHTLu8FC-O-k | |
FRONT_DIR: ./frontend | |
BACK_DIR: ./backend | |
jobs: | |
determine_changes: | |
runs-on: ubuntu-latest | |
outputs: | |
backend: ${{ steps.changes.outputs.backend }} | |
frontend: ${{ steps.changes.outputs.frontend }} | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: dorny/paths-filter@0bc4621a3135347011ad047f9ecf449bf72ce2bd | |
id: changes | |
with: | |
filters: | | |
backend: | |
- 'backend/**' | |
frontend: | |
- 'frontend/**' | |
check_backend: | |
runs-on: ubuntu-latest | |
needs: [determine_changes] | |
if: needs.determine_changes.outputs.backend == 'true' | |
defaults: | |
run: | |
working-directory: ${{ env.BACK_DIR }} | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions-rust-lang/setup-rust-toolchain@1fbea72663f6d4c03efaab13560c8a24cfd2a7cc | |
with: | |
components: rustfmt | |
- name: check formatting | |
run: cargo fmt --check | |
build_and_push_backend_image: | |
runs-on: ubuntu-latest | |
needs: [determine_changes] | |
if: needs.determine_changes.outputs.backend == 'true' | |
steps: | |
- uses: actions/checkout@v4 | |
- name: set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: set up docker buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: login to docker hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ env.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: docker meta | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ env.DOCKER_IMAGE }} | |
tags: | | |
type=sha | |
type=ref,event=branch | |
type=ref,event=pr | |
- name: build and push docker image | |
uses: docker/build-push-action@v5 | |
with: | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
context: ${{ env.BACK_DIR }} | |
platforms: linux/amd64 | |
cache-from: type=registry,ref=${{ env.DOCKER_IMAGE }}:buildcache | |
cache-to: type=registry,ref=${{ env.DOCKER_IMAGE }}:buildcache,mode=max | |
push_prod_backend_image: | |
runs-on: ubuntu-latest | |
needs: [build_and_push_backend_image] | |
if: github.event_name != 'pull_request' | |
environment: prod | |
steps: | |
- uses: actions/checkout@v4 | |
- name: set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: set up docker buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: login to docker hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ env.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: docker meta | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ env.DOCKER_IMAGE }} | |
tags: prod | |
- name: build and push docker image | |
uses: docker/build-push-action@v5 | |
with: | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
context: ${{ env.BACK_DIR }} | |
platforms: linux/amd64 | |
cache-from: type=registry,ref=${{ env.DOCKER_IMAGE }}:buildcache | |
cache-to: type=registry,ref=${{ env.DOCKER_IMAGE }}:buildcache,mode=max | |
deploy_backend: | |
runs-on: ubuntu-latest | |
needs: [push_prod_backend_image] | |
environment: prod | |
steps: | |
- name: update deployment | |
uses: appleboy/ssh-action@029f5b4aeeeb58fdfe1410a5d17f967dacf36262 | |
with: | |
host: ${{ secrets.SSH_HOST }} | |
username: ${{ secrets.SSH_USER }} | |
key: ${{ secrets.SSH_KEY }} | |
port: ${{ secrets.SSH_PORT }} | |
script: | | |
cd ~/tasks && \ | |
docker rollout -f ./docker-compose.yml backend | |
check_frontend: | |
runs-on: ubuntu-latest | |
needs: [determine_changes] | |
if: needs.determine_changes.outputs.frontend == 'true' | |
defaults: | |
run: | |
working-directory: ${{ env.FRONT_DIR }} | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: oven-sh/setup-bun@v1 | |
- name: install | |
run: bun install | |
- name: check formatting | |
run: bun run formatcheck | |
- name: typecheck | |
run: bun run typecheck | |
- name: lint | |
run: bun run lint | |
- name: build | |
run: bun run build | |
deploy_frontend: | |
runs-on: ubuntu-latest | |
needs: [check_frontend] | |
environment: prod | |
if: github.event_name != 'pull_request' | |
defaults: | |
run: | |
working-directory: ${{ env.FRONT_DIR }} | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: oven-sh/setup-bun@v1 | |
- name: install | |
run: bun install | |
- name: build | |
run: bun run build | |
env: | |
VITE_APP_API_URL: ${{ env.FRONT_API_URL }} | |
VITE_APP_VAPID_PUBLIC_KEY: ${{ env.FRONT_VAPID_PUBLIC_KEY }} | |
- name: deploy frontend | |
run: bun run deploy | |
env: | |
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} |