Skip to content

Commit

Permalink
Do not fail when a release is not necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
gpmayorga committed Dec 5, 2024
1 parent dbe1cc7 commit ad5b11d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
30 changes: 27 additions & 3 deletions .github/ci-scripts/check-version-bump.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,39 @@

# Get the current version from package.json
current_version=$(node -p "require('./package.json').version")
current_commit=$(git rev-parse --short HEAD)

# Get the previous version from the last commit
previous_version=$(git show HEAD~1:package.json | node -p "JSON.parse(require('fs').readFileSync(0, 'utf-8')).version")
previous_commit=$(git rev-parse --short HEAD~1)

# Compare the versions
if [ "$current_version" != "$previous_version" ]; then
echo "Version has been bumped from $previous_version to $current_version."
echo "Version changed from $previous_version (commit $previous_commit) to $current_version (commit $current_commit)"
echo "Creating release https://github.com/centrifuge/sdk/releases/tag/$current_version"
exit 0
else
echo "Version has not been bumped."
exit 1
echo "Version $current_version remains unchanged between commits $previous_commit and $current_commit"
# Initialize error flag
has_error=0

# Check if GitHub release exists
if ! curl -s -f "https://api.github.com/repos/centrifuge/sdk/releases/tags/v${current_version}" &>/dev/null; then
echo "ERROR: GitHub tag v${current_version} does not exist."
has_error=1
fi

# Check if npm package version exists
if ! npm view "@centrifuge/sdk@${current_version}" version &>/dev/null; then
echo "ERROR: NPM package @centrifuge/sdk@${current_version} does not exist."
has_error=1
fi

# Exit with error if either check failed
if [ $has_error -eq 1 ]; then
echo "Maybe a step was skipped for v$current_version? Please check the release manually."
exit 1
fi
# If the version on package.json is released and hasn't changed, exit without errors.
exit 0
fi
5 changes: 3 additions & 2 deletions .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ jobs:
- name: Check if version was bumped
id: version_check
run: |
./.github/ci-scripts/check-version-bump.sh
OUTPUT=$(./.github/ci-scripts/check-version-bump.sh)
echo "::warning::$OUTPUT"
- name: Create GitHub Release
if: success() && steps.version_check.outcome == 'success'
if: steps.version_check.outcome == 'success'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
Expand Down

0 comments on commit ad5b11d

Please sign in to comment.