-
Notifications
You must be signed in to change notification settings - Fork 3
77 lines (66 loc) · 2.62 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
name: Publish OCR-D Monitor
on:
workflow_dispatch:
inputs:
checkout-ref:
description: The branch, tag or SHA to checkout. Otherwise, uses the default branch.
image-tag:
description: Tag name of Docker image
default: 'latest'
env:
IMAGE_NAME: ghcr.io/${{ github.repository }}
jobs:
build-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout without input reference (default)
uses: actions/checkout@v3
if: github.event.inputs.checkout-ref == ''
- name: Checkout input reference ${{ github.event.inputs.checkout-ref }}
uses: actions/checkout@v3
if: github.event.inputs.checkout-ref != ''
with:
ref: ${{ github.event.inputs.checkout-ref }}
- name: Determine environment variables
run: |
date -u +"build_date=%Y-%m-%dT%H:%M:%SZ" >> $GITHUB_ENV
LOCAL_VSC_REF=`git rev-parse --short HEAD`
echo "vcs_ref=$LOCAL_VSC_REF" >> $GITHUB_ENV
echo "cache_key=${{ github.event.inputs.image-tag }}-$LOCAL_VSC_REF" >> $GITHUB_ENV # (input image-tag - vcs_ref)
echo "$LOCAL_VSC_REF" > /tmp/${{ github.event.inputs.image-tag }}-vcs-ref # temporary file to fill cache
- name: Get cache key "${{ env.cache_key }}"
uses: actions/cache/restore@v3
id: cache
with:
path: /tmp/${{ github.event.inputs.image-tag }}-vcs-ref
key: ${{ env.cache_key }}
lookup-only: true
- # Activate cache export feature to reduce build time of images
name: Set up Docker Buildx
if: steps.cache.outputs.cache-hit != 'true'
uses: docker/setup-buildx-action@v2
- name: Login to GitHub Container Registry
if: steps.cache.outputs.cache-hit != 'true'
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build the OCR-D Monitor image "${{ env.IMAGE_NAME }}:${{ github.event.inputs.image-tag }}" and deploy to GitHub Container Repository
if: steps.cache.outputs.cache-hit != 'true'
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ env.IMAGE_NAME }}:${{ github.event.inputs.image-tag }}
build-args: |
BUILD_DATE=${{ env.build_date }}
VCS_REF=${{ env.vcs_ref }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Save cache key "${{ env.cache_key }}"
uses: actions/cache/save@v3
if: steps.cache.outputs.cache-hit != 'true'
with:
path: /tmp/${{ github.event.inputs.image-tag }}-vcs-ref
key: ${{ env.cache_key }}