forked from p4lang/p4c
-
Notifications
You must be signed in to change notification settings - Fork 0
54 lines (51 loc) · 1.59 KB
/
ci-container-image.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
name: container-image
on:
push:
branches: [ main ]
pull_request:
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@v3
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@v2
- name: Login to DockerHub
if: ${{ github.event_name != 'pull_request' }}
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push Docker image to registry
uses: docker/build-push-action@v3
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