Skip to content

Commit 0917dbe

Browse files
committed
feat: workflows for 3 types of branches
1 parent 4803260 commit 0917dbe

4 files changed

Lines changed: 547 additions & 5 deletions

File tree

.github/workflows/ci-docker-release.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ jobs:
2222
strategy:
2323
fail-fast: true
2424
uses: ./.github/workflows/tests.yml
25+
2526
# ==========================
2627
# Generate Release Tags
2728
# ==========================
@@ -64,11 +65,7 @@ jobs:
6465
6566
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
6667
67-
#Only increase patch version if merging feature branch to main (previously dev)
68-
IS_MERGE=$(git log -1 --pretty=%P | wc -w)
69-
if [ "$IS_MERGE" -gt 1 ]; then
70-
PATCH=$((PATCH + 1))
71-
fi
68+
# any commit or merge to main updates the beta counter - this version holds the future base version
7269
7370
NEW_VERSION="$MAJOR.$MINOR.$PATCH"
7471
@@ -130,6 +127,7 @@ jobs:
130127
131128
git tag ${{ steps.set_release_info.outputs.TAG }}
132129
git push origin ${{ steps.set_release_info.outputs.TAG }}
130+
133131
# ==========================
134132
# Publish Docker Image
135133
# ==========================
@@ -165,6 +163,7 @@ jobs:
165163
tags: |
166164
aminnausin/mediaserver:${{ needs.get-release-tags.outputs.docker-tag }}
167165
aminnausin/mediaserver:${{ needs.get-release-tags.outputs.tag }}
166+
168167
# ==========================
169168
# Check for Docker Changes
170169
# ==========================

.github/workflows/ci-main.yml

