Create Release #224
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: Create Release | |
on: | |
workflow_run: | |
workflows: ["frontera"] | |
types: | |
- completed | |
env: | |
REGISTRY: ghcr.io | |
FRONTERA_PROD_IMAGE_NAME: ${{ github.repository }}/prod | |
MIDDLEWARE_IMAGE_NAME: ${{ github.repository }}/middleware | |
DOCKER_BUILDKIT: 1 | |
permissions: | |
contents: write | |
packages: write | |
jobs: | |
create-release: | |
runs-on: ubicloud-standard-2 | |
if: github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.head_branch == 'main' | |
outputs: | |
next_version: ${{ steps.generate_version.outputs.next_version }} | |
should_release: ${{ steps.generate_version.outputs.should_release }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 # Needed to fetch all tags | |
- name: Get latest tag | |
id: get_latest_tag | |
run: | | |
# Get the latest tag, default to v0.0.0 if no tags exist | |
latest_tag=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0") | |
echo "latest_tag=${latest_tag}" >> $GITHUB_OUTPUT | |
- name: Get version info from commits | |
id: commit_message | |
run: | | |
# Get the merge commit message | |
merge_msg=$(git log -1 --pretty=format:"%s") | |
echo "Merge message: $merge_msg" | |
# If this is a merge commit, get the PR commits | |
if [[ "$merge_msg" == "Merge pull request"* ]]; then | |
# Get just the commits from this PR (between HEAD and where PR branched) | |
pr_commits=$(git log HEAD^2 --not HEAD^ --pretty=format:"%s") | |
echo "PR commits:" | |
echo "$pr_commits" | |
# Check for version prefixes in PR commits | |
if echo "$pr_commits" | grep -q "^major:"; then | |
echo "Found major version commit" | |
echo "version_bump=major" >> $GITHUB_OUTPUT | |
elif echo "$pr_commits" | grep -q "^minor:"; then | |
echo "Found minor version commit" | |
echo "version_bump=minor" >> $GITHUB_OUTPUT | |
elif echo "$pr_commits" | grep -q "^patch:"; then | |
echo "Found patch version commit" | |
echo "version_bump=patch" >> $GITHUB_OUTPUT | |
else | |
echo "No version prefix found, skipping release" | |
echo "version_bump=skip" >> $GITHUB_OUTPUT | |
fi | |
else | |
# Direct commit to branch - same logic | |
if [[ "$merge_msg" =~ ^major: ]]; then | |
echo "Found major version commit" | |
echo "version_bump=major" >> $GITHUB_OUTPUT | |
elif [[ "$merge_msg" =~ ^minor: ]]; then | |
echo "Found minor version commit" | |
echo "version_bump=minor" >> $GITHUB_OUTPUT | |
elif [[ "$merge_msg" =~ ^patch: ]]; then | |
echo "Found patch version commit" | |
echo "version_bump=patch" >> $GITHUB_OUTPUT | |
else | |
echo "No version prefix found, skipping release" | |
echo "version_bump=skip" >> $GITHUB_OUTPUT | |
fi | |
fi | |
- name: Generate next version | |
id: generate_version | |
if: steps.commit_message.outputs.version_bump != 'skip' | |
run: | | |
latest_tag=${{ steps.get_latest_tag.outputs.latest_tag }} | |
version_bump="${{ steps.commit_message.outputs.version_bump }}" | |
# Debug output | |
echo "Latest tag: $latest_tag" | |
echo "Version bump type: $version_bump" | |
# Extract version numbers | |
major=$(echo $latest_tag | sed 's/v\([0-9]*\).\([0-9]*\).\([0-9]*\)/\1/') | |
minor=$(echo $latest_tag | sed 's/v\([0-9]*\).\([0-9]*\).\([0-9]*\)/\2/') | |
patch=$(echo $latest_tag | sed 's/v\([0-9]*\).\([0-9]*\).\([0-9]*\)/\3/') | |
echo "Current version: major=$major minor=$minor patch=$patch" | |
# Increment version based on bump type | |
case "$version_bump" in | |
"major") | |
echo "Performing major version bump" | |
new_major=$((major + 1)) | |
next_version="v${new_major}.0.0" | |
;; | |
"minor") | |
echo "Performing minor version bump" | |
new_minor=$((minor + 1)) | |
next_version="v${major}.${new_minor}.0" | |
;; | |
"patch") | |
echo "Performing patch version bump" | |
new_patch=$((patch + 1)) | |
next_version="v${major}.${minor}.${new_patch}" | |
;; | |
esac | |
echo "Next version will be: $next_version" | |
echo "next_version=${next_version}" >> $GITHUB_OUTPUT | |
echo "should_release=true" >> $GITHUB_OUTPUT | |
- name: Create Release | |
if: steps.commit_message.outputs.version_bump != 'skip' && steps.generate_version.outputs.should_release == 'true' | |
uses: softprops/action-gh-release@v1 | |
with: | |
tag_name: ${{ steps.generate_version.outputs.next_version }} | |
generate_release_notes: true | |
token: ${{ secrets.GITHUB_TOKEN }} | |
# Docker build and push steps start here | |
- name: Delete huge unnecessary tools folder | |
if: steps.generate_version.outputs.should_release == 'true' | |
run: rm -rf /opt/hostedtoolcache | |
- name: Set up Docker Buildx | |
if: steps.generate_version.outputs.should_release == 'true' | |
uses: docker/setup-buildx-action@v3 | |
with: | |
driver-opts: | | |
network=host | |
- uses: ubicloud/setup-node@v4 | |
if: steps.generate_version.outputs.should_release == 'true' | |
with: | |
node-version: '20' | |
cache: 'npm' | |
cache-dependency-path: './package-lock.json' | |
- name: Log in to the Container registry | |
if: steps.generate_version.outputs.should_release == 'true' | |
uses: docker/login-action@v3.3.0 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ secrets.REPOSITORY_READ_WRITE_USERNAME }} | |
password: ${{ secrets.REPOSITORY_READ_WRITE_TOKEN }} | |
# Build and push production image with the new version tag | |
- name: Build and push production image | |
if: steps.generate_version.outputs.should_release == 'true' | |
uses: docker/build-push-action@v6.13.0 | |
with: | |
push: true | |
tags: ${{ env.REGISTRY }}/${{ env.FRONTERA_PROD_IMAGE_NAME }}:${{ steps.generate_version.outputs.next_version }} | |
cache-from: | | |
type=gha,scope=frontera-build | |
type=gha,scope=frontera-build-${{ github.job }} | |
cache-to: | | |
type=gha,mode=max,scope=frontera-build-${{ github.job }} | |
build-args: | | |
"VITE_MIDDLEWARE_API_URL=${{ secrets.PROD_VITE_MIDDLEWARE_API_URL }}" | |
"VITE_CLIENT_APP_URL=${{ secrets.PROD_VITE_CLIENT_APP_URL }}" | |
"VITE_REALTIME_WS_PATH=${{ secrets.PROD_VITE_REALTIME_WS_PATH }}" | |
"VITE_REALTIME_WS_API_KEY=${{ secrets.PROD_VITE_REALTIME_WS_API_KEY }}" | |
"VITE_STRIPE_PUBLIC_KEY=${{ secrets.PROD_VITE_STRIPE_PUBLIC_KEY }}" | |
# Build and push middleware image with the new version tag | |
- name: Build and push middleware image | |
if: steps.generate_version.outputs.should_release == 'true' | |
uses: docker/build-push-action@v6.13.0 | |
with: | |
context: middleware/ | |
push: true | |
tags: ${{ env.REGISTRY }}/${{ env.MIDDLEWARE_IMAGE_NAME }}:${{ steps.generate_version.outputs.next_version }} | |
cache-from: | | |
type=gha,scope=frontera-build | |
type=gha,scope=middleware-build-${{ github.job }} | |
cache-to: | | |
type=gha,mode=max,scope=middleware-build-${{ github.job }} | |
# Save outputs for the deploy workflow | |
- name: Save workflow outputs | |
if: steps.generate_version.outputs.should_release == 'true' | |
run: | | |
echo "{\"next_version\": \"${{ steps.generate_version.outputs.next_version }}\"}" > workflow-data.json | |
- name: Upload workflow outputs | |
if: steps.generate_version.outputs.should_release == 'true' | |
uses: actions/upload-artifact@v4 | |
with: | |
name: workflow-data | |
path: workflow-data.json |