Skip to content

Add ids to release jobs #7

Add ids to release jobs

Add ids to release jobs #7

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"
echo "version_changed=true" >> $GITHUB_OUTPUT
else
echo "Version did not change"
echo "version_changed=false" >> $GITHUB_OUTPUT
# Read version changelog
- id: get-changelog
if: steps.previous_commit.outputs.version_changed == 'true'
name: Get version changelog
uses: superfaceai/release-changelog-action@v1
with:
path-to-changelog: CHANGELOG.md
version: ${{ env.CURRENT_VERSION }}
operation: read
# Commit changes
- name: Create tag
if: steps.compare_versions.outputs.version_changed == 'true'
run: |
git tag ${{ env.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: ${{ env.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 }}