Skip to content

Merge pull request #41 from wkelly1/release-v2.0.0 #12

Merge pull request #41 from wkelly1/release-v2.0.0

Merge pull request #41 from wkelly1/release-v2.0.0 #12

name: Create new release
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: main
fetch-depth: 0 # Fetch full history to ensure we can compare versions properly
- name: Debug Git History
run: |
echo "Current Branch: $(git rev-parse --abbrev-ref HEAD)"
echo "Commit History:"
git log --oneline --graph --decorate --all
- name: Get previous commit hash (before HEAD)
id: previous_commit
run: |
git fetch origin main --prune
# Get the commit hash before the most recent one
PREVIOUS_COMMIT=$(git rev-parse HEAD^)
echo "commit_hash=$PREVIOUS_COMMIT" >> $GITHUB_OUTPUT
- name: Get the package.json version from previous commit
id: get_base_version
run: |
# Fetch the package.json version from the previous commit
BASE_VERSION=$(git show ${{ steps.previous_commit.outputs.commit_hash }}:package.json | jq -r .version)
echo "Previous version: $BASE_VERSION"
echo "base_version=$BASE_VERSION" >> $GITHUB_OUTPUT
- name: Get the current package.json version (after merge)
id: get_current_version
run: |
# Extract the current package.json version at the HEAD
CURRENT_VERSION=$(jq -r .version package.json)
echo "Current version: $CURRENT_VERSION"
echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
- name: Compare versions
if: ${{ steps.previous_commit.outputs.commit_hash }}
id: compare_versions
run: |
if [ "${{ steps.get_base_version.outputs.BASE_VERSION }}" != "${{ steps.get_current_version.outputs.CURRENT_VERSION }}" ]; then
echo "Version has changed"
latest_version=$(printf '%s\n' "${{ steps.get_base_version.outputs.BASE_VERSION }}" "${{ steps.get_current_version.outputs.CURRENT_VERSION }}" | sort -V | tail -n 1)
if [ "$latest_version" != "${{ steps.get_current_version.outputs.CURRENT_VERSION }}"]; then
echo "Newly added version (${{ steps.get_base_version.outputs.BASE_VERSION }}) is older than current version (${{ steps.get_base_version.outputs.BASE_VERSION }})"
echo "version_changed=false" >> $GITHUB_OUTPUT
else
echo "Newly added version (${{ steps.get_base_version.outputs.BASE_VERSION }}) is newer than current version (${{ steps.get_base_version.outputs.BASE_VERSION }})"
echo "version_changed=true" >> $GITHUB_OUTPUT
fi
else
echo "Version did not change"
echo "version_changed=false" >> $GITHUB_OUTPUT
fi
# Read version changelog
- id: get-changelog
if: steps.compare_versions.outputs.version_changed == 'true'
name: Get version changelog
uses: superfaceai/release-changelog-action@v1
with:
path-to-changelog: CHANGELOG.md
version: ${{ steps.get_current_version.outputs.CURRENT_VERSION }}
operation: read
# Commit changes
- name: Create tag
if: steps.compare_versions.outputs.version_changed == 'true'
run: |
git tag ${{ steps.get_current_version.outputs.CURRENT_VERSION }}
# Push repository changes
- name: Push tag to repository
if: steps.compare_versions.outputs.version_changed == 'true'
env:
GITHUB_TOKEN: ${{ secrets.IKONO_TOKEN }}
run: |
git push --tags
# Update GitHub release with changelog
- name: Update GitHub release documentation
uses: softprops/action-gh-release@v1
if: steps.compare_versions.outputs.version_changed == 'true'
with:
tag_name: ${{ steps.get_current_version.outputs.CURRENT_VERSION }}
body: ${{ steps.get-changelog.outputs.changelog }}
## Pre-releases not currently supported
# prerelease: ${{ startsWith(github.event.inputs.release-type, 'pre') }}
env:
GITHUB_TOKEN: ${{ secrets.IKONO_TOKEN }}