Build, Test, Check Format #497
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: Build, Test, Check Format | |
on: | |
push: | |
branches: [main] | |
pull_request: | |
branches: [main] | |
# Run at 4am PT each day. | |
schedule: | |
- cron: "0 11 * * *" | |
# Allow manual trigger. | |
workflow_dispatch: | |
inputs: | |
no-cache: | |
type: boolean | |
description: use --no-cache flag on docker build. 'true' turns on --no-cache. | |
env: | |
REGISTRY: ghcr.io | |
# Can't use ${{ env.REGISTRY }} here, but would like to, so that we' don't | |
# repeat ghcr.io. | |
IMAGE_TAG: ghcr.io/${{ github.repository }}:sha-${{ github.sha }} | |
concurrency: | |
# Cancel in-progress runs for branches other than main. | |
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | |
cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} | |
jobs: | |
# Job which cleans up GitHub Actions workspace. This is only needed when | |
# running on self-hosted runners. | |
# | |
# TODO(@gussmith23) It would be nice if this wasn't necessary. We could use | |
# this: https://docs.github.com/en/actions/hosting-your-own-runners/running-scripts-before-or-after-a-job | |
# cleaner: | |
# runs-on: self-hosted | |
# steps: | |
# - name: Clean up previous runs | |
# run: rm -rf "${{ github.workspace }}" | |
build-and-push-image: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
submodules: recursive | |
token: ${{ secrets.LAKEROAD_PRIVATE_PAT }} | |
- name: Log in to the Container registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
# If we want to do this more cleanly, we can use metadata-action. | |
# - name: Extract metadata (tags, labels) for Docker | |
# id: meta | |
# uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 | |
# with: | |
# images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
- name: Docker Setup Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
push: true | |
tags: ${{ env.IMAGE_TAG }} | |
cache-to: type=gha,mode=max | |
cache-from: type=gha | |
no-cache: ${{ github.event.inputs.no-cache == true }} | |
run-tests: | |
runs-on: ubuntu-latest | |
needs: [build-and-push-image, | |
# Needed if we switch back to self-hosted. | |
# cleaner, | |
] | |
steps: | |
- name: Log in to the Container registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Pull image | |
run: docker pull ${{ env.IMAGE_TAG }} | |
- name: Run tests | |
run: docker run ${{ env.IMAGE_TAG }} bash run-tests.sh | |
check-format: | |
runs-on: ubuntu-latest | |
needs: build-and-push-image | |
steps: | |
- name: Log in to the Container registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Pull image | |
run: docker pull ${{ env.IMAGE_TAG }} | |
- name: Project-wide formatting check | |
run: | | |
docker run ${{ env.IMAGE_TAG }} \ | |
bash -c './fmt.sh && git status && [ -z "$(git status --porcelain)" ]' | |
- name: cargo clippy | |
run: | | |
docker run ${{ env.IMAGE_TAG }} \ | |
bash -c 'cargo clippy -- --no-deps --deny warnings' |