#39 [docker public hub] fix: get latest tag version #20
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Publish Docker image | |
on: [push] | |
permissions: | |
contents: write | |
env: | |
DOCKER_ID: ${{ secrets.DOCKER_ID }} | |
IMAGE_NAME: ${{ secrets.IMAGE_NAME }} | |
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} | |
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} | |
jobs: | |
shellcheck: | |
name: Shellcheck | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
name: Checkout repository | |
- name: Copy .env.example to .env | |
run: cp .env.example .env | |
- name: Run ShellCheck | |
uses: ludeeus/action-shellcheck@master | |
with: | |
check_together: 'yes' | |
ignore_paths: >- | |
sources | |
push_to_registry: | |
if: github.event_name != 'pull_request' | |
name: Build and push Docker image | |
needs: shellcheck | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Setup Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Log into Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ env.DOCKER_USERNAME }} | |
password: ${{ env.DOCKER_PASSWORD }} | |
- name: Extract Docker metadata | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ env.DOCKER_ID }}/${{ env.IMAGE_NAME }} | |
tags: | | |
type=ref,event=branch | |
type=ref,event=tag | |
type=semver,pattern={{version}} | |
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }} | |
- name: Get latest version tag | |
id: get_version | |
run: | | |
git fetch --tags | |
latest_tag=$(git tag -l | sort -V | tail -n 1) | |
echo "Latest tag: $latest_tag" | |
echo ::set-output name=version::$latest_tag | |
- name: Increment version number | |
id: inc_version | |
run: | | |
version=${{ steps.get_version.outputs.version }} | |
version=${version#v} | |
if [ -z "$version" ]; then | |
major=0 | |
minor=0 | |
patch=0 | |
else | |
IFS='.' read -r -a parts <<< "$version" | |
major=${parts[0]:-0} | |
minor=${parts[1]:-0} | |
patch=${parts[2]:-0} | |
fi | |
patch=$((patch+1)) | |
if [ "$patch" -ge 10 ]; then | |
patch=0 | |
minor=$((minor+1)) | |
fi | |
if [ "$minor" -ge 10 ]; then | |
minor=0 | |
major=$((major+1)) | |
fi | |
new_version="v$major.$minor.$patch" | |
echo "New version: $new_version" | |
echo ::set-output name=new_version::$new_version | |
- name: Set new version tag | |
run: | | |
git tag ${{ steps.inc_version.outputs.new_version }} | |
git push origin ${{ steps.inc_version.outputs.new_version }} | |
- name: Build and push Docker image | |
id: build-and-push | |
uses: docker/build-push-action@v6 | |
with: | |
context: php | |
push: true | |
tags: | | |
${{ steps.meta.outputs.tags }} | |
${{ steps.inc_version.outputs.new_version }} | |
labels: ${{ steps.meta.outputs.labels }} | |
build-args: | | |
PHP_VERSION=8.3 | |
USER_ID=1000 | |
GROUP_ID=1000 |