merge dev to main #151
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
name: Merge PR to main | |
permissions: | |
contents: read | |
on: | |
pull_request: | |
types: | |
- closed | |
# - opened | |
# - reopened | |
# - synchronize | |
branches: | |
- main | |
jobs: | |
release: | |
runs-on: ubuntu-latest | |
concurrency: release | |
permissions: | |
contents: write | |
if: github.event.pull_request.merged == true # Ensure the PR was merged | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Setup Python version | |
uses: actions/setup-python@v5 | |
with: | |
python-version: "3.11" | |
- name: Install dependencies for Semantic Versioning | |
run: | | |
python -m pip install --upgrade pip | |
pip install tomli tomli-w | |
- name: Get Base and Latest Commits of the Merged PR | |
id: commit-range | |
run: | | |
# Get the base commit of the PR (the commit where it diverged from the main branch) | |
BASE_COMMIT=$(git merge-base HEAD^ origin/main) | |
# Get the commits introduced by this PR | |
COMMITS=$(git rev-list --reverse $BASE_COMMIT..HEAD) | |
# Extract the first and last commits | |
FIRST_COMMIT=$(echo "$COMMITS" | head -n 1) | |
LATEST_COMMIT=$(echo "$COMMITS" | tail -n 1) | |
# Set outputs for later steps | |
echo "base_commit=$BASE_COMMIT" >> $GITHUB_OUTPUT | |
echo "first_commit=$FIRST_COMMIT" >> $GITHUB_OUTPUT | |
echo "latest_commit=$LATEST_COMMIT" >> $GITHUB_OUTPUT | |
# Log for debugging | |
echo "Base Commit: $BASE_COMMIT" | |
echo "First Commit in PR: $FIRST_COMMIT" | |
echo "Latest Commit in PR: $LATEST_COMMIT" | |
- name: Get Latest Feluda Tag | |
id: latest-tag | |
run: | | |
LATEST_TAG=$(git tag -l "feluda-[0-9]*" | sort -V | tail -n1) | |
echo "current_tag=$LATEST_TAG" >> $GITHUB_OUTPUT | |
echo "current feluda tag: $LATEST_TAG" | |
- name: Run Dynamic Semantic Release Script | |
env: | |
FIRST_COMMIT: ${{ steps.commit-range.outputs.first_commit }} | |
LATEST_COMMIT: ${{ steps.commit-range.outputs.latest_commit }} | |
run: | | |
pwd | |
# run the script | |
python -m scripts.semantic_release_workflow "$FIRST_COMMIT" "$LATEST_COMMIT" | |
- name: Commit and Push Changes | |
id: push-changes | |
run: | | |
git config --local user.email "github-actions[bot]@users.noreply.github.com" | |
git config --local user.name "GitHub Actions [Bot]" | |
if [[ -n $(git status -s) ]]; then | |
git add . | |
git commit -m "chore: semantic versioning workflow and update related files" | |
git push | |
git push --tags | |
# Check if new feluda tag was created | |
NEW_TAG=$(git tag -l "feluda-[0-9]*" | sort -V | tail -n1) | |
if [ "$NEW_TAG" != "${{ steps.latest-tag.outputs.current_tag }}" ]; then | |
echo "new_tag=$NEW_TAG" >> $GITHUB_OUTPUT | |
echo "tag_created=true" >> $GITHUB_OUTPUT | |
else | |
echo "tag_created=false" >> $GITHUB_OUTPUT | |
fi | |
else | |
echo "tag_created=false" >> $GITHUB_OUTPUT | |
fi | |
- name: Create GitHub Release | |
if: steps.push-changes.outputs.tag_created == 'true' | |
run: | | |
gh release create "${{ steps.push-changes.outputs.new_tag }}" \ | |
--repo="${GITHUB_REPOSITORY}" \ | |
--title="Release ${{ steps.push-changes.outputs.new_tag }}" \ | |
--generate-notes | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
# rough logic for generating custom changelog's | |
# - name: Generate Release Notes and Update Changelog | |
# if: steps.push-changes.outputs.tag_created == 'true' | |
# id: release-notes | |
# run: | | |
# # Get the previous feluda tag | |
# PREV_TAG=$(git tag -l "feluda-[0-9]*" | sort -V | grep -B1 "${{ steps.push-changes.outputs.new_tag }}" | head -n1) | |
# echo "Prev feluda tag: $PREV_TAG" | |
# echo "New feluda tag: ${{ steps.push-changes.outputs.new_tag }}" | |
# # Create release notes file with header | |
# echo "# Release ${{ steps.push-changes.outputs.new_tag }}" > release_notes.md | |
# echo "" >> release_notes.md | |
# # Function to add section if commits exist | |
# add_section() { | |
# local title="$1" | |
# local pattern="$2" | |
# local commits=$(git log "${PREV_TAG}^..${{ steps.push-changes.outputs.new_tag }}" --pretty=format:"* %s (%h)" | grep "^* $pattern" || true) | |
# if [ ! -z "$commits" ]; then | |
# echo "## $title" >> release_notes.md | |
# echo "$commits" >> release_notes.md | |
# echo "" >> release_notes.md | |
# fi | |
# } | |
# # Add sections only if they have commits | |
# add_section "Features" "feat" | |
# add_section "Bug Fixes" "fix" | |
# add_section "Chores" "chore" | |
# add_section "Documentation" "docs" | |
# # Add miscellaneous section for other commits | |
# misc_commits=$(git log "${PREV_TAG}^..${{ steps.push-changes.outputs.new_tag }}" --pretty=format:"* %s (%h)" | | |
# grep -v "^* feat" | | |
# grep -v "^* fix" | | |
# grep -v "^* chore" | | |
# grep -v "^* docs" || true) | |
# if [ ! -z "$misc_commits" ]; then | |
# echo "## Miscellaneous" >> release_notes.md | |
# echo "$misc_commits" >> release_notes.md | |
# echo "" >> release_notes.md | |
# fi | |
# # Update CHANGELOG.md | |
# if [ -f CHANGELOG.md ]; then | |
# cat release_notes.md > temp_changelog | |
# echo "" >> temp_changelog | |
# cat CHANGELOG.md >> temp_changelog | |
# mv temp_changelog CHANGELOG.md | |
# else | |
# cat release_notes.md > CHANGELOG.md | |
# fi | |
# # Commit the updated CHANGELOG | |
# git add CHANGELOG.md | |
# git commit -m "docs: update CHANGELOG.md for ${{ steps.push-changes.outputs.new_tag }}" | |
# git push | |