Skip to content

Creating Release

Creating Release #13

name: Create Release
run-name: Creating Release
on:
push:
branches:
- main
paths:
- '**.pre-commit-hooks.yaml'
jobs:
create-release:
if: contains(github.event.head_commit.message, 'Release v')
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.create-tag.outputs.TAG }}
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Check Commit for Release
id: check_commit
run: |
# Checking Last Commit
COMMIT_MSG=$(git --no-pager log -1 --pretty=%B)
if [[ "${COMMIT_MSG}" =~ Release\ v([0-9]+\.[0-9]+\.[0-9]+) ]]; then
echo "VERSION=${BASH_REMATCH[1]}" >> "${GITHUB_ENV}"
else
echo "Not a release commit."
fi
- name: Create Tag and Release for ${{ env.VERSION }}
id: create-tag
if: ${{ env.VERSION != '' }}
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
TAG="v${VERSION}"
git config user.name "GitHub Actions"
git config user.email "github-actions[bot]@users.noreply.github.com"
gh release create "${TAG}" --generate-notes
echo "TAG=${TAG}" >> "${GITHUB_OUTPUT}"
create-docker-image:
needs: create-release
if: needs.create-release.outputs.tag != ''
name: Pushlish Docker image to Docker Hub
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: 'arm64'
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: robertderose/esh-template-check
tags: |
type=raw,value=latest
type=raw,value=${{ needs.create-release.outputs.tag }}
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}