1+ name : Docker Build and Push
2+ on :
3+ push :
4+ branches :
5+ - main
6+ - dev
7+ tags :
8+ - " *" # This will trigger on any tag push
9+ pull_request :
10+ branches :
11+ - main
12+ jobs :
13+ build-and-push :
14+ runs-on : ubuntu-latest
15+ steps :
16+ # 1) Check out your repository code with full depth
17+ - name : Checkout code
18+ uses : actions/checkout@v3
19+ with :
20+ fetch-depth : 0
21+
22+ # 2) List files to verify huntarr.py is present
23+ - name : List files in directory
24+ run : ls -la
25+
26+ # 3) Set up Docker Buildx
27+ - name : Set up Docker Buildx
28+ uses : docker/setup-buildx-action@v2
29+
30+ # 4) Log in to Docker Hub
31+ - name : Log in to Docker Hub
32+ if : github.event_name != 'pull_request'
33+ uses : docker/login-action@v2
34+ with :
35+ username : ${{ secrets.DOCKERHUB_USERNAME }}
36+ password : ${{ secrets.DOCKERHUB_PASSWORD }}
37+
38+ # 5) Extract version from tag if it's a tag push
39+ - name : Extract version from tag
40+ if : startsWith(github.ref, 'refs/tags/')
41+ id : get_version
42+ run : echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
43+
44+ # 6a) Build & Push if on 'main' branch
45+ - name : Build and Push (main)
46+ if : github.ref == 'refs/heads/main' && github.event_name != 'pull_request'
47+ uses : docker/build-push-action@v3
48+ with :
49+ context : .
50+ push : true
51+ tags : |
52+ huntarr/4readarr:latest
53+ huntarr/4readarr:${{ github.sha }}
54+
55+ # 6b) Build & Push if on 'dev' branch
56+ - name : Build and Push (dev)
57+ if : github.ref == 'refs/heads/dev' && github.event_name != 'pull_request'
58+ uses : docker/build-push-action@v3
59+ with :
60+ context : .
61+ push : true
62+ tags : |
63+ huntarr/4readarr:dev
64+ huntarr/4readarr:${{ github.sha }}
65+
66+ # 6c) Build & Push if it's a tag/release
67+ - name : Build and Push (release)
68+ if : startsWith(github.ref, 'refs/tags/') && github.event_name != 'pull_request'
69+ uses : docker/build-push-action@v3
70+ with :
71+ context : .
72+ push : true
73+ tags : |
74+ huntarr/4readarr:${{ steps.get_version.outputs.VERSION }}
75+ huntarr/4readarr:latest
76+
77+ # 6d) Just build on pull requests
78+ - name : Build (PR)
79+ if : github.event_name == 'pull_request'
80+ uses : docker/build-push-action@v3
81+ with :
82+ context : .
83+ push : false
0 commit comments