1+ name : " Build docker image"
2+
3+ on :
4+ push :
5+ tags :
6+ - ' v*'
7+ workflow_dispatch :
8+
9+ jobs :
10+ build-and-push-docker :
11+ name : Build and push Docker image to GhCr
12+ runs-on : ubuntu-latest
13+ if : github.event_name == 'push' && contains(github.ref, 'refs/tags/')
14+ steps :
15+ - name : Check out the repo
16+ uses : actions/checkout@v2
17+
18+ - name : Set up Docker Buildx
19+ uses : docker/setup-buildx-action@v1
20+
21+ - name : Log in to Docker Hub
22+ uses : docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
23+ with :
24+ registry : ghcr.io
25+ username : ${{ github.actor }}
26+ password : ${{ secrets.GITHUB_TOKEN }}
27+
28+ - name : Extract metadata (tags, labels) for Docker
29+ id : meta
30+ uses : docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
31+ with :
32+ images : ghcr.io/keinenclue/sasm-docker
33+ tags : type=ref,event=tag
34+
35+ - name : Build and push Docker image
36+ uses : docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
37+ with :
38+ context : .
39+ push : true
40+ tags : ${{ steps.meta.outputs.tags }}
41+ labels : ${{ steps.meta.outputs.labels }}
42+
43+ build-and-push-docker-manually :
44+ name : Build and push Docker image to GhCr with previous tag
45+ runs-on : ubuntu-latest
46+ if : github.event_name == 'workflow_dispatch'
47+ steps :
48+ - name : Check out the repo
49+ uses : actions/checkout@v2
50+ with :
51+ fetch-depth : 0 # Required due to the weg Git works, without it this action won't be able to find any or the correct tags
52+
53+ - name : Set up Docker Buildx
54+ uses : docker/setup-buildx-action@v1
55+
56+ - name : Log in to Docker Hub
57+ uses : docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
58+ with :
59+ registry : ghcr.io
60+ username : ${{ github.actor }}
61+ password : ${{ secrets.GITHUB_TOKEN }}
62+
63+ - name : ' Get Previous tag'
64+ id : previoustag
65+ uses : " WyriHaximus/github-action-get-previous-tag@v1"
66+
67+ - name : Extract metadata (tags, labels) for Docker
68+ id : meta
69+ uses : docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
70+ with :
71+ images : ghcr.io/keinenclue/sasm-docker
72+ tags : type=semver,pattern={{version}},value=${{ steps.previoustag.outputs.tag }}
73+ flavor : |
74+ latest=true
75+
76+ - name : Build and push Docker image
77+ uses : docker/build-push-action@v2
78+ with :
79+ context : .
80+ push : true
81+ tags : ${{ steps.meta.outputs.tags }}
82+ labels : ${{ steps.meta.outputs.labels }}
0 commit comments