File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ name : Build and Push Docker Image
2+
3+ on :
4+ workflow_dispatch :
5+ inputs :
6+ branch :
7+ description : ' Branch to build from'
8+ required : true
9+ default : ' release-v1'
10+ type : string
11+ tag_as_latest :
12+ description : ' Tag image as latest'
13+ required : false
14+ default : false
15+ type : boolean
16+
17+ jobs :
18+ build-and-push :
19+ runs-on : ubuntu-latest
20+
21+ steps :
22+ - name : Checkout branch
23+ uses : actions/checkout@v4
24+ with :
25+ ref : ${{ inputs.branch }}
26+
27+ - name : Get latest tag
28+ id : get-tag
29+ run : |
30+ git fetch --tags
31+ LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
32+ if [ -z "$LATEST_TAG" ]; then
33+ echo "No tags found on branch ${{ inputs.branch }}"
34+ exit 1
35+ fi
36+ echo "tag=$LATEST_TAG" >> $GITHUB_OUTPUT
37+
38+ - name : Checkout tag
39+ run : |
40+ git checkout ${{ steps.get-tag.outputs.tag }}
41+
42+ - name : Log in to GitHub Container Registry
43+ uses : docker/login-action@v3
44+ with :
45+ registry : ghcr.io
46+ username : ${{ github.actor }}
47+ password : ${{ secrets.GITHUB_TOKEN }}
48+
49+ - name : Extract metadata
50+ id : meta
51+ uses : docker/metadata-action@v5
52+ with :
53+ images : ghcr.io/${{ github.repository }}
54+ tags : |
55+ type=raw,value=${{ steps.get-tag.outputs.tag }}
56+ type=raw,value=latest,enable=${{ inputs.tag_as_latest }}
57+
58+ - name : Build and push Docker image
59+ uses : docker/build-push-action@v5
60+ with :
61+ context : .
62+ push : true
63+ tags : ${{ steps.meta.outputs.tags }}
64+ labels : ${{ steps.meta.outputs.labels }}
You can’t perform that action at this time.
0 commit comments