Lines changed: 228 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,228 @@
1+
name: CI & Docker Release (Beta)
2+
3+
concurrency:
4+
group: beta-main
5+
cancel-in-progress: false
6+
7+
on:
8+
push:
9+
branches: [ 'main' ]
10+
paths-ignore:
11+
- "VERSION"
12+
workflow_dispatch:
13+
inputs:
14+
bump:
15+
description: 'Version bump type'
16+
required: true
17+
default: 'minor'
18+
type: choice
19+
options:
20+
- major
21+
- minor
22+
23+
jobs:
24+
run-tests:
25+
permissions:
26+
contents: write
27+
strategy:
28+
fail-fast: true
29+
uses: ./.github/workflows/tests.yml
30+
31+
# ==========================
32+
# Generate Beta Tags
33+
# ==========================
34+
get-beta-tags:
35+
name: Generate Beta Tags
36+
runs-on: ubuntu-latest
37+
needs: run-tests
38+
permissions:
39+
contents: write
40+
strategy:
41+
fail-fast: true
42+
outputs:
43+
tag: ${{ steps.beta.outputs.TAG }}
44+
45+
steps:
46+
- name: Checkout Repository
47+
uses: actions/checkout@v4
48+
49+
- name: Ensure VERSION file exists
50+
run: |
51+
VERSION_FILE="VERSION"
52+
if [ ! -f "$VERSION_FILE" ]; then
53+
echo "0.1.0" > "$VERSION_FILE"
54+
fi
55+
56+
- name: Fetch full git history and tags
57+
run: |
58+
git fetch --unshallow --tags || git fetch --tags
59+
60+
- name: Calculate beta version
61+
id: beta
62+
run: |
63+
VERSION_FILE="VERSION"
64+
CURRENT_VERSION=$(cat $VERSION_FILE)
65+
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION"
66+
67+
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
68+
INCREMENT="${{ github.event.inputs.bump }}"
69+
INCREMENT="${INCREMENT:-minor}"
70+
71+
case $INCREMENT in
72+
major)
73+
MAJOR=$((MAJOR + 1)); MINOR=0; PATCH=0 ;;
74+
minor|*)
75+
MINOR=$((MINOR + 1)); PATCH=0 ;;
76+
esac
77+
fi
78+
79+
if [ "$PATCH" != "0" ]; then
80+
echo "ERROR: main branch cannot hold patch versions (found $CURRENT_VERSION)"
81+
echo "::error::Main branch should only have X.Y.0 versions"
82+
exit 1
83+
fi
84+
85+
# any commit or merge to main updates the beta counter - this version holds the future base version
86+
87+
NEW_VERSION="$MAJOR.$MINOR.$PATCH"
88+
89+
LAST_BETA=$(git tag --list "${NEW_VERSION}-beta.[0-9]*" | sed -E "s/.*-beta\.//" | sort -V | tail -n1)
90+
LAST_BETA=${LAST_BETA:-0}
91+
BUILD_COUNT=$((LAST_BETA + 1))
92+
93+
TAG="${NEW_VERSION}-beta.${BUILD_COUNT}"
94+
95+
echo "::notice::Beta Tag: $TAG"
96+
97+
echo "$NEW_VERSION" > $VERSION_FILE
98+
echo "TAG=$TAG" >> $GITHUB_OUTPUT
99+
100+
- name: Commit updated VERSION file and manifest
101+
uses: stefanzweifel/git-auto-commit-action@v5
102+
with:
103+
commit_message: 'chore: bump version to ${{ steps.beta.outputs.TAG }}'
104+
file_pattern: |
105+
VERSION
106+
107+
- name: Create and push Git tag
108+
if: steps.beta.outputs.TAG != ''
109+
env:
110+
TAG: ${{ steps.beta.outputs.TAG }}
111+
run: |
112+
git config user.name "github-actions[bot]"
113+
git config user.email "github-actions[bot]@users.noreply.github.com"
114+
115+
if git rev-parse "$TAG" >/dev/null 2>&1; then
116+
echo "Tag already exists."
117+
exit 0
118+
fi
119+
120+
git tag "$TAG"
121+
git push origin "$TAG"
122+
123+
# ==========================
124+
# Publish Docker Image
125+
# ==========================
126+
build-docker:
127+
name: Build Docker Image
128+
runs-on: ubuntu-latest
129+
needs: [ get-beta-tags ]
130+
permissions:
131+
contents: write
132+
133+
steps:
134+
- name: Checkout Repository
135+
uses: actions/checkout@v4
136+
with:
137+
fetch-depth: 0
138+
submodules: false # Optional — only needed if using submodules
139+
persist-credentials: false # not needed unless you push
140+
141+
- name: Update .env.docker
142+
run: |
143+
sed -i "s/DOCKER_RELEASE=.*/DOCKER_RELEASE=beta/" docker/.env.docker
144+
145+
- name: Login to Docker Hub
146+
uses: docker/login-action@v3
147+
with:
148+
username: ${{ secrets.DOCKER_HUB_USERNAME }}
149+
password: ${{ secrets.DOCKER_HUB_TOKEN }}
150+
151+
- name: Push to Docker Hub
152+
uses: docker/build-push-action@v6
153+
with:
154+
context: .
155+
push: true
156+
tags: |
157+
aminnausin/mediaserver:beta
158+
aminnausin/mediaserver:${{ needs.get-beta-tags.outputs.tag }}
159+
160+
# ==========================
161+
# Check for Docker Changes
162+
# ==========================
163+
check-docker-changes:
164+
name: Check for Docker Related File Changes
165+
needs: [ run-tests ]
166+
if: needs.run-tests.result == 'success'
167+
runs-on: ubuntu-latest
168+
outputs:
169+
files_changed: ${{ steps.filter.outputs.changes != '[]' }}
170+
171+
steps:
172+
- name: Checkout code
173+
uses: actions/checkout@v4
174+
175+
- name: Check for file changes
176+
id: filter
177+
uses: dorny/paths-filter@v2
178+
with:
179+
filters: |
180+
changed:
181+
- 'docker/**'
182+
- 'docker-compose.yaml'
183+
- 'Dockerfile'
184+
- 'startDocker.*'
185+
- 'data/**'
186+
- 'README.md'
187+
188+
# ==========================
189+
# Release Docker Setup Pkg
190+
# ==========================
191+
release:
192+
name: Create GitHub Release
193+
runs-on: ubuntu-latest
194+
needs: [ build-docker, check-docker-changes, get-beta-tags ]
195+
if: needs.check-docker-changes.outputs.files_changed == 'true' || github.event_name == 'workflow_dispatch'
196+
permissions:
197+
contents: write
198+
199+
steps:
200+
- name: Checkout Repository
201+
uses: actions/checkout@v4
202+
203+
- name: Prepare default data files for release
204+
run: |
205+
mkdir -p data
206+
cp -r storage/app/public/* data
207+
208+
- name: Zip Files Linux
209+
run: |
210+
zip -r mediaServerDockerLinux.zip ./docker/etc ./docker/.env.docker ./docker-compose.yaml ./startDocker.sh ./README.md ./data/*
211+
212+
- name: Zip Files Windows
213+
run: |
214+
zip -r mediaServerDockerWindows.zip ./docker/etc ./docker/.env.docker ./docker-compose.yaml ./startDocker.bat ./README.md ./data/* ./add-hosts-entry.ps1
215+
216+
- name: Cleanup temp
217+
run: rm -rf temp
218+
219+
- name: Create Release
220+
uses: ncipollo/release-action@v1
221+
with:
222+
allowUpdates: false
223+
token: ${{ secrets.GITHUB_TOKEN }}
224+
tag: ${{ needs.get-beta-tags.outputs.tag }}
225+
name: Docker Release - ${{ needs.get-beta-tags.outputs.tag }}
226+
draft: false
227+
prerelease: true
228+
artifacts: mediaServerDockerLinux.zip,mediaServerDockerWindows.zip

0 commit comments

Comments
 (0)