Skip to content

Commit 648a8b6

Browse files
committed
Add workflow for local docker image
1 parent fa3de8d commit 648a8b6

1 file changed

Lines changed: 86 additions & 0 deletions

File tree

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: Build and push Docker image (local)
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- 'backend/**'
9+
workflow_dispatch:
10+
inputs:
11+
target_branch:
12+
description: 'Local branch to merge into (default: local)'
13+
required: false
14+
default: 'local'
15+
16+
permissions:
17+
contents: write
18+
19+
jobs:
20+
merge-and-build:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Checkout repository
24+
uses: actions/checkout@v4
25+
with:
26+
fetch-depth: 0
27+
persist-credentials: true
28+
29+
- name: Set target branch
30+
run: echo "TARGET_BRANCH=${{ github.event.inputs.target_branch || 'local' }}" >> $GITHUB_ENV
31+
32+
- name: Configure Git
33+
run: |
34+
git config user.name "github-actions[bot]"
35+
git config user.email "github-actions[bot]@users.noreply.github.com"
36+
37+
- name: Fetch branches
38+
run: |
39+
git fetch origin main
40+
git fetch origin $TARGET_BRANCH || true
41+
42+
- name: Checkout target branch
43+
run: |
44+
if git rev-parse --verify origin/$TARGET_BRANCH >/dev/null 2>&1; then
45+
git checkout -B $TARGET_BRANCH origin/$TARGET_BRANCH
46+
else
47+
git checkout -B $TARGET_BRANCH
48+
fi
49+
50+
- name: Merge main into target branch
51+
run: |
52+
set -o pipefail
53+
if git merge --no-edit origin/main; then
54+
echo "Merge succeeded"
55+
else
56+
echo "Merge failed. Showing status and conflicted files:" >&2
57+
git status --porcelain
58+
git --no-pager diff --name-only --diff-filter=U || true
59+
exit 1
60+
fi
61+
62+
- name: Push merged branch
63+
run: git push origin HEAD:$TARGET_BRANCH
64+
65+
- name: Set up Java
66+
uses: actions/setup-java@v4
67+
with:
68+
java-version: '21'
69+
distribution: 'temurin'
70+
71+
- name: Build with Maven
72+
run: mvn -DskipTests package
73+
working-directory: backend
74+
75+
- name: Login to DockerHub
76+
uses: docker/login-action@v2
77+
with:
78+
username: ${{ secrets.DOCKERHUB_USERNAME }}
79+
password: ${{ secrets.DOCKERHUB_TOKEN }}
80+
81+
- name: Build Docker image
82+
run: docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/transformer-tracker-local:latest .
83+
working-directory: backend
84+
85+
- name: Push image
86+
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/transformer-tracker-local:latest

0 commit comments

Comments
 (0)