mirror of
https://github.com/HangarMC/Hangar.git
synced 2024-12-21 06:51:19 +08:00
162 lines
4.8 KiB
YAML
162 lines
4.8 KiB
YAML
name: Deploy
|
|
|
|
on:
|
|
# allow manual dispatch
|
|
workflow_dispatch:
|
|
# run on PRs
|
|
pull_request:
|
|
# run on pushes to master
|
|
push:
|
|
branches:
|
|
- master
|
|
- staging
|
|
|
|
concurrency:
|
|
group: ${{ github.ref }}
|
|
cancel-in-progress: true
|
|
|
|
env:
|
|
REGISTRY: ghcr.io
|
|
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
|
|
env:
|
|
CI: true
|
|
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v3
|
|
with:
|
|
submodules: true
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v2
|
|
|
|
- name: Get timestamp
|
|
id: timestamp
|
|
run: echo "timestamp=$(date +%s)" >> $GITHUB_OUTPUT
|
|
|
|
- name: Set up JDK
|
|
uses: actions/setup-java@v3
|
|
with:
|
|
java-version: 17
|
|
distribution: temurin
|
|
|
|
- name: Set up Node
|
|
uses: actions/setup-node@v3
|
|
with:
|
|
node-version: '16'
|
|
|
|
- name: Set up pnpm
|
|
uses: pnpm/action-setup@v2
|
|
with:
|
|
version: 7
|
|
|
|
- name: Cache Maven Deps
|
|
uses: actions/cache@v3
|
|
with:
|
|
path: $GITHUB_WORKSPACE/.m2/repository
|
|
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
|
|
restore-keys: |
|
|
${{ runner.os }}-maven-
|
|
|
|
- name: Cache pnpm
|
|
uses: actions/cache@v3
|
|
with:
|
|
path: "~/.pnpm-store"
|
|
key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }}
|
|
restore-keys: |
|
|
${{ runner.os }}-pnpm-
|
|
|
|
- name: Build backend
|
|
working-directory: backend
|
|
run: mvn --batch-mode --errors --fail-at-end --show-version --no-transfer-progress -Dmaven.repo.local=$GITHUB_WORKSPACE/.m2/repository install
|
|
|
|
- name: Install frontend deps
|
|
run: (cd frontend && pnpm install --frozen-lockfile)
|
|
|
|
- name: Set environment for branch
|
|
run: |
|
|
if [[ $GITHUB_REF == 'refs/heads/master' ]]; then
|
|
echo "BACKEND_DATA_HOST=https://hangar.papermc.io" >> $GITHUB_ENV
|
|
else
|
|
echo "BACKEND_DATA_HOST=https://hangar.papermc.dev" >> $GITHUB_ENV
|
|
fi
|
|
|
|
- name: Lint frontend
|
|
env:
|
|
DEBUG: "hangar:*"
|
|
run: (cd frontend && pnpm prep && pnpm lint:eslint)
|
|
|
|
# - name: Sync forth and back with crowdin
|
|
# uses: crowdin/github-action@1.4.0
|
|
# with:
|
|
# upload_sources: true
|
|
# download_translations: true
|
|
# push_translations: false
|
|
# create_pull_request: false
|
|
# skip_untranslated_strings: true
|
|
# config: 'crowdin.yml'
|
|
# crowdin_branch_name: master
|
|
# env:
|
|
# CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}
|
|
|
|
- name: Build frontend
|
|
env:
|
|
# keep these in sync with compose!
|
|
BACKEND_HOST: "http://hangar_backend:8080"
|
|
AUTH_HOST: "https://hangar-auth.papermc.dev"
|
|
PUBLIC_HOST: "https://hangar.papermc.dev"
|
|
DEBUG: "hangar:*"
|
|
run: (cd frontend && pnpm build)
|
|
|
|
- name: Login to registry
|
|
uses: docker/login-action@v2
|
|
with:
|
|
registry: ${{ env.REGISTRY }}
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Extract metadata (tags, labels) for Docker (frontend)
|
|
id: frontend-meta
|
|
uses: docker/metadata-action@v4
|
|
with:
|
|
images: ${{ env.REGISTRY }}/${{ github.repository }}/frontend
|
|
tags: |
|
|
type=sha,enable=true,format=short,prefix=${{ env.BRANCH_NAME }}-,suffix=-${{ steps.timestamp.outputs.timestamp }}
|
|
type=raw,value=latest,enable={{is_default_branch}}
|
|
|
|
- name: Build and push frontend Dockerfile
|
|
uses: docker/build-push-action@v3
|
|
with:
|
|
context: .
|
|
file: chart/dockerfiles/frontend/Dockerfile
|
|
tags: ${{ steps.frontend-meta.outputs.tags }}
|
|
labels: ${{ steps.frontend-meta.outputs.labels }}
|
|
push: true
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|
|
|
|
- name: Extract metadata (tags, labels) for Docker (backend)
|
|
id: backend-meta
|
|
uses: docker/metadata-action@v4
|
|
with:
|
|
images: ${{ env.REGISTRY }}/${{ github.repository }}/backend
|
|
tags: |
|
|
type=sha,enable=true,format=short,prefix=${{ env.BRANCH_NAME }}-,suffix=-${{ steps.timestamp.outputs.timestamp }}
|
|
type=raw,value=latest,enable={{is_default_branch}}
|
|
|
|
- name: Build and push backend Dockerfile
|
|
uses: docker/build-push-action@v3
|
|
with:
|
|
context: .
|
|
file: chart/dockerfiles/backend/Dockerfile
|
|
tags: ${{ steps.backend-meta.outputs.tags }}
|
|
labels: ${{ steps.backend-meta.outputs.labels }}
|
|
push: true
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|