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: Auto Tag and Push Docker Release Image | |
on: | |
pull_request: | |
types: [closed] | |
branches: | |
- release/v* | |
jobs: | |
auto-tag-and-push: | |
if: github.event.pull_request.merged == true | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Identify and Create New Tag | |
id: new_tag | |
run: | | |
# Extract major and minor version from the branch name | |
BRANCH_NAME="${GITHUB_REF#refs/heads/}" | |
VERSION_PREFIX=$(echo $BRANCH_NAME | sed -E 's/release\/v([0-9]+\.[0-9]+).*/\1/') | |
# Fetch tags and find the latest tag with the same major and minor version | |
git fetch --tags | |
LATEST_TAG=$(git tag -l "v$VERSION_PREFIX.*" | sort -V | tail -n1) | |
echo "Latest tag for version $VERSION_PREFIX: $LATEST_TAG" | |
# Check if a tag was found, if not, start with x.0 | |
if [ -z "$LATEST_TAG" ]; then | |
NEW_TAG="v${VERSION_PREFIX}.0" | |
else | |
# Increment the patch version | |
NEW_TAG=$(echo $LATEST_TAG | awk -F. '{print $1"."$2"."$3+1}') | |
fi | |
echo "New tag: $NEW_TAG" | |
# Create and push the new tag | |
git tag $NEW_TAG | |
git push origin $NEW_TAG | |
echo "::set-output name=tag::$NEW_TAG" | |
- name: Get Title For Release | |
id: get_pr_details | |
run: | | |
# Fetch the full commit message of the most recent commit | |
FULL_COMMIT_MESSAGE=$(git log -1 --pretty=format:%B) | |
echo "Full commit message: $FULL_COMMIT_MESSAGE" | |
# Extract the main title from the commit message | |
# This regex captures the string before the first "(" and removes trailing spaces | |
PR_TITLE=$(echo "$FULL_COMMIT_MESSAGE" | sed -n '1p' | sed 's/ *([^()]*) *//g') | |
echo "::set-output name=title::$PR_TITLE" | |
- name: Create Release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{ steps.new_tag.outputs.tag }} | |
release_name: ${{ steps.get_pr_details.outputs.title }} | |
draft: false | |
prerelease: false | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to DockerHub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Build and push | |
id: docker_build | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
platforms: linux/amd64,linux/arm64 | |
push: true | |
tags: | | |
lagrangelabs/lagrange-node:${{ steps.new_tag.outputs.tag }} |