Build and push latest image #6390
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 and push latest image | |
on: | |
push: | |
branches: | |
- main | |
- stable | |
schedule: | |
# We run it every 4 hours, starting at 02:15. | |
# Note that this will only update the 'latest' tag (not the 'stable' tag). | |
# Ideally, we would update the image every time the base image | |
# (p4lang/third-party) is updated, but we deem this good enough. | |
- cron: '15 2-23/4 * * *' # "At minute 15 past every 4th hour from 2 through 23." | |
jobs: | |
build: | |
if: ${{ github.repository == 'p4lang/PI' }} | |
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" | |
elif [[ "$GITHUB_REF" =~ "stable" ]]; then | |
TAG="stable" | |
else | |
echo "Invalid Github ref $GITHUB_REF" | |
exit 1 | |
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 | |
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: true | |
tags: p4lang/pi:${{ steps.get-tag.outputs.tag }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max |