Skip to content

Updated create-release action #27

Updated create-release action

Updated create-release action #27

name: Release with Changeset
on:
workflow_dispatch:
branches:
- main
jobs:
release:
name: Create Release
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ github.token }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Install dependencies
run: npm ci
- name: Commit Changeset Version Bump
id: changesets
run: |
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
npx changeset version
# Print the git status to see the changes
git status
if [ -n "$(git status --porcelain)" ]; then
NEW_VERSION=$(node -p "require('./package.json').version")
git add .
git commit -m "Version packages"
echo "commit=true" >> $GITHUB_ENV
echo "NEW_VERSION=${NEW_VERSION}" >> $GITHUB_ENV
echo "::set-output name=commit::true"
else
echo "No changes to commit"
echo "commit=false" >> $GITHUB_ENV
echo "::set-output name=commit::false"
fi
- name: Debug Commit Output
run: echo "Commit output: ${{ steps.changesets.outputs.commit }}"

Check failure on line 52 in .github/workflows/create-release.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/create-release.yml

Invalid workflow file

You have an error in your yaml syntax on line 52
- name: Pull Latest Changes
run: git pull origin main --rebase
env:
GITHUB_TOKEN: ${{ github.token }}
- name: Push Version Bump to Main
if: steps.changesets.outputs.commit == 'true'
run: git push origin main
env:
GITHUB_TOKEN: ${{ github.token }}
- name: Check Version Change
id: version_check
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
CURRENT_VERSION=$(node -p "require('./package.json').version")
LATEST_RELEASE=$(gh release list --limit 1 | cut -f1)
LATEST_VERSION=${LATEST_RELEASE#v}
echo "Current version: ${CURRENT_VERSION}"
echo "Latest release: ${LATEST_VERSION}"
if [ "$(printf '%s\n' "$LATEST_VERSION" "$CURRENT_VERSION" | sort -V | tail -n1)" = "$CURRENT_VERSION" ] && [ "$LATEST_VERSION" != "$CURRENT_VERSION" ]; then
echo "Version increment detected"
echo "should_release=true" >> $GITHUB_OUTPUT
else
echo "No version increment detected or versions are equal"
echo "should_release=false" >> $GITHUB_OUTPUT
exit 0
fi
- name: Generate Release Summary
if: steps.version_check.outputs.should_release == 'true'
id: release_summary
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Get all commits between the last release and current
LATEST_RELEASE=$(gh release list --limit 1 | cut -f1)
COMMITS=$(git log ${LATEST_RELEASE}..HEAD --pretty=format:"%s")
# Generate a summary from the commit messages
SUMMARY="Summary of changes:\n${COMMITS}"
# Store the summary for the release
echo "summary<<EOF" >> $GITHUB_OUTPUT
echo "$SUMMARY" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Create GitHub Release
if: steps.version_check.outputs.should_release == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
CURRENT_VERSION=$(node -p "require('./package.json').version")
gh release create "v${CURRENT_VERSION}" \
--title "v${CURRENT_VERSION}: ${{ steps.release_summary.outputs.summary }}" \
--notes "${{ steps.release_summary.outputs.summary }}" \
--generate-notes