Skip to content

Update dependencies, copy (#342) #89

Update dependencies, copy (#342)

Update dependencies, copy (#342) #89

Workflow file for this run

name: Deploy
on:
workflow_dispatch:
push:
branches: main
concurrency:
group: deploy-schedge
jobs:
server:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout Repository
uses: actions/checkout@v3
with:
lfs: true
- name: Set up Node + Yarn
uses: actions/setup-node@v3
with:
cache: 'yarn'
# https://nextjs.org/docs/advanced-features/ci-build-caching
- name: Cache NextJS Files
uses: actions/cache@v3
with:
path: |
${{ github.workspace }}/.next/cache
# Generate a new cache whenever packages or source files change.
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/yarn.lock') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
# If source files changed but packages didn't, rebuild from a prior cache.
restore-keys: |
${{ runner.os }}-nextjs-${{ hashFiles('**/yarn.lock') }}-
- name: Set up Java
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'adopt'
cache: 'gradle'
- name: Install JS Dependencies
run: yarn install --frozen-lockfile
- name: Compile Frontend
run: yarn export
- name: Set version
run: >
sed -i
"s/SCHEDGE DEVELOPMENT BUILD/$(git log --pretty=format:'%h' -n 1)/g"
"src/main/java/api/v1/Health.java"
- name: Compile Backend
run: yarn gradle jar
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v3
with:
context: .
file: src/build/Dockerfile
push: true
tags: ghcr.io/a1liu/schedge:latest
- name: Wait for Server to update
shell: bash
run: |
x=1
sha=$(git log --pretty=format:'%h' -n 1)
echo "SHA=$sha"
output=""
# Deploy updates are polled every 5 minutes
# 36 iterations at 10 seconds each = 6 minutes of time
while [[ $x -le 36 ]]; do
echo "Iteration: $x"
output=$(curl nyu.a1liu.com/api/stat 2> /dev/null)
echo " Received: $output"
if [[ "$output" =~ .*"$sha".* ]]; then
echo " Production is up to date"
exit 0
fi
echo " versions didn't match, sleeping for 10 seconds\\n"
sleep 10s
x=$(( $x + 1 ))
done
# Retried way too many times
exit 1
docker-compose:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout Repository
uses: actions/checkout@v3
with:
lfs: true
- name: Setup Git User
run: |
git config user.name github-actions
git config user.email github-actions@github.com
- name: Push to prod-config Branch
run: |
git --work-tree src/build/production add --all
git commit -m "Automatic deploy action run by github-actions"
git push origin HEAD:prod-config --force