-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
231 additions
and
125 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
name: 'Setup environment' | ||
description: 'This action will checkout code, setup node and retrieve the cache' | ||
|
||
inputs: | ||
skip-install: | ||
description: 'Skip Install1' | ||
required: false | ||
outputs: | ||
version: | ||
description: 'Project version' | ||
value: ${{ steps.version.outputs.version }} | ||
cache-hit: | ||
description: 'A boolean value to indicate an exact match was found for the key' | ||
value: ${{ steps.yarn-cache.outputs.cache-hit }} | ||
|
||
runs: | ||
using: composite | ||
steps: | ||
- name: Set Yarn version | ||
shell: bash | ||
run: yarn set version 4.5.1 | ||
|
||
- name: Install NodeJs 22 | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 22 | ||
|
||
- name: Derive appropriate SHAs for base and head for `nx affected` commands | ||
uses: nrwl/nx-set-shas@v3 | ||
|
||
- name: Get yarn cache directory path | ||
id: yarn-cache-dir-path | ||
shell: bash | ||
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT | ||
|
||
- name: Restore yarn cache | ||
uses: actions/cache@v4 | ||
id: yarn-cache | ||
if: inputs.skip-install != 'true' | ||
with: | ||
path: | | ||
./.yarn/install-state.gz | ||
~/.cache/Cypress | ||
${{ steps.yarn-cache-dir-path.outputs.dir }} | ||
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }} | ||
restore-keys: ${{ runner.os }}-yarn- | ||
|
||
- name: Yarn Install | ||
shell: bash | ||
run: yarn install --immutable | ||
if: inputs.skip-install != 'true' | ||
|
||
- name: Retrieve commit message | ||
id: commit_message | ||
shell: bash | ||
run: | | ||
echo "commit_message=$(git log --no-merges -1 --pretty=format:"%s")" >> $GITHUB_OUTPUT | ||
- name: Retrieve version | ||
id: version | ||
shell: bash | ||
run: | | ||
echo "version=$(node -e 'console.log(require("./package.json").version);')" >> $GITHUB_OUTPUT |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
name: Build & Deploy | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
|
||
concurrency: ${{ github.ref }} | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
permissions: write-all | ||
steps: | ||
- name: Check out code | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- uses: ./.github/actions/setup-environment | ||
id: setup | ||
|
||
- name: Lint | ||
run: yarn lint | ||
|
||
- name: Prettier | ||
run: yarn prettier | ||
|
||
- name: Generate Prisma Schema | ||
run: yarn prisma:generate | ||
|
||
- name: Build | ||
run: yarn build | ||
|
||
- name: Log in to the Container registry | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Build and push Dependencies Docker image | ||
uses: docker/build-push-action@v5 | ||
if: steps.setup.outputs.cache-hit != 'true' | ||
with: | ||
context: . | ||
file: docker/Dockerfile | ||
push: true | ||
tags: | | ||
ghcr.io/tun-judge/dependencies:${{ hashFiles('yarn.lock') }} | ||
ghcr.io/tun-judge/dependencies:latest | ||
- name: Run docker compose up | ||
if: false | ||
run: | | ||
docker compose -f docker-compose.test.yaml up -d app | ||
sleep 30s | ||
env: | ||
DEPENDENCIES_TAG: ${{ hashFiles('yarn.lock') }} | ||
|
||
- name: Run E2E tests | ||
if: false | ||
shell: bash | ||
run: yarn e2e | ||
|
||
- name: Run docker compose down | ||
if: false | ||
run: | | ||
docker compose -f docker-compose.test.yaml logs | ||
docker compose -f docker-compose.test.yaml down | ||
- name: Save Build Output | ||
uses: actions/cache/save@v4 | ||
with: | ||
path: dist/apps | ||
key: apps-${{ steps.setup.outputs.version }} | ||
|
||
deploy: | ||
runs-on: ubuntu-latest | ||
permissions: write-all | ||
if: startsWith(github.event.head_commit.message, 'release') | ||
needs: build | ||
steps: | ||
- name: Check out code | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- uses: ./.github/actions/setup-environment | ||
id: setup | ||
with: | ||
skip-install: 'true' | ||
|
||
- name: Restore Build Output | ||
uses: actions/cache/restore@v4 | ||
with: | ||
path: dist/apps | ||
key: apps-${{ steps.setup.outputs.version }} | ||
fail-on-cache-miss: true | ||
|
||
- name: Google Auth | ||
id: auth | ||
uses: google-github-actions/auth@v2 | ||
with: | ||
token_format: access_token | ||
workload_identity_provider: ${{ vars.WIF_PROVIDER }} | ||
service_account: ${{ vars.WIF_SERVICE_ACCOUNT }} | ||
|
||
- name: Log in to the Container registry | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Docker Auth | ||
id: docker-auth | ||
uses: docker/login-action@v3 | ||
with: | ||
username: oauth2accesstoken | ||
password: ${{ steps.auth.outputs.access_token }} | ||
registry: europe-west1-docker.pkg.dev | ||
|
||
- name: Build and push Server Docker image | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
file: docker/server/Dockerfile | ||
push: true | ||
tags: | | ||
ghcr.io/tunjudge/server:${{ steps.setup.outputs.version }} | ||
europe-west1-docker.pkg.dev/tun-judge-dev/docker/tun-judge-app:${{ steps.setup.outputs.version }} | ||
build-args: | | ||
DEPENDENCIES_TAG=${{ hashFiles('yarn.lock') }} | ||
- name: Build and push Judge Docker image | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
file: docker/judge/Dockerfile | ||
push: true | ||
tags: ghcr.io/tunjudge/judge:${{ steps.setup.outputs.version }} | ||
build-args: | | ||
DEPENDENCIES_TAG=${{ hashFiles('yarn.lock') }} | ||
- name: Deploy to Cloud Run | ||
id: deploy | ||
uses: google-github-actions/deploy-cloudrun@v2 | ||
with: | ||
image: europe-west1-docker.pkg.dev/tun-judge-dev/docker/tun-judge-app:${{ steps.setup.outputs.version }} | ||
service: tun-judge | ||
region: europe-west1 | ||
env_vars: | | ||
GOOGLE_PROJECT_ID=tun-judge-dev | ||
GOOGLE_STORAGE_ENABLED=true | ||
GOOGLE_STORAGE_BUCKET_NAME=tun-judge-files | ||
secrets: | | ||
SESSION_SECRET=SESSION_SECRET:latest | ||
DATABASE_URL=TUN_JUDGE_DATABASE_URL:latest | ||
DATABASE_DIRECT_URL=TUN_JUDGE_DATABASE_DIRECT_URL:latest | ||
REDIS_URL=TUN_JUDGE_REDIS_URL:latest | ||
- name: Show Output | ||
shell: bash | ||
run: echo ${{ steps.deploy.outputs.url }} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
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