container-image #12517
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: container-image | |
on: | |
push: | |
branches: [main] | |
pull_request: | |
branches: [main] | |
merge_group: | |
branches: [main] | |
schedule: | |
# Ideally, we would update the image every time the base image | |
# (p4lang/behavioral-model) is updated, this is good enough. | |
# "At minute 15 past every 4th hour from midnight through 23." | |
- cron: "15 0-23/4 * * *" | |
# Cancel any preceding run on the pull request. | |
concurrency: | |
group: container-image-${{ github.event.pull_request.number || github.ref }} | |
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} | |
jobs: | |
build: | |
if: ${{ github.repository == 'p4lang/p4c' }} | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
submodules: recursive | |
- name: Determine Docker image tag | |
id: get-tag | |
shell: bash | |
run: | | |
TAG="" | |
if [[ "$GITHUB_REF" =~ "main" ]]; then | |
TAG="latest" | |
else | |
TAG=${GITHUB_REF////_} | |
fi | |
echo "Tag is $TAG" | |
echo "::set-output name=tag::$TAG" | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to DockerHub | |
if: ${{ github.event_name != 'pull_request' }} | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Build and push Docker image to registry | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
push: ${{ github.event_name != 'pull_request' }} | |
tags: p4lang/p4c:${{ steps.get-tag.outputs.tag }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max |