Skip to content

Merge pull request #19 from mindfiredigital/master #3

Merge pull request #19 from mindfiredigital/master

Merge pull request #19 from mindfiredigital/master #3

name: Release and Publish Package
on:
push:
branches:
- main
workflow_dispatch:
jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- 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 python-semantic-release setuptools-scm
- name: Run semantic-release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
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/*
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