-
Notifications
You must be signed in to change notification settings - Fork 0
84 lines (71 loc) · 2.76 KB
/
publish.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
name: publish
on:
workflow_call:
inputs:
docker_files_name:
description: Dockerfile
required: true
type: string
image_name:
description: Docker image
required: true
type: string
version_substr:
description: Version substring
required: true
type: string
env:
VERSION: ${{ vars.VERSION }}
P4NAME: ${{ vars.P4NAME }}
P4PORT: ${{ vars.P4PORT }}
P4USER: ${{ secrets.P4USER }}
P4PASSWD: ${{ secrets.P4PASSWD }}
P4HOME: ${{ vars.P4HOME }}
P4ROOT: ${{ vars.P4HOME }}/${{ vars.P4NAME }}
CASE_INSENSITIVE: ${{ vars.CASE_INSENSITIVE }}
IMAGE_NAME: ${{ inputs.image_name }}
jobs:
# Push image to GitHub Packages.
# See also https://docs.docker.com/docker-hub/builds/
# TAG_SUFFIX="nightly-$(date +'%Y%m%d')"
publish:
# Ensure test job passes before pushing image.
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Build image
run: |
docker build \
-t ${{ inputs.image_name }} \
--build-arg VERSION=$VERSION \
--build-arg P4NAME=$P4NAME \
--build-arg P4PORT=$P4PORT \
--build-arg P4USER=$P4USER \
--build-arg P4PASSWD=$P4PASSWD \
--build-arg P4HOME=$P4HOME \
--build-arg P4ROOT=$P4ROOT \
--build-arg CASE_INSENSITIVE=$CASE_INSENSITIVE \
-f ./build/${{ inputs.docker_files_name }} ./build
- name: Log into registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Set current datetime as env variable
env:
TZ: 'Asia/Tokyo'
run: echo "CURRENT_DATETIME=$(date +'%Y%m%d')" >> $GITHUB_ENV
- name: Push image
run: |
IMAGE_ID=ghcr.io/${{ github.repository }}/${{ inputs.image_name }}
# Convert to lowercase.
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
# If the event that triggered this workflow is a schedule event, then tag the image as "nightly".
TAG_SUFFIX=""
if [ "${{ github.event_name }}" == "schedule" ]; then
TAG_SUFFIX="nightly"
docker tag ${{ inputs.image_name }} $IMAGE_ID:${{ inputs.version_substr }}$TAG_SUFFIX
docker push $IMAGE_ID:${{ inputs.version_substr }}$TAG_SUFFIX
fi
TAG_SUFFIX="latest"
docker tag ${{ inputs.image_name }} $IMAGE_ID:$VERSION.${{ inputs.version_substr }}$GITHUB_RUN_NUMBER
docker push $IMAGE_ID:$VERSION.${{ inputs.version_substr }}$GITHUB_RUN_NUMBER
docker tag ${{ inputs.image_name }} $IMAGE_ID:${{ inputs.version_substr }}$TAG_SUFFIX
docker push $IMAGE_ID:${{ inputs.version_substr }}$TAG_SUFFIX