diff --git a/.github/workflows/release-version.yaml b/.github/workflows/release-version.yaml index d507ce3..8f865e3 100644 --- a/.github/workflows/release-version.yaml +++ b/.github/workflows/release-version.yaml @@ -19,6 +19,8 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 + with: + fetch-depth: 0 # Fetch all history for tags - name: Set up Python uses: actions/setup-python@v4 @@ -33,11 +35,22 @@ jobs: - name: Check for changes inside oscar_python directory id: check_changes run: | - PREV_MONTH=$(date -d "last month" +%Y-%m) - if git log --since="$PREV_MONTH-01" --until="$(date +%Y-%m-01)" --pretty=format: --name-only | grep -q '^oscar_python/'; then + # Get the latest release tag + latest_release=$(git describe --tags --abbrev=0 2>/dev/null || echo "") + + if [ -z "$latest_release" ]; then + echo "No previous release found - treating as first release" echo "changes_detected=true" >> $GITHUB_ENV else - echo "changes_detected=false" >> $GITHUB_ENV + echo "Latest release: $latest_release" + # Check if there are changes in oscar_python directory since last release + if git log $latest_release..HEAD --pretty=format: --name-only | grep -q '^oscar_python/'; then + echo "Changes detected in oscar_python directory since $latest_release" + echo "changes_detected=true" >> $GITHUB_ENV + else + echo "No changes detected in oscar_python directory since $latest_release" + echo "changes_detected=false" >> $GITHUB_ENV + fi fi - name: Get current version diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml deleted file mode 100644 index 7d852b5..0000000 --- a/.github/workflows/release.yaml +++ /dev/null @@ -1,106 +0,0 @@ -name: Release workflow - Increase Version - -on: - release: - types: [created] - schedule: - - cron: '0 0 1 * *' # Runs at 00:00 on the 1st of every month - workflow_dispatch: - inputs: - version_type: - description: 'Type of version increment (patch, minor, major)' - required: true - default: 'patch' - -jobs: - release: - runs-on: ubuntu-22.04 - - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: '3.12' - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - python -m pip install setuptools wheel twine - - - name: Check for changes inside oscar_python directory - id: check_changes - run: | - PREV_MONTH=$(date -d "last month" +%Y-%m) - if git log --since="$PREV_MONTH-01" --until="$(date +%Y-%m-01)" --pretty=format: --name-only | grep -q '^oscar_python/'; then - echo "changes_detected=true" >> $GITHUB_ENV - else - echo "changes_detected=false" >> $GITHUB_ENV - fi - - - name: Get current version - if: env.changes_detected == 'true' - id: get_version - run: | - current_version=$(python setup.py --version) - echo "Current version: $current_version" - IFS='.' read -r -a version_parts <<< "$current_version" - major=${version_parts[0]} - minor=${version_parts[1]} - patch=${version_parts[2]} - version_type="${{ github.event.inputs.version_type }}" - if [ "$version_type" == "major" ]; then - new_major=$((major + 1)) - new_version="$new_major.0.0" - elif [ "$version_type" == "minor" ]; then - new_minor=$((minor + 1)) - new_version="$major.$new_minor.0" - else - new_patch=$((patch + 1)) - new_version="$major.$minor.$new_patch" - fi - echo "New version: $new_version" - echo "::set-output name=new_version::$new_version" - - - name: Create GitHub Release - if: env.changes_detected == 'true' - uses: actions/create-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - tag_name: v${{ steps.get_version.outputs.new_version }} - release_name: Release ${{ steps.get_version.outputs.new_version }} - draft: false - prerelease: false - - - name: Update version.py - if: env.changes_detected == 'true' - run: | - echo "__version__ = '$new_version'" > oscar_python/version.py - env: - new_version: ${{ steps.get_version.outputs.new_version }} - - - name: Commit version change and push to a new branch - if: env.changes_detected == 'true' - run: | - git config --global user.name 'github-actions' - git config --global user.email 'github-actions@github.com' - git checkout -b bump-version-${{ steps.get_version.outputs.new_version }} - git add oscar_python/version.py - git commit -m "Bump version to $new_version" - git push origin bump-version-${{ steps.get_version.outputs.new_version }} - env: - new_version: ${{ steps.get_version.outputs.new_version }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Create Pull Request - if: env.changes_detected == 'true' - uses: peter-evans/create-pull-request@v6 - with: - token: ${{ secrets.GITHUB_TOKEN }} - branch: bump-version-${{ steps.get_version.outputs.new_version }} - title: "Bump version to ${{ steps.get_version.outputs.new_version }}" - body: "Automated version bump and release workflow" - base: main