Run checks #1946
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: Run checks | |
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: | |
# Set up SSH agent for cloning lakeroad-private. | |
- uses: webfactory/[email protected] | |
with: | |
ssh-private-key: ${{ secrets.LAKEROAD_PRIVATE_SSH_KEY }} | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
with: | |
submodules: true | |
- name: Log in to the Container registry | |
uses: docker/[email protected] | |
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@v2 | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v4 | |
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' }} | |
# This can be run on ubuntu-latest (i.e., on GitHub's provided runners), but | |
# it will be much slower. Specifically, our end-to-end tests using Verilator | |
# take advantage of the many threads on our machines, whereas the GitHub | |
# machines only have two threads. | |
# | |
# Perhaps we should run this on both? | |
run-tests: | |
runs-on: self-hosted | |
needs: [build-and-push-image, cleaner] | |
steps: | |
- name: Log in to the Container registry | |
uses: docker/[email protected] | |
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/[email protected] | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Pull image | |
run: docker pull ${{ env.IMAGE_TAG }} | |
- name: Format check | |
run: | | |
docker run ${{ env.IMAGE_TAG }} \ | |
bash -c './fmt.sh && git diff && [ -z "$(git status --porcelain)" ]' |