forked from dmitryn/GitStats
-
Notifications
You must be signed in to change notification settings - Fork 1
97 lines (84 loc) · 2.9 KB
/
workflow.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
85
86
87
88
89
90
91
92
93
94
95
96
97
name: Build
on:
push:
branches:
- main
tags:
- v[0-9]+.[0-9]+.[0-9]+**
pull_request:
workflow_dispatch:
schedule:
- cron: '30 0 * * 1'
jobs:
build:
name: Build
runs-on: ubuntu-22.04
timeout-minutes: 10
env:
docker_image: jk4ger/gitstats
docker_cache_in: /tmp/.buildx-cache
docker_cache_out: /tmp/.buildx-cache-new
is_publish: ${{((github.event_name == 'push' && github.ref_type == 'tag') && 'true') || 'false'}}
steps:
- name: Checkout sources
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{secrets.DOCKER_USERNAME}}
password: ${{secrets.DOCKER_PASSWORD}}
- name: Determine metadata for Docker image
id: meta
uses: docker/metadata-action@v4
with:
images: ${{env.docker_image}}
# type=semver is only active on workflow trigger "push".
# It will automatically add the tag "latest" on release tags (e.g. "v1.2.3", not on "v1.2.3-rc.1").
# We always move the tag "latest-dev" to every new image.
tags: |
type=raw,value=latest-dev
type=semver,pattern={{major}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{version}}
type=semver,pattern=v{{major}}
type=semver,pattern=v{{major}}.{{minor}}
type=semver,pattern={{raw}}
type=sha
type=sha,format=long
labels: |
org.opencontainers.image.title=gitstats
org.opencontainers.image.authors=Jens Kager <[email protected]>
org.opencontainers.image.version=${{github.ref_name}}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
# Allows re-using the build cache across workflow runs.
- name: Restore Docker build cache
uses: actions/cache@v3
with:
path: ${{env.docker_cache_in}}
key: docker-build-cache-${{github.sha}}
restore-keys: docker-build-cache
- name: Build/push Docker image
uses: docker/build-push-action@v4
with:
context: .
push: ${{env.is_publish == 'true'}}
load: ${{env.is_publish == 'false'}}
tags: |
${{env.docker_image}}:local
${{steps.meta.outputs.tags}}
labels: ${{steps.meta.outputs.labels}}
cache-from: type=local,src=${{env.docker_cache_in}}
cache-to: type=local,mode=max,dest=${{env.docker_cache_out}}
- name: Test Docker image
if: env.is_publish == 'false'
run: make test-ci
- name: Publish output as build artifact
if: env.is_publish == 'false'
uses: actions/upload-artifact@v3
with:
name: gitstats-output
path: ./out
retention-days: 3