Skip to content

Commit 87971c7

Browse files
committed
feat: add Github workflow for mysql9
1 parent f373cc0 commit 87971c7

1 file changed

Lines changed: 117 additions & 0 deletions

File tree

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
name: Publish MySQL 9 image to Docker Hub
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- "mysql9/**"
9+
10+
permissions:
11+
contents: write
12+
13+
env:
14+
IMAGE_NAME: dev-mysql9
15+
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
16+
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
17+
DOCKERHUB_ID: ${{ secrets.DOCKERHUB_ID }}
18+
19+
jobs:
20+
build_and_push:
21+
if: github.event_name != 'pull_request'
22+
name: Build and push MySQL 9 image
23+
runs-on: ubuntu-latest
24+
steps:
25+
- name: Checkout repository
26+
uses: actions/checkout@v5
27+
with:
28+
fetch-depth: 0
29+
30+
- name: Check for changes in mysql9 directory
31+
id: changes
32+
uses: dorny/paths-filter@v3
33+
with:
34+
filters: |
35+
mysql9:
36+
- 'mysql9/**'
37+
38+
- name: Exit if no changes
39+
if: steps.changes.outputs.mysql9 != 'true'
40+
run: |
41+
echo "No changes in mysql9 directory, skipping build"
42+
exit 0
43+
44+
- name: Setup Docker Buildx
45+
uses: docker/setup-buildx-action@v3
46+
47+
- name: Log into Docker Hub
48+
uses: docker/login-action@v3
49+
with:
50+
registry: https://index.docker.io/v1/
51+
username: ${{ env.DOCKERHUB_USERNAME }}
52+
password: ${{ env.DOCKERHUB_PASSWORD }}
53+
54+
- name: Get latest version tag
55+
id: get_version
56+
run: |
57+
git fetch --tags
58+
# get the latest tag with regex pattern have vmysql9 prefix
59+
latest_tag=$(git tag -l | grep -E '^vmysql9' | sort -V | tail -n 1)
60+
echo "Latest tag: $latest_tag"
61+
echo "version=$latest_tag" >> $GITHUB_OUTPUT
62+
63+
- name: Increment version number
64+
id: inc_version
65+
run: |
66+
version=${{ steps.get_version.outputs.version }}
67+
version=${version#"v"}
68+
if [ -z "$version" ]; then
69+
major=0
70+
minor=0
71+
patch=0
72+
else
73+
IFS='.' read -r -a parts <<< "$version"
74+
major=${parts[0]:-0}
75+
minor=${parts[1]:-0}
76+
patch=${parts[2]:-0}
77+
fi
78+
patch=$((patch+1))
79+
if [ "$patch" -ge 100 ]; then
80+
patch=0
81+
minor=$((minor+1))
82+
fi
83+
if [ "$minor" -ge 10 ]; then
84+
minor=0
85+
major=$((major+1))
86+
fi
87+
new_version="v$major.$minor.$patch"
88+
echo "New version: $new_version"
89+
echo "new_version=$new_version" >> $GITHUB_OUTPUT
90+
91+
- name: Set new version tag
92+
run: |
93+
git tag ${{ steps.inc_version.outputs.new_version }}
94+
git push origin ${{ steps.inc_version.outputs.new_version }}
95+
96+
- name: Extract Docker metadata
97+
id: meta
98+
uses: docker/metadata-action@v5
99+
with:
100+
images: ${{ env.DOCKERHUB_ID }}/${{ env.IMAGE_NAME }}
101+
tags: |
102+
type=ref,event=branch
103+
type=ref,event=tag
104+
type=semver,pattern={{version}}
105+
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
106+
type=raw,value=${{ steps.inc_version.outputs.new_version }}
107+
108+
- name: Build and push MySQL 9 image
109+
id: build-and-push
110+
uses: docker/build-push-action@v6
111+
with:
112+
context: mysql9
113+
push: true
114+
tags: |
115+
${{ env.DOCKERHUB_ID }}/${{ env.IMAGE_NAME }}:latest
116+
${{ env.DOCKERHUB_ID }}/${{ env.IMAGE_NAME }}:${{ steps.inc_version.outputs.new_version }}
117+
labels: ${{ steps.meta.outputs.labels }}

0 commit comments

Comments
 (0)