Skip to content

Release and Publish Docker Image #4

Release and Publish Docker Image

Release and Publish Docker Image #4

name: Release and Publish Docker Image
on:
workflow_dispatch:
inputs:
version:
description: "Version to release (optional, defaults to patch increment)"
required: false
default: ""
jobs:
test:
name: Run Tests
runs-on: ubuntu-latest
env:
BEACONCHAIN_URL: ${{ secrets.BEACONCHAIN_URL }}
RPC_URL: ${{ secrets.RPC_URL }}
WS_URL: ${{ secrets.WS_URL }}
IPFS_URL: ${{ secrets.IPFS_URL }}
LOG_LEVEL: DEBUG
steps:
# Checkout code
- name: Checkout code
uses: actions/checkout@v4
# Run integration tests
- name: Run Integration Tests
run: |
echo "Running Integration Tests"
go test -v --race -tags=integration ./...
release:
name: Release and Publish Docker Image
needs: test
runs-on: ubuntu-latest
steps:
# Checkout the repository
- name: Checkout code
uses: actions/checkout@v4
# Fetch all tags
- name: Fetch tags
run: git fetch --tags
# Determine the next version
- name: Determine release version
id: determine_version
run: |
# Get the input version
INPUT_VERSION="${{ github.event.inputs.version }}"
# Find the latest tag
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "0.0.0")
# If an input version is provided, use it
if [[ -n "$INPUT_VERSION" ]]; then
NEW_VERSION="$INPUT_VERSION"
else
# Increment the patch version by default
IFS='.' read -r MAJOR MINOR PATCH <<< "$LATEST_TAG"
NEW_VERSION="${MAJOR}.${MINOR}.$((PATCH + 1))"
fi
# If no releases exist, default to 0.1.0
if [[ "$LATEST_TAG" == "0.0.0" ]]; then
NEW_VERSION="0.1.0"
fi
echo "New version: $NEW_VERSION"
echo "::set-output name=version::$NEW_VERSION"
# Create a new Git tag
- name: Create and push Git tag
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
NEW_VERSION=${{ steps.determine_version.outputs.version }}
# Configure git user
git config user.name "github-actions"
git config user.email "[email protected]"
# Create and push the tag
git tag -a "$NEW_VERSION" -m "Release $NEW_VERSION"
git push origin "$NEW_VERSION"
# Create a GitHub release
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.determine_version.outputs.version }}
name: Release ${{ steps.determine_version.outputs.version }}
body: |
Automatically generated release ${{ steps.determine_version.outputs.version }}.
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Log in to GitHub Docker Registry
- name: Log in to GitHub Docker Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Build and push Docker image
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:${{ steps.determine_version.outputs.version }}