Skip to content

Commit 1b9985a

Browse files
authored
Merge pull request #7 from EED-Solutions/dev
dev
2 parents 14baf21 + caa4ce0 commit 1b9985a

2 files changed

Lines changed: 56 additions & 10 deletions

File tree

.github/workflows/publish_docker.yml

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
name: Publish Docker Image to GHCR
22

33
on:
4-
workflow_dispatch:
54
push:
65
branches:
76
- main
8-
- release
9-
- dev
107
tags:
118
- 'v*.*.*' # Semantic versioning pattern
9+
pull_request:
10+
# This triggers on any PR, but we filter by source branch in the job
11+
types: [opened, synchronize, reopened]
12+
workflow_dispatch:
1213

1314
permissions:
1415
contents: read
@@ -21,6 +22,16 @@ jobs:
2122
steps:
2223
- uses: actions/checkout@v4
2324

25+
# Only continue for PRs if the source branch is dev or release
26+
- name: Check PR source branch
27+
if: github.event_name == 'pull_request'
28+
run: |
29+
echo "PR source branch: ${{ github.head_ref }}"
30+
if [[ "${{ github.head_ref }}" != "dev" && "${{ github.head_ref }}" != "release" ]]; then
31+
echo "Not a PR from dev or release branch. Skipping workflow."
32+
exit 1
33+
fi
34+
2435
- name: Log in to GHCR
2536
uses: docker/login-action@v3
2637
with:
@@ -34,9 +45,30 @@ jobs:
3445
TAG=latest
3546
SHOULD_BUILD_PUSH=false
3647
48+
echo "GITHUB_EVENT_NAME: $GITHUB_EVENT_NAME"
49+
echo "GITHUB_REF: $GITHUB_REF"
50+
echo "GITHUB_HEAD_REF: $GITHUB_HEAD_REF"
51+
52+
# Determine context: PR or push/tag
53+
if [[ "$GITHUB_EVENT_NAME" == "pull_request" ]]; then
54+
BRANCH_NAME="$GITHUB_HEAD_REF"
55+
REF_TYPE="pr"
56+
elif [[ "$GITHUB_REF" == refs/heads/* ]]; then
57+
BRANCH_NAME="${GITHUB_REF#refs/heads/}"
58+
REF_TYPE="branch"
59+
elif [[ "$GITHUB_REF" == refs/tags/* ]]; then
60+
BRANCH_NAME="${GITHUB_REF#refs/tags/}"
61+
REF_TYPE="tag"
62+
else
63+
BRANCH_NAME=""
64+
REF_TYPE=""
65+
fi
66+
echo "REF_TYPE: $REF_TYPE"
67+
echo "BRANCH_NAME: $BRANCH_NAME"
68+
3769
# Determine tag and build indicator based on context
38-
if [[ "${{ github.ref_type }}" == "branch" ]]; then
39-
case "${{ github.ref_name }}" in
70+
if [[ "$REF_TYPE" == "branch" || "$REF_TYPE" == "pr" ]]; then
71+
case "$BRANCH_NAME" in
4072
"main")
4173
TAG=main
4274
SHOULD_BUILD_PUSH=true
@@ -50,16 +82,19 @@ jobs:
5082
SHOULD_BUILD_PUSH=true
5183
;;
5284
*)
53-
TAG=${{ github.ref_name }}
85+
TAG="$BRANCH_NAME"
5486
;;
5587
esac
56-
elif [[ "${{ github.ref_type }}" == "tag" ]]; then
57-
TAG=${{ github.ref_name }}
58-
if [[ "${{ github.ref_name }}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
88+
elif [[ "$REF_TYPE" == "tag" ]]; then
89+
TAG="$BRANCH_NAME"
90+
if [[ "$BRANCH_NAME" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
5991
SHOULD_BUILD_PUSH=true
6092
fi
6193
fi
6294
95+
echo "Determined TAG: $TAG"
96+
echo "SHOULD_BUILD_PUSH: $SHOULD_BUILD_PUSH"
97+
6398
# Build and push the image if indicated
6499
if [[ "$SHOULD_BUILD_PUSH" == "true" ]]; then
65100
docker build -t $IMAGE_NAME:$TAG -f .devcontainer/Dockerfile .

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,20 @@
77
88
## Github actions
99
10-
Workflows are centraly hosted in EED_Solutions/eed_gha_workflows.
10+
Workflows are centrally hosted in EED_Solutions/eed_gha_workflows.
1111
Please check for more details here.
1212
13+
### Docker Publish Workflow Triggering
14+
15+
The Docker publish workflow (`publish_docker.yml`) is triggered automatically in the following cases:
16+
17+
- **On any push to the `main` branch.**
18+
- **On any tag pushed to the repository that matches semantic versioning (`v*.*.*`).**
19+
- **When a pull request is opened, synchronized, or reopened and the source branch is named `dev` or `release`.**
20+
- Note: The workflow runs for all PRs, but will immediately exit unless the source branch is `dev` or `release`.
21+
22+
This ensures Docker images are only built and published for main releases, version tags, and changes coming from the main development branches.
23+
1324
## Other
1425
1526
Test EED85-machine

0 commit comments

Comments
 (0)