diff --git a/.github/workflows/release-and-publish.yml b/.github/workflows/release-and-publish.yml index 710f300..ef82568 100644 --- a/.github/workflows/release-and-publish.yml +++ b/.github/workflows/release-and-publish.yml @@ -9,32 +9,83 @@ on: jobs: release: runs-on: ubuntu-latest + permissions: + contents: write + id-token: write steps: - - uses: actions/checkout@v4 + - name: Checkout code + uses: actions/checkout@v3 with: fetch-depth: 0 + token: ${{ secrets.GITHUB_TOKEN }} + - name: Set up Python uses: actions/setup-python@v3 with: python-version: "3.x" + - name: Install dependencies run: | python -m pip install --upgrade pip - pip install build twine semantic-release setuptools-scm + pip install build twine python-semantic-release setuptools-scm + - name: Run semantic-release env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - git config user.name github-actions - git config user.email github-actions@github-actions.github.com + git config --global user.name "github-actions" + git config --global user.email "github-actions@github.com" semantic-release version semantic-release publish + - name: Build package run: python -m build + - name: Publish package to PyPI env: TWINE_USERNAME: __token__ TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} run: twine upload dist/* - - name: Delete release-main branch from remote - run: git push origin --delete release-main + + create-pr-back-to-master: + needs: release + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + steps: + - name: Checkout code + uses: actions/checkout@v3 + with: + fetch-depth: 0 + ref: main + + - name: Set Git Identity + run: | + git config --global user.name 'GitHub Actions' + git config --global user.email 'github-actions@github.com' + + - name: Create Pull Request from main to master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + # Fetch the latest from master + git fetch origin master:refs/remotes/origin/master + + # Check if there are differences between main and master + DIFF_COUNT=$(git rev-list --count origin/master..HEAD) + + if [ "$DIFF_COUNT" -gt 0 ]; then + echo "Differences found between main and master. Creating PR..." + + # Use GitHub CLI to create the PR + gh pr create \ + --base master \ + --head main \ + --title "Sync master with main after release" \ + --body "This is an automated PR to sync changes from main back to master after a release." || true + + echo "Pull request created or already exists." + else + echo "No differences found between main and master. Skipping PR creation." + fi