[deploy] Update frontend and Dockerfile #294
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: All | |
on: | |
push: | |
branches: [master] | |
pull_request: | |
branches: ["**"] | |
jobs: | |
# Check which files / paths have changed. | |
# We use this to inform whether we should run later jobs. | |
changes: | |
name: Determine changes | |
outputs: | |
backend: ${{ steps.filter.outputs.backend }} | |
frontend: ${{ steps.filter.outputs.frontend }} | |
build: ${{ steps.filter.outputs.build }} | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- uses: dorny/[email protected] | |
id: filter | |
with: | |
filters: '.github/filters.yml' | |
- name: Print changes | |
run: printf "Backend changed $BACK\nFrontend changed $FRONT\nBuild changed $BUILD\n" | |
env: | |
BACK: ${{ steps.filter.outputs.backend }} | |
FRONT: ${{ steps.filter.outputs.frontend }} | |
BUILD: ${{ steps.filter.outputs.build }} | |
# Ensure that the backend is styled. | |
backend_style: | |
name: Backend style check | |
needs: [changes] | |
if: needs.changes.outputs.backend == 'true' | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- run: rustup toolchain install stable --profile minimal --component rustfmt | |
- run: cargo fmt -- --check | |
# Ensure that the frontend is styled. | |
frontend_style: | |
name: Frontend style check | |
needs: [changes] | |
if: needs.changes.outputs.frontend == 'true' | |
defaults: | |
run: | |
working-directory: ui | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- uses: actions/[email protected] | |
with: | |
node-version: '15.6.0' | |
- run: yarn install | |
- run: yarn run style-check | |
# Run the backend tests. | |
backend_tests: | |
name: Backend tests | |
needs: [changes] | |
if: needs.changes.outputs.backend == 'true' | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- uses: actions-rs/toolchain@v1 | |
with: | |
toolchain: stable | |
default: true | |
override: true | |
- uses: actions-rs/cargo@v1 | |
with: | |
command: test | |
# Run the frontend tests. | |
frontend_tests: | |
name: Frontend tests | |
needs: [changes] | |
if: needs.changes.outputs.frontend == 'true' | |
defaults: | |
run: | |
working-directory: ui | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- uses: actions/[email protected] | |
with: | |
node-version: '15.6.0' | |
- uses: arduino/setup-protoc@master | |
with: | |
version: '3.14.0' | |
- run: yarn install | |
- run: cp ../src/types.proto . | |
- run: ./generate_types.sh | |
- run: yarn run tsc | |
- run: yarn run test | |
# If all the previous steps pass or are skipped due to there being no changes to | |
# warrant style checks / tests, build and publish the image. | |
build_image: | |
# The if condition here is pretty complicated. The conditions are: | |
# - This is a push. | |
# - Something changed in the `build` filter list. | |
# - If the backend changed, the backend style and tests must have passed. | |
# - If the frontend changed, the frontend style and tests must have passed. | |
# To make this step always run even if the previous `needs` were skipped, | |
# we have to use the `always()` function condition. See here for more information: | |
# https://github.community/t/semantics-of-using-job-needs-and-job-if-together/17557/3. | |
needs: [changes, backend_style, frontend_style, backend_tests, frontend_tests] | |
if: | | |
always() && | |
github.event_name == 'push' && | |
needs.changes.outputs.build == 'true' && ( | |
needs.changes.outputs.backend == 'false' || ( | |
needs.changes.outputs.backend == 'true' && | |
needs.backend_style.result == 'success' && | |
needs.backend_tests.result == 'success' | |
) | |
) && ( | |
needs.changes.outputs.frontend == 'false' || ( | |
needs.changes.outputs.frontend == 'true' && | |
needs.frontend_style.result == 'success' && | |
needs.frontend_tests.result == 'success' | |
) | |
) | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- uses: whoan/docker-build-with-cache-action@v5 | |
with: | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
registry: docker.pkg.github.com | |
image_name: team_heist_tactics |