Merge pull request #45 from atomantic/chore/update-all-deps #27
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Release | |
| on: | |
| push: | |
| branches: [release] | |
| permissions: | |
| contents: write | |
| jobs: | |
| release: | |
| runs-on: ubuntu-latest | |
| # Skip version bump commits | |
| if: "!contains(github.event.head_commit.message, '[skip ci]')" | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Use Node.js 20.x | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: 20.x | |
| - name: Configure git | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| - name: Get version from package.json | |
| id: package-version | |
| run: echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT | |
| - name: Check if tag exists | |
| id: tag-check | |
| run: | | |
| if git rev-parse "v${{ steps.package-version.outputs.version }}" >/dev/null 2>&1; then | |
| echo "exists=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "exists=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Generate changelog | |
| id: changelog | |
| if: steps.tag-check.outputs.exists == 'false' | |
| run: | | |
| VERSION="${{ steps.package-version.outputs.version }}" | |
| MAJOR_MINOR=$(echo $VERSION | cut -d. -f1-2) | |
| # Try exact version first (e.g., v0.10.5.md), then minor.x pattern (e.g., v0.10.x.md) | |
| CHANGELOG_FILE_EXACT=".changelog/v${VERSION}.md" | |
| CHANGELOG_FILE_PATTERN=".changelog/v${MAJOR_MINOR}.x.md" | |
| if [ -f "$CHANGELOG_FILE_EXACT" ]; then | |
| # Use exact version changelog | |
| CHANGELOG=$(cat "$CHANGELOG_FILE_EXACT") | |
| elif [ -f "$CHANGELOG_FILE_PATTERN" ]; then | |
| # Use minor version pattern changelog (e.g., v0.10.x.md) | |
| CHANGELOG=$(cat "$CHANGELOG_FILE_PATTERN") | |
| # Replace version placeholder with actual version | |
| CHANGELOG=$(echo "$CHANGELOG" | sed "s/v${MAJOR_MINOR}.x/v${VERSION}/g" | sed "s/${MAJOR_MINOR}.x/${VERSION}/g") | |
| else | |
| # Fallback: Generate changelog from commits (exclude [skip ci] commits) | |
| PREV_TAG=$(git describe --tags --abbrev=0 2>/dev/null || git rev-list --max-parents=0 HEAD) | |
| COMMIT_LOG=$(git log $PREV_TAG..HEAD --pretty=format:"- %s" --no-merges | grep -v "\[skip ci\]" | head -50) | |
| # Create a basic changelog structure | |
| CHANGELOG="# Release v${VERSION} | |
| ## Changes | |
| ${COMMIT_LOG} | |
| ## Installation | |
| \`\`\`bash | |
| git clone https://github.com/atomantic/SparseTree.git | |
| cd SparseTree | |
| npm run install:all | |
| pm2 start ecosystem.config.cjs | |
| \`\`\`" | |
| fi | |
| # Handle multiline output | |
| echo "changelog<<EOF" >> $GITHUB_OUTPUT | |
| echo "$CHANGELOG" >> $GITHUB_OUTPUT | |
| echo "EOF" >> $GITHUB_OUTPUT | |
| - name: Create Release | |
| if: steps.tag-check.outputs.exists == 'false' | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: v${{ steps.package-version.outputs.version }} | |
| name: v${{ steps.package-version.outputs.version }} | |
| body: ${{ steps.changelog.outputs.changelog }} | |
| draft: false | |
| prerelease: false | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Archive changelog on main | |
| if: steps.tag-check.outputs.exists == 'false' | |
| run: | | |
| CURRENT_VERSION=${{ steps.package-version.outputs.version }} | |
| MAJOR=$(echo $CURRENT_VERSION | cut -d. -f1) | |
| MINOR=$(echo $CURRENT_VERSION | cut -d. -f2) | |
| MAJOR_MINOR="$MAJOR.$MINOR" | |
| PATTERN_FILE=".changelog/v${MAJOR_MINOR}.x.md" | |
| VERSIONED_FILE=".changelog/v${CURRENT_VERSION}.md" | |
| if [ -f "$PATTERN_FILE" ]; then | |
| # Archive directly on main so release never diverges | |
| git fetch origin main | |
| git checkout main | |
| git mv "$PATTERN_FILE" "$VERSIONED_FILE" | |
| sed -i.bak "s/v${MAJOR_MINOR}\.x/v${CURRENT_VERSION}/g; s/${MAJOR_MINOR}\.x/${CURRENT_VERSION}/g; s/YYYY-MM-DD/$(date +%Y-%m-%d)/g" "$VERSIONED_FILE" | |
| rm "${VERSIONED_FILE}.bak" | |
| git add "$VERSIONED_FILE" | |
| git commit -m "docs: archive changelog for v${CURRENT_VERSION} [skip ci]" | |
| git push origin main | |
| # Fast-forward release to match main | |
| git push origin main:release | |
| fi |