Skip to content

Convert Yosys fork into Yosys plugin plus other cleanup #36

Convert Yosys fork into Yosys plugin plus other cleanup

Convert Yosys fork into Yosys plugin plus other cleanup #36

name: Build Docker image, format check, and run tests
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@v3
- name: Log in to the Container registry
uses: docker/login-action@v2
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' }}
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@v2
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@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Pull image
run: docker pull ${{ env.IMAGE_TAG }}
- name: Rust format check
run: docker run ${{ env.IMAGE_TAG }} cargo fmt --manifest-path ./Cargo.toml -- --check