Release CD #20
Workflow file for this run
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: Release CD | |
env: | |
DOCKERREPO: seblum/octivbooker | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- master | |
paths: | |
- src/** | |
- poetry.Dockerfile | |
- pyproject.toml | |
- CHANGELOG.md | |
jobs: | |
release: | |
name: 🚀 Release | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write # to be able to publish a GitHub release | |
issues: write # to be able to comment on released issues | |
pull-requests: write # to be able to comment on released pull requests | |
steps: | |
- | |
name: Checkout code | |
uses: actions/checkout@v4 | |
- | |
name: Release | |
uses: googleapis/release-please-action@v4 | |
id: release | |
with: | |
release-type: "python" | |
- | |
name: 🏷️ Tag Major and Minor Versions | |
if: ${{ steps.release.outputs.release_created }} | |
run: | | |
git config user.name github-actions[bot] | |
git config user.email 41898282+github-actions[bot]@users.noreply.github.com | |
git tag -d v${{ steps.release.outputs.major }} || true | |
git tag -d v${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }} || true | |
git push origin :v${{ steps.release.outputs.major }} || true | |
git push origin :v${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }} || true | |
git tag -a v${{ steps.release.outputs.major }} -m "Release v${{ steps.release.outputs.major }}" | |
git tag -a v${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }} -m "Release v${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }}" | |
git push origin v${{ steps.release.outputs.major }} | |
git push origin v${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }} | |
poetry-version-tag: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
issues: write | |
pull-requests: write | |
needs: release | |
steps: | |
- | |
name: Checkout code with full history | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- | |
name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.x' | |
- | |
name: Extract tag version | |
id: extract_version | |
run: | | |
TAG_VERSION=$(git describe --match "v*.*.*" --tags --abbrev=0 || echo "no-tags") | |
echo "TAG_VERSION=$TAG_VERSION" >> $GITHUB_ENV | |
echo "Extracted tag version: $TAG_VERSION" | |
- | |
name: Create new Branch | |
run: | | |
git fetch origin | |
git checkout -b update-version-$TAG_VERSION origin/master | |
git pull --rebase | |
git push origin update-version-$TAG_VERSION --force | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- | |
name: Update Version in pyproject.toml | |
run: | | |
sed -i "s/^version = \".*\"/version = \"$TAG_VERSION\"/" ./pyproject.toml | |
- | |
name: Verify Update | |
run: cat ./pyproject.toml | |
- | |
name: Commit changes | |
run: | | |
git config --global user.name 'github-actions[bot]' | |
git config --global user.email 'github-actions[bot]@users.noreply.github.com' | |
git add pyproject.toml | |
git commit -m "Update version to $TAG_VERSION" | |
git push origin update-version-$TAG_VERSION | |
- | |
name: Install GitHub CLI | |
run: | | |
sudo apt-get install gh | |
- | |
name: Create Pull Request | |
run: | | |
PR_EXISTS=$(gh pr list --head update-version-$TAG_VERSION --json number --jq '.[0].number' || echo "") | |
if [ -z "$PR_EXISTS" ]; then | |
gh pr create --title "Bump version to $TAG_VERSION" \ | |
--body "This PR updates the version in pyproject.toml to $TAG_VERSION." \ | |
--base master \ | |
--head update-version-$TAG_VERSION | |
else | |
echo "PR already exists." | |
fi | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |