Skip to content

[FIX] push with double tags; #24

[FIX] push with double tags;

[FIX] push with double tags; #24

name: ci-builds-and-releases
on:
push:
branches:
- main
release:
types:
- created
schedule:
- cron: "0 0 * * *"
jobs:
docker_build:
name: Build and Push Docker Image
runs-on: ubuntu-20.04
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Get short SHA
id: vars
run: echo "SHORT_SHA=${GITHUB_SHA::8}" >> $GITHUB_ENV
- name: Get repo name
id: repo_vars
run: echo "GH_REPO_NAME=${GITHUB_REPOSITORY##*/}" >> $GITHUB_ENV
- name: Build and Push Docker Image
uses: docker/build-push-action@v6
with:
context: .
tags: ${{ secrets.DOCKER_USERNAME }}/${{ env.GH_REPO_NAME }}:${{ env.SHORT_SHA }}, ${{ secrets.DOCKER_USERNAME }}/${{ env.GH_REPO_NAME }}:latest
push: true
platforms: 'linux/amd64,linux/arm64'
labels: ${{ github.github_repository }}
release:
name: Create GitHub Release
runs-on: ubuntu-20.04
needs: docker_build
permissions:
contents: write
actions: read
discussions: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get last 4 commits
id: last_commits
run: |
git log -4 --pretty=format:"- %s (%h)" > last_commits.txt
- name: Determine next tag
id: tag_version
run: |
latest_tag=$(git describe --tags --abbrev=0 2>/dev/null || echo "0.0.0")
echo "Latest tag: $latest_tag"
IFS='.' read -r major minor patch <<<"${latest_tag#v}"
if [ "$latest_tag" = "0.0.0" ]; then
new_tag="v0.0.1"
else
if [ "$patch" -lt 9 ]; then
patch=$((patch + 1))
else
patch=0
if [ "$minor" -lt 9 ]; then
minor=$((minor + 1))
else
minor=0
major=$((major + 1))
fi
fi
new_tag="v$major.$minor.$patch"
fi
echo "New tag: $new_tag"
echo "TAG_NAME=$new_tag" >> $GITHUB_ENV
- name: Create and push new tag
run: |
git tag ${{ env.TAG_NAME }}
git push origin ${{ env.TAG_NAME }}
- name: Upload source code to GitHub Release
uses: softprops/action-gh-release@v2
with:
body_path: last_commits.txt
tag_name: ${{ env.TAG_NAME }}