Merge pull request #26 from alisaitteke/develop #36
This file contains 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
# .github/workflows/release-drafter.yml | |
name: Release Drafter | |
on: | |
push: | |
branches: [ master ] # Changed from main to master | |
pull_request: | |
types: [opened, reopened, synchronize] | |
branches: [ master ] # Changed from main to master | |
workflow_dispatch: | |
permissions: | |
contents: write | |
pull-requests: write | |
issues: write | |
jobs: | |
draft: | |
runs-on: ubuntu-latest | |
outputs: | |
version: ${{ steps.version.outputs.version }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- uses: release-drafter/release-drafter@v5 | |
id: release_drafter | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
config-name: release-drafter.yml | |
disable-autolabeler: false | |
commitish: master # Changed from main to master | |
- name: Extract version without v prefix | |
id: version | |
run: | | |
VERSION="${{ steps.release_drafter.outputs.resolved_version }}" | |
VERSION="${VERSION#v}" # Remove v prefix if present | |
echo "version=$VERSION" >> $GITHUB_OUTPUT | |
update_version: | |
needs: draft | |
runs-on: ubuntu-latest | |
if: github.event_name == 'push' && github.ref == 'refs/heads/master' # Changed from main to master | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '20' | |
- name: Configure Git | |
run: | | |
git config --global user.name 'github-actions[bot]' | |
git config --global user.email 'github-actions[bot]@users.noreply.github.com' | |
- name: Update Package Version | |
run: | | |
NEW_VERSION="${{ needs.draft.outputs.version }}" | |
if [ -n "$NEW_VERSION" ]; then | |
# Read current version | |
CURRENT_VERSION=$(node -p "require('./package.json').version") | |
if [ "$CURRENT_VERSION" != "$NEW_VERSION" ]; then | |
echo "Updating version from $CURRENT_VERSION to $NEW_VERSION" | |
# Update package.json without creating git tag | |
npm version $NEW_VERSION --no-git-tag-version --allow-same-version | |
npm install | |
rm -rf dist/ | |
# Stage changes | |
git add package.json | |
if [ -f "package-lock.json" ]; then | |
rm -rf package-lock.json | |
fi | |
# Commit and push changes | |
git commit -m "chore: update package version to $NEW_VERSION [skip ci]" | |
git push | |
else | |
echo "Version is already up to date ($CURRENT_VERSION)" | |
fi | |
else | |
echo "No version update needed" | |
fi | |
- name: Update Changelog | |
if: needs.draft.outputs.version != '' | |
run: | | |
if [ -f CHANGELOG.md ]; then | |
NEW_VERSION="${{ needs.draft.outputs.version }}" | |
DATE=$(date +"%Y-%m-%d") | |
# Create temporary file for new content | |
echo "# $NEW_VERSION ($DATE)" > temp_changelog.md | |
echo "" >> temp_changelog.md | |
# Add release notes | |
curl -s \ | |
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
"https://api.github.com/repos/${{ github.repository }}/releases" \ | |
| jq -r '.[0].body' >> temp_changelog.md | |
echo "" >> temp_changelog.md | |
# Combine with existing changelog | |
if [ -f CHANGELOG.md ]; then | |
cat CHANGELOG.md >> temp_changelog.md | |
fi | |
mv temp_changelog.md CHANGELOG.md | |
# Commit changelog | |
git add CHANGELOG.md | |
git commit -m "docs: update changelog for $NEW_VERSION [skip ci]" | |
git push | |
fi